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%2FAbstractTransactionContextFactory.java;h=69c69bb84b395dc5d89db35f74cdd44343987c95;hp=4832d8a6af5f17bbfa9d3321d37e39dea3ad6229;hb=ef3b9a8300db1c791f2c4088d39152ccf9f5b97c;hpb=4e3f49788c05730b29468deebc2aaa4ed0d94eef diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContextFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContextFactory.java index 4832d8a6af..69c69bb84b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContextFactory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContextFactory.java @@ -14,10 +14,11 @@ import java.util.Collection; import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.atomic.AtomicLong; +import java.util.concurrent.atomic.AtomicLongFieldUpdater; import javax.annotation.Nonnull; +import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; import org.opendaylight.controller.cluster.access.concepts.MemberName; -import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; @@ -35,32 +36,43 @@ import scala.util.Try; */ abstract class AbstractTransactionContextFactory implements AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(AbstractTransactionContextFactory.class); - private static final MemberName UNKNOWN_MEMBER = MemberName.forName("UNKNOWN-MEMBER"); - - protected static final AtomicLong TX_COUNTER = new AtomicLong(); + @SuppressWarnings("rawtypes") + private static final AtomicLongFieldUpdater TX_COUNTER_UPDATER = + AtomicLongFieldUpdater.newUpdater(AbstractTransactionContextFactory.class, "nextTx"); private final ConcurrentMap knownLocal = new ConcurrentHashMap<>(); + private final LocalHistoryIdentifier historyId; private final ActorContext actorContext; - protected AbstractTransactionContextFactory(final ActorContext actorContext) { + // Used via TX_COUNTER_UPDATER + @SuppressWarnings("unused") + private volatile long nextTx; + + protected AbstractTransactionContextFactory(final ActorContext actorContext, + final LocalHistoryIdentifier historyId) { this.actorContext = Preconditions.checkNotNull(actorContext); + this.historyId = Preconditions.checkNotNull(historyId); } final ActorContext getActorContext() { return actorContext; } - private TransactionContext maybeCreateLocalTransactionContext(final TransactionProxy parent, final String shardName) { + final LocalHistoryIdentifier getHistoryId() { + return historyId; + } + + @SuppressWarnings("checkstyle:IllegalCatch") + private TransactionContext maybeCreateLocalTransactionContext(final TransactionProxy parent, + final String shardName) { final LocalTransactionFactory local = knownLocal.get(shardName); if (local != null) { - if(LOG.isDebugEnabled()) { - LOG.debug("Tx {} - Creating local component for shard {} using factory {}", - parent.getIdentifier(), shardName, local); - } + LOG.debug("Tx {} - Creating local component for shard {} using factory {}", parent.getIdentifier(), + shardName, local); try { return createLocalTransactionContext(local, parent); - } catch(Exception e) { + } catch (Exception e) { return new NoOpTransactionContext(e, parent.getIdentifier()); } } @@ -70,16 +82,14 @@ abstract class AbstractTransactionContextFactory findPrimaryFuture = findPrimaryShard(shardName, parent.getIdentifier()); - if(findPrimaryFuture.isCompleted()) { + if (findPrimaryFuture.isCompleted()) { Try maybe = findPrimaryFuture.value().get(); - if(maybe.isSuccess()) { + if (maybe.isSuccess()) { onFindPrimaryShardSuccess(maybe.get(), parent, shardName, transactionContextWrapper); } else { onFindPrimaryShardFailure(maybe.failed().get(), parent, shardName, transactionContextWrapper); @@ -134,22 +145,21 @@ abstract class AbstractTransactionContextFactory maybeDataTree = primaryShardInfo.getLocalShardDataTree(); if (maybeDataTree.isPresent()) { - if(!knownLocal.containsKey(shardName)) { + if (!knownLocal.containsKey(shardName)) { LOG.debug("Shard {} resolved to local data tree - adding local factory", shardName); F factory = factoryForShard(shardName, primaryShardInfo.getPrimaryShardActor(), maybeDataTree.get()); knownLocal.putIfAbsent(shardName, factory); } - } else if(knownLocal.containsKey(shardName)) { + } else if (knownLocal.containsKey(shardName)) { LOG.debug("Shard {} invalidating local data tree", shardName); knownLocal.remove(shardName); } } - protected MemberName getMemberName() { - final MemberName ret = getActorContext().getCurrentMemberName(); - return ret == null ? UNKNOWN_MEMBER : ret; + protected final MemberName getMemberName() { + return historyId.getClientId().getFrontendId().getMemberName(); } /** @@ -157,7 +167,9 @@ abstract class AbstractTransactionContextFactory void onTransactionReady(@Nonnull TransactionIdentifier transaction, @Nonnull Collection> cohortFutures); + protected abstract void onTransactionReady(@Nonnull TransactionIdentifier transaction, + @Nonnull Collection> cohortFutures); /** * Callback invoked when the internal TransactionContext has been created for a transaction. @@ -197,7 +210,7 @@ abstract class AbstractTransactionContextFactory