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%2FRemoteTransactionContextSupport.java;h=7be72393a2caff1918cd1f8e75bc392feab5290a;hb=422ac9fbe65c02f942c1fed41ff4aa96545f4224;hp=4f41d8902e029dc97b99b9cb385e47682e076f7b;hpb=c796596b5c46b5203c30b143e6282662e66c5642;p=controller.git
diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContextSupport.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContextSupport.java
index 4f41d8902e..7be72393a2 100644
--- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContextSupport.java
+++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/RemoteTransactionContextSupport.java
@@ -8,11 +8,12 @@
*/
package org.opendaylight.controller.cluster.datastore;
+import static java.util.Objects.requireNonNull;
+
import akka.actor.ActorSelection;
import akka.dispatch.OnComplete;
import akka.pattern.AskTimeoutException;
import akka.util.Timeout;
-import com.google.common.base.Preconditions;
import java.util.concurrent.TimeUnit;
import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException;
@@ -20,8 +21,7 @@ import org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRe
import org.opendaylight.controller.cluster.datastore.messages.CreateTransaction;
import org.opendaylight.controller.cluster.datastore.messages.CreateTransactionReply;
import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo;
-import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
-import org.opendaylight.controller.cluster.datastore.utils.TransactionIdentifierUtils;
+import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scala.concurrent.Future;
@@ -31,7 +31,7 @@ import scala.concurrent.duration.FiniteDuration;
* Handles creation of TransactionContext instances for remote transactions. This class creates
* remote transactions, if necessary, by sending CreateTransaction messages with retries, up to a limit,
* if the shard doesn't have a leader yet. This is done by scheduling a retry task after a short delay.
- *
+ *
* The end result from a completed CreateTransaction message is a TransactionContext that is
* used to perform transaction operations. Transaction operations that occur before the
* CreateTransaction completes are cache via a TransactionContextWrapper and executed once the
@@ -60,21 +60,21 @@ final class RemoteTransactionContextSupport {
private final TransactionContextWrapper transactionContextWrapper;
- RemoteTransactionContextSupport(final TransactionContextWrapper transactionContextWrapper, final TransactionProxy parent,
- final String shardName) {
- this.parent = Preconditions.checkNotNull(parent);
+ RemoteTransactionContextSupport(final TransactionContextWrapper transactionContextWrapper,
+ final TransactionProxy parent, final String shardName) {
+ this.parent = requireNonNull(parent);
this.shardName = shardName;
this.transactionContextWrapper = transactionContextWrapper;
// For the total create tx timeout, use 2 times the election timeout. This should be enough time for
// a leader re-election to occur if we happen to hit it in transition.
- totalCreateTxTimeout = parent.getActorContext().getDatastoreContext().getShardRaftConfig()
+ totalCreateTxTimeout = parent.getActorUtils().getDatastoreContext().getShardRaftConfig()
.getElectionTimeOutInterval().toMillis() * 2;
// We'll use the operationTimeout for the the create Tx message timeout so it can be set appropriately
// for unit tests but cap it at MAX_CREATE_TX_MSG_TIMEOUT_IN_MS. The operationTimeout could be set
// larger than the totalCreateTxTimeout in production which we don't want.
- long operationTimeout = parent.getActorContext().getOperationTimeout().duration().toMillis();
+ long operationTimeout = parent.getActorUtils().getOperationTimeout().duration().toMillis();
createTxMessageTimeout = new Timeout(Math.min(operationTimeout, MAX_CREATE_TX_MSG_TIMEOUT_IN_MS),
TimeUnit.MILLISECONDS);
}
@@ -87,8 +87,8 @@ final class RemoteTransactionContextSupport {
return parent.getType();
}
- private ActorContext getActorContext() {
- return parent.getActorContext();
+ private ActorUtils getActorUtils() {
+ return parent.getActorUtils();
}
private TransactionIdentifier getIdentifier() {
@@ -98,12 +98,12 @@ final class RemoteTransactionContextSupport {
/**
* Sets the target primary shard and initiates a CreateTransaction try.
*/
- void setPrimaryShard(PrimaryShardInfo primaryShardInfo) {
- this.primaryShardInfo = primaryShardInfo;
+ void setPrimaryShard(final PrimaryShardInfo newPrimaryShardInfo) {
+ this.primaryShardInfo = newPrimaryShardInfo;
- if (getTransactionType() == TransactionType.WRITE_ONLY &&
- getActorContext().getDatastoreContext().isWriteOnlyTransactionOptimizationsEnabled()) {
- ActorSelection primaryShard = primaryShardInfo.getPrimaryShardActor();
+ if (getTransactionType() == TransactionType.WRITE_ONLY
+ && getActorUtils().getDatastoreContext().isWriteOnlyTransactionOptimizationsEnabled()) {
+ ActorSelection primaryShard = newPrimaryShardInfo.getPrimaryShardActor();
LOG.debug("Tx {} Primary shard {} found - creating WRITE_ONLY transaction context",
getIdentifier(), primaryShard);
@@ -111,61 +111,49 @@ final class RemoteTransactionContextSupport {
// For write-only Tx's we prepare the transaction modifications directly on the shard actor
// to avoid the overhead of creating a separate transaction actor.
transactionContextWrapper.executePriorTransactionOperations(createValidTransactionContext(
- primaryShard, String.valueOf(primaryShard.path()), primaryShardInfo.getPrimaryShardVersion()));
+ primaryShard, String.valueOf(primaryShard.path()), newPrimaryShardInfo.getPrimaryShardVersion()));
} else {
tryCreateTransaction();
}
}
/**
- * @deprecated Temporary utility for extracting transaction chain ID from a {@link TransactionIdentifier}
- */
- @Deprecated
- static String compatTransactionChainId(final TransactionIdentifier txId) {
- final long historyId = txId.getHistoryId().getHistoryId();
- return historyId == 0 ? "" : Long.toUnsignedString(historyId);
- }
-
- /**
- * Performs a CreateTransaction try async.
+ Performs a CreateTransaction try async.
*/
private void tryCreateTransaction() {
- if(LOG.isDebugEnabled()) {
- LOG.debug("Tx {} Primary shard {} found - trying create transaction", getIdentifier(),
- primaryShardInfo.getPrimaryShardActor());
- }
+ LOG.debug("Tx {} Primary shard {} found - trying create transaction", getIdentifier(),
+ primaryShardInfo.getPrimaryShardActor());
- Object serializedCreateMessage = new CreateTransaction(TransactionIdentifierUtils.actorNameFor(getIdentifier()),
- getTransactionType().ordinal(), compatTransactionChainId(getIdentifier()),
+ Object serializedCreateMessage = new CreateTransaction(getIdentifier(), getTransactionType().ordinal(),
primaryShardInfo.getPrimaryShardVersion()).toSerializable();
- Future