import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier;
+import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
import org.opendaylight.controller.cluster.datastore.messages.AbstractRead;
import org.opendaylight.controller.cluster.datastore.messages.DataExists;
import org.opendaylight.controller.cluster.datastore.messages.ReadData;
@Override
public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) {
- return executeRead(shardNameFromIdentifier(path), new DataExists(path));
+ return executeRead(shardNameFromIdentifier(path), new DataExists(path, DataStoreVersions.CURRENT_VERSION));
}
private <T> CheckedFuture<T, ReadFailedException> executeRead(String shardName, final AbstractRead<T> readCmd) {
private CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> singleShardRead(
final String shardName, final YangInstanceIdentifier path) {
- return executeRead(shardName, new ReadData(path));
+ return executeRead(shardName, new ReadData(path, DataStoreVersions.CURRENT_VERSION));
}
private CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> readAllData() {
@Override
public Optional<NormalizedNode<?, ?>> apply(final List<Optional<NormalizedNode<?, ?>>> input) {
try {
- return NormalizedNodeAggregator.aggregate(YangInstanceIdentifier.EMPTY, input, txContextFactory.getActorContext().getSchemaContext());
+ return NormalizedNodeAggregator.aggregate(YangInstanceIdentifier.EMPTY, input,
+ txContextFactory.getActorContext().getSchemaContext(),
+ txContextFactory.getActorContext().getDatastoreContext().getLogicalStoreType());
} catch (DataValidationFailedException e) {
throw new IllegalArgumentException("Failed to aggregate", e);
}
return debugContext == null ? ret : new DebugThreePhaseCommitCohort(getIdentifier(), ret, debugContext);
}
+ @SuppressWarnings({ "rawtypes", "unchecked" })
private AbstractThreePhaseCommitCohort<?> createSingleCommitCohort(final String shardName,
final TransactionContextWrapper contextWrapper) {
contextWrapper.maybeExecuteTransactionOperation(new TransactionOperation() {
@Override
public void invoke(TransactionContext transactionContext) {
- promise.completeWith(getReadyOrDirectCommitFuture(transactionContext, operationCallbackRef));
+ promise.completeWith(getDirectCommitFuture(transactionContext, operationCallbackRef));
}
});
future = promise.future();
} else {
// avoid the creation of a promise and a TransactionOperation
- future = getReadyOrDirectCommitFuture(transactionContext, operationCallbackRef);
+ future = getDirectCommitFuture(transactionContext, operationCallbackRef);
}
- return new SingleCommitCohortProxy(txContextFactory.getActorContext(), future, getIdentifier().toString(),
- operationCallbackRef);
+ return new SingleCommitCohortProxy(txContextFactory.getActorContext(), future, getIdentifier(),
+ operationCallbackRef);
}
- private Future<?> getReadyOrDirectCommitFuture(TransactionContext transactionContext,
+ private Future<?> getDirectCommitFuture(TransactionContext transactionContext,
OperationCallback.Reference operationCallbackRef) {
- if (transactionContext.supportsDirectCommit()) {
- TransactionRateLimitingCallback rateLimitingCallback = new TransactionRateLimitingCallback(
- txContextFactory.getActorContext());
- operationCallbackRef.set(rateLimitingCallback);
- rateLimitingCallback.run();
- return transactionContext.directCommit();
- } else {
- return transactionContext.readyTransaction();
- }
+ TransactionRateLimitingCallback rateLimitingCallback = new TransactionRateLimitingCallback(
+ txContextFactory.getActorContext());
+ operationCallbackRef.set(rateLimitingCallback);
+ rateLimitingCallback.run();
+ return transactionContext.directCommit();
}
private AbstractThreePhaseCommitCohort<ActorSelection> createMultiCommitCohort(
final Set<Entry<String, TransactionContextWrapper>> txContextWrapperEntries) {
- final List<Future<ActorSelection>> cohortFutures = new ArrayList<>(txContextWrapperEntries.size());
+ final List<ThreePhaseCommitCohortProxy.CohortInfo> cohorts = new ArrayList<>(txContextWrapperEntries.size());
for (Entry<String, TransactionContextWrapper> e : txContextWrapperEntries) {
LOG.debug("Tx {} Readying transaction for shard {}", getIdentifier(), e.getKey());
- cohortFutures.add(e.getValue().readyTransaction());
+ final TransactionContextWrapper wrapper = e.getValue();
+
+ // The remote tx version is obtained the via TransactionContext which may not be available yet so
+ // we pass a Supplier to dynamically obtain it. Once the ready Future is resolved the
+ // TransactionContext is available.
+ Supplier<Short> txVersionSupplier = new Supplier<Short>() {
+ @Override
+ public Short get() {
+ return wrapper.getTransactionContext().getTransactionVersion();
+ }
+ };
+
+ cohorts.add(new ThreePhaseCommitCohortProxy.CohortInfo(wrapper.readyTransaction(), txVersionSupplier));
}
- return new ThreePhaseCommitCohortProxy(txContextFactory.getActorContext(), cohortFutures, getIdentifier().toString());
+ return new ThreePhaseCommitCohortProxy(txContextFactory.getActorContext(), cohorts, getIdentifier());
}
private String shardNameFromIdentifier(final YangInstanceIdentifier path) {