X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FRemoteTransactionContext.java;h=ce4bda74cfa7357a8114d84a06f58fc49a35c36c;hp=941c86116cb7926ebd13a6b55b79b32484bdd54e;hb=731e7284cf0895fdb1b89427f91762e80e67c2ff;hpb=6a0fab98dc4d16a52922c6594f99a97d4050e800 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContext.java index 941c86116c..ce4bda74cf 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContext.java @@ -13,6 +13,8 @@ import akka.dispatch.Futures; import akka.dispatch.OnComplete; import com.google.common.base.Preconditions; import com.google.common.util.concurrent.SettableFuture; +import java.util.Optional; +import java.util.SortedSet; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.messages.AbstractRead; import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications; @@ -50,8 +52,8 @@ public class RemoteTransactionContext extends AbstractTransactionContext { */ private volatile Throwable failedModification; - protected RemoteTransactionContext(TransactionIdentifier identifier, ActorSelection actor, - ActorContext actorContext, short remoteTransactionVersion, OperationLimiter limiter) { + protected RemoteTransactionContext(final TransactionIdentifier identifier, final ActorSelection actor, + final ActorContext actorContext, final short remoteTransactionVersion, final OperationLimiter limiter) { super(identifier, remoteTransactionVersion); this.limiter = Preconditions.checkNotNull(limiter); this.actor = actor; @@ -75,27 +77,35 @@ public class RemoteTransactionContext extends AbstractTransactionContext { } @Override - public Future directCommit() { + public Future directCommit(final Boolean havePermit) { LOG.debug("Tx {} directCommit called", getIdentifier()); // Send the remaining batched modifications, if any, with the ready flag set. - - return sendBatchedModifications(true, true); + bumpPermits(havePermit); + return sendBatchedModifications(true, true, Optional.empty()); } @Override - public Future readyTransaction() { + public Future readyTransaction(final Boolean havePermit, + final Optional> participatingShardNames) { logModificationCount(); LOG.debug("Tx {} readyTransaction called", getIdentifier()); // Send the remaining batched modifications, if any, with the ready flag set. - Future lastModificationsFuture = sendBatchedModifications(true, false); + bumpPermits(havePermit); + Future lastModificationsFuture = sendBatchedModifications(true, false, participatingShardNames); return transformReadyReply(lastModificationsFuture); } + private void bumpPermits(final Boolean havePermit) { + if (Boolean.TRUE.equals(havePermit)) { + ++batchPermits; + } + } + protected Future transformReadyReply(final Future readyReplyFuture) { // Transform the last reply Future into a Future that returns the cohort actor path from // the last reply message. That's the end result of the ready operation. @@ -107,7 +117,7 @@ public class RemoteTransactionContext extends AbstractTransactionContext { return new BatchedModifications(getIdentifier(), getTransactionVersion()); } - private void batchModification(Modification modification, boolean havePermit) { + private void batchModification(final Modification modification, final boolean havePermit) { incrementModificationCount(); if (havePermit) { ++batchPermits; @@ -126,10 +136,11 @@ public class RemoteTransactionContext extends AbstractTransactionContext { } protected Future sendBatchedModifications() { - return sendBatchedModifications(false, false); + return sendBatchedModifications(false, false, Optional.empty()); } - protected Future sendBatchedModifications(boolean ready, boolean doCommitOnReady) { + protected Future sendBatchedModifications(final boolean ready, final boolean doCommitOnReady, + final Optional> participatingShardNames) { Future sent = null; if (ready || batchedModifications != null && !batchedModifications.getModifications().isEmpty()) { if (batchedModifications == null) { @@ -139,7 +150,6 @@ public class RemoteTransactionContext extends AbstractTransactionContext { LOG.debug("Tx {} sending {} batched modifications, ready: {}", getIdentifier(), batchedModifications.getModifications().size(), ready); - batchedModifications.setReady(ready); batchedModifications.setDoCommitOnReady(doCommitOnReady); batchedModifications.setTotalMessagesSent(++totalBatchedModificationsSent); @@ -148,6 +158,8 @@ public class RemoteTransactionContext extends AbstractTransactionContext { batchPermits = 0; if (ready) { + batchedModifications.setReady(participatingShardNames); + batchedModifications.setDoCommitOnReady(doCommitOnReady); batchedModifications = null; } else { batchedModifications = newBatchedModifications(); @@ -167,7 +179,7 @@ public class RemoteTransactionContext extends AbstractTransactionContext { actorContext.getTransactionCommitOperationTimeout()); sent.onComplete(new OnComplete() { @Override - public void onComplete(Throwable failure, Object success) { + public void onComplete(final Throwable failure, final Object success) { if (failure != null) { LOG.debug("Tx {} modifications failed", getIdentifier(), failure); failedModification = failure; @@ -183,16 +195,23 @@ public class RemoteTransactionContext extends AbstractTransactionContext { } @Override - public void executeModification(AbstractModification modification) { + public void executeModification(final AbstractModification modification, final Boolean havePermit) { LOG.debug("Tx {} executeModification {} called path = {}", getIdentifier(), modification.getClass().getSimpleName(), modification.getPath()); - final boolean havePermit = failedModification == null && acquireOperation(); - batchModification(modification, havePermit); + final boolean permitToRelease; + if (havePermit == null) { + permitToRelease = failedModification == null && acquireOperation(); + } else { + permitToRelease = havePermit.booleanValue(); + } + + batchModification(modification, permitToRelease); } @Override - public void executeRead(final AbstractRead readCmd, final SettableFuture returnFuture) { + public void executeRead(final AbstractRead readCmd, final SettableFuture returnFuture, + final Boolean havePermit) { LOG.debug("Tx {} executeRead {} called path = {}", getIdentifier(), readCmd.getClass().getSimpleName(), readCmd.getPath()); @@ -209,14 +228,14 @@ public class RemoteTransactionContext extends AbstractTransactionContext { // Send any batched modifications. This is necessary to honor the read uncommitted semantics of the // public API contract. - final boolean havePermit = acquireOperation(); + final boolean permitToRelease = havePermit == null ? acquireOperation() : havePermit.booleanValue(); sendBatchedModifications(); OnComplete onComplete = new OnComplete() { @Override - public void onComplete(Throwable failure, Object response) { + public void onComplete(final Throwable failure, final Object response) { // We have previously acquired an operation, now release it, no matter what happened - if (havePermit) { + if (permitToRelease) { limiter.release(); } @@ -245,15 +264,15 @@ public class RemoteTransactionContext extends AbstractTransactionContext { * @return True if a permit was successfully acquired, false otherwise */ private boolean acquireOperation() { - if (isOperationHandOffComplete()) { - if (limiter.acquire()) { - return true; - } + Preconditions.checkState(isOperationHandOffComplete(), + "Attempted to acquire execute operation permit for transaction %s on actor %s during handoff", + getIdentifier(), actor); - LOG.warn("Failed to acquire execute operation permit for transaction {} on actor {}", getIdentifier(), - actor); + if (limiter.acquire()) { + return true; } + LOG.warn("Failed to acquire execute operation permit for transaction {} on actor {}", getIdentifier(), actor); return false; }