X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FTransactionProxy.java;h=191cb2ef1edcb6e650d50d2769d49ec596059ea0;hb=a47dd7a5d21ca68804a6d0e2e3ca765f223c2ef4;hp=cdc2ec2a0a1c253025a0a5104beca1e556bfb279;hpb=5273c33b6f2051a7e3b1afcc4eeae4e457b6f26c;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java index cdc2ec2a0a..191cb2ef1e 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java @@ -12,6 +12,7 @@ import com.google.common.annotations.VisibleForTesting; 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; @@ -24,7 +25,14 @@ import java.util.List; 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; +import org.opendaylight.controller.cluster.datastore.modification.AbstractModification; +import org.opendaylight.controller.cluster.datastore.modification.DeleteModification; +import org.opendaylight.controller.cluster.datastore.modification.MergeModification; +import org.opendaylight.controller.cluster.datastore.modification.WriteModification; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; import org.opendaylight.controller.cluster.datastore.utils.NormalizedNodeAggregator; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; @@ -67,16 +75,22 @@ public class TransactionProxy extends AbstractDOMStoreTransaction exists(final YangInstanceIdentifier path) { + return executeRead(shardNameFromIdentifier(path), new DataExists(path, DataStoreVersions.CURRENT_VERSION)); + } + + private CheckedFuture executeRead(String shardName, final AbstractRead readCmd) { Preconditions.checkState(type != TransactionType.WRITE_ONLY, "Reads from write-only transactions are not allowed"); - LOG.debug("Tx {} exists {}", getIdentifier(), path); + if(LOG.isDebugEnabled()) { + LOG.debug("Tx {} {} {}", getIdentifier(), readCmd.getClass().getSimpleName(), readCmd.getPath()); + } - final SettableFuture proxyFuture = SettableFuture.create(); - TransactionContextWrapper contextWrapper = getContextWrapper(path); + final SettableFuture proxyFuture = SettableFuture.create(); + TransactionContextWrapper contextWrapper = getContextWrapper(shardName); contextWrapper.maybeExecuteTransactionOperation(new TransactionOperation() { @Override public void invoke(TransactionContext transactionContext) { - transactionContext.dataExists(path, proxyFuture); + transactionContext.executeRead(readCmd, proxyFuture); } }); @@ -98,16 +112,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction>, ReadFailedException> singleShardRead( final String shardName, final YangInstanceIdentifier path) { - final SettableFuture>> proxyFuture = SettableFuture.create(); - TransactionContextWrapper contextWrapper = getContextWrapper(shardName); - contextWrapper.maybeExecuteTransactionOperation(new TransactionOperation() { - @Override - public void invoke(TransactionContext transactionContext) { - transactionContext.readData(path, proxyFuture); - } - }); - - return MappingCheckedFuture.create(proxyFuture, ReadFailedException.MAPPER); + return executeRead(shardName, new ReadData(path, DataStoreVersions.CURRENT_VERSION)); } private CheckedFuture>, ReadFailedException> readAllData() { @@ -125,7 +130,9 @@ public class TransactionProxy extends AbstractDOMStoreTransaction> apply(final List>> 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); } @@ -137,45 +144,32 @@ public class TransactionProxy extends AbstractDOMStoreTransaction data) { - checkModificationState(); - - LOG.debug("Tx {} merge {}", getIdentifier(), path); - - TransactionContextWrapper contextWrapper = getContextWrapper(path); - contextWrapper.maybeExecuteTransactionOperation(new TransactionOperation() { - @Override - public void invoke(TransactionContext transactionContext) { - transactionContext.mergeData(path, data); - } - }); + executeModification(new MergeModification(path, data)); } @Override public void write(final YangInstanceIdentifier path, final NormalizedNode data) { + executeModification(new WriteModification(path, data)); + } + + private void executeModification(final AbstractModification modification) { checkModificationState(); - LOG.debug("Tx {} write {}", getIdentifier(), path); + if(LOG.isDebugEnabled()) { + LOG.debug("Tx {} executeModification {} {}", getIdentifier(), modification.getClass().getSimpleName(), + modification.getPath()); + } - TransactionContextWrapper contextWrapper = getContextWrapper(path); + TransactionContextWrapper contextWrapper = getContextWrapper(modification.getPath()); contextWrapper.maybeExecuteTransactionOperation(new TransactionOperation() { @Override - public void invoke(TransactionContext transactionContext) { - transactionContext.writeData(path, data); + protected void invoke(TransactionContext transactionContext) { + transactionContext.executeModification(modification); } }); } @@ -246,6 +240,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction createSingleCommitCohort(final String shardName, final TransactionContextWrapper contextWrapper) { @@ -261,43 +256,51 @@ public class TransactionProxy extends AbstractDOMStoreTransaction 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 createMultiCommitCohort( final Set> txContextWrapperEntries) { - final List> cohortFutures = new ArrayList<>(txContextWrapperEntries.size()); + final List cohorts = new ArrayList<>(txContextWrapperEntries.size()); for (Entry 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 txVersionSupplier = new Supplier() { + @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) {