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=4832d8a6af5f17bbfa9d3321d37e39dea3ad6229;hp=c90a3f6f6f70edb1f937efc701fad31086114959;hb=93e6f3bfc003d4ce2d968761dff963615a0b799d;hpb=c7e1ddeaf842ebb696c8dd38c0ca14c925ee31a1 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 c90a3f6f6f..4832d8a6af 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 @@ -9,13 +9,14 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorSelection; import akka.dispatch.OnComplete; -import com.google.common.base.Optional; import com.google.common.base.Preconditions; 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 javax.annotation.Nonnull; +import org.opendaylight.controller.cluster.access.concepts.MemberName; import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; @@ -34,6 +35,7 @@ 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(); @@ -55,14 +57,19 @@ abstract class AbstractTransactionContextFactory findPrimaryFuture = findPrimaryShard(shardName); + Future findPrimaryFuture = findPrimaryShard(shardName, parent.getIdentifier()); if(findPrimaryFuture.isCompleted()) { Try maybe = findPrimaryFuture.value().get(); if(maybe.isSuccess()) { - onFindPrimaryShardSuccess(maybe.get(), parent, shardName, transactionContextAdapter); + onFindPrimaryShardSuccess(maybe.get(), parent, shardName, transactionContextWrapper); } else { - onFindPrimaryShardFailure(maybe.failed().get(), parent, shardName, transactionContextAdapter); + onFindPrimaryShardFailure(maybe.failed().get(), parent, shardName, transactionContextWrapper); } } else { findPrimaryFuture.onComplete(new OnComplete() { @Override public void onComplete(final Throwable failure, final PrimaryShardInfo primaryShardInfo) { if (failure == null) { - onFindPrimaryShardSuccess(primaryShardInfo, parent, shardName, transactionContextAdapter); + onFindPrimaryShardSuccess(primaryShardInfo, parent, shardName, transactionContextWrapper); } else { - onFindPrimaryShardFailure(failure, parent, shardName, transactionContextAdapter); + onFindPrimaryShardFailure(failure, parent, shardName, transactionContextWrapper); } } }, actorContext.getClientDispatcher()); } - return transactionContextAdapter; + return transactionContextWrapper; } private void updateShardInfo(final String shardName, final PrimaryShardInfo primaryShardInfo) { @@ -131,13 +147,9 @@ abstract class AbstractTransactionContextFactory findPrimaryShard(String shardName); + protected abstract Future findPrimaryShard(@Nonnull String shardName, + @Nonnull TransactionIdentifier txId); /** * Create local transaction factory for specified shard, backed by specified shard leader @@ -174,11 +187,20 @@ abstract class AbstractTransactionContextFactory void onTransactionReady(@Nonnull TransactionIdentifier transaction, @Nonnull Collection> cohortFutures); - private static TransactionContext createLocalTransactionContext(final LocalTransactionFactory factory, final TransactionProxy parent) { + /** + * Callback invoked when the internal TransactionContext has been created for a transaction. + * + * @param transactionId the ID of the transaction. + */ + protected abstract void onTransactionContextCreated(@Nonnull TransactionIdentifier transactionId); + + private static TransactionContext createLocalTransactionContext(final LocalTransactionFactory factory, + final TransactionProxy parent) { + switch(parent.getType()) { case READ_ONLY: final DOMStoreReadTransaction readOnly = factory.newReadOnlyTransaction(parent.getIdentifier()); - return new LocalTransactionContext(parent.getIdentifier(), readOnly, parent.getLimiter()) { + return new LocalTransactionContext(readOnly, parent.getIdentifier(), factory) { @Override protected DOMStoreWriteTransaction getWriteDelegate() { throw new UnsupportedOperationException(); @@ -191,7 +213,7 @@ abstract class AbstractTransactionContextFactory