From c796596b5c46b5203c30b143e6282662e66c5642 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 17 May 2016 10:29:38 +0200 Subject: [PATCH] BUG-5280: switch transactionIdentifier This eliminates datastore-internal TransactionIdentifier in favor of the concept one, which is structured. Since the structured identifier also includes LocalHistoryIdentifier, this eliminates also ChainedTransactionIdentifier. Change-Id: Iabfa2ddd7aadd1e4913115f342e520ffaa8b84f0 Signed-off-by: Robert Varga --- .../datastore/AbstractTransactionContext.java | 5 +- .../AbstractTransactionContextFactory.java | 39 +++++--- .../DebugThreePhaseCommitCohort.java | 2 +- .../datastore/DistributedDataStore.java | 4 +- .../LocalThreePhaseCommitCohort.java | 7 +- .../datastore/LocalTransactionChain.java | 6 +- .../datastore/LocalTransactionContext.java | 2 +- .../datastore/LocalTransactionFactory.java | 2 +- .../LocalTransactionFactoryImpl.java | 2 +- .../datastore/NoOpTransactionContext.java | 2 +- .../cluster/datastore/OperationLimiter.java | 2 +- .../datastore/RemoteTransactionContext.java | 7 +- .../RemoteTransactionContextSupport.java | 16 +++- .../datastore/SingleCommitCohortProxy.java | 8 +- .../datastore/TransactionChainProxy.java | 22 ++--- .../datastore/TransactionContextFactory.java | 24 ++--- .../datastore/TransactionContextWrapper.java | 4 +- .../cluster/datastore/TransactionProxy.java | 9 +- .../TransactionReadyReplyMapper.java | 2 +- ...EntityOwnershipShardCommitCoordinator.java | 26 ++++-- .../ChainedTransactionIdentifier.java | 46 --------- .../TransactionChainIdentifier.java | 45 --------- .../identifiers/TransactionIdentifier.java | 93 ------------------- .../utils/TransactionIdentifierUtils.java | 35 +++++++ .../AbstractTransactionProxyTest.java | 6 +- .../DebugThreePhaseCommitCohortTest.java | 8 +- .../LocalTransactionContextTest.java | 12 +-- .../cluster/datastore/MockIdentifiers.java | 30 ++++++ .../datastore/OperationLimiterTest.java | 7 +- .../datastore/TransactionChainProxyTest.java | 48 +++++----- .../TransactionContextWrapperTest.java | 14 +-- .../datastore/TransactionProxyTest.java | 2 +- .../compat/PreBoronTransactionProxyTest.java | 4 +- .../ChainedTransactionIdentifierTest.java | 33 ------- .../TransactionChainIdentifierTest.java | 42 --------- 35 files changed, 218 insertions(+), 398 deletions(-) delete mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/ChainedTransactionIdentifier.java delete mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/TransactionChainIdentifier.java delete mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/TransactionIdentifier.java create mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/TransactionIdentifierUtils.java create mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/MockIdentifiers.java delete mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/identifiers/ChainedTransactionIdentifierTest.java delete mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/identifiers/TransactionChainIdentifierTest.java diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContext.java index 7b25abbe83..057dbfa56a 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionContext.java @@ -8,7 +8,7 @@ package org.opendaylight.controller.cluster.datastore; import javax.annotation.Nonnull; -import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,8 +23,7 @@ abstract class AbstractTransactionContext implements TransactionContext { this(transactionIdentifier, DataStoreVersions.CURRENT_VERSION); } - protected AbstractTransactionContext(TransactionIdentifier transactionIdentifier, - short transactionVersion) { + protected AbstractTransactionContext(TransactionIdentifier transactionIdentifier, short transactionVersion) { this.transactionIdentifier = transactionIdentifier; this.transactionVersion = transactionVersion; } 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..b5afd596bf 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,28 +36,37 @@ 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; } + final LocalHistoryIdentifier getHistoryId() { + return historyId; + } + 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); @@ -147,9 +157,8 @@ abstract class AbstractTransactionContextFactory transaction, final DataTreeModification modification) { + protected DOMStoreThreePhaseCommitCohort createCohort( + final SnapshotBackedWriteTransaction transaction, + final DataTreeModification modification) { return new LocalChainThreePhaseCommitCohort(transaction, modification); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContext.java index 55ff68e39f..0dbd2a284d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContext.java @@ -12,7 +12,7 @@ import com.google.common.base.Preconditions; import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.SettableFuture; -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.modification.AbstractModification; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionFactory.java index ff0ef76cec..a08fef8eb1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionFactory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionFactory.java @@ -7,7 +7,7 @@ */ package org.opendaylight.controller.cluster.datastore; -import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionFactoryImpl.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionFactoryImpl.java index 700d96f4fd..7c05fef87f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionFactoryImpl.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalTransactionFactoryImpl.java @@ -11,7 +11,7 @@ import akka.actor.ActorSelection; import com.google.common.base.Preconditions; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/NoOpTransactionContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/NoOpTransactionContext.java index b3dd638e56..3f5a1521dc 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/NoOpTransactionContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/NoOpTransactionContext.java @@ -9,8 +9,8 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorSelection; import com.google.common.util.concurrent.SettableFuture; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.exceptions.NoShardLeaderException; -import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.messages.AbstractRead; import org.opendaylight.controller.cluster.datastore.modification.AbstractModification; import org.opendaylight.controller.md.sal.common.api.data.DataStoreUnavailableException; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OperationLimiter.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OperationLimiter.java index 22413badc8..ad26d0a50b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OperationLimiter.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/OperationLimiter.java @@ -12,7 +12,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; -import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.messages.BatchedModificationsReply; import org.slf4j.Logger; import org.slf4j.LoggerFactory; 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 29783a6e7d..75c5de82c3 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,7 +13,7 @@ import akka.dispatch.OnComplete; import akka.util.Timeout; import com.google.common.base.Preconditions; import com.google.common.util.concurrent.SettableFuture; -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.BatchedModifications; import org.opendaylight.controller.cluster.datastore.messages.CloseTransaction; @@ -21,6 +21,7 @@ import org.opendaylight.controller.cluster.datastore.messages.SerializableMessag import org.opendaylight.controller.cluster.datastore.modification.AbstractModification; import org.opendaylight.controller.cluster.datastore.modification.Modification; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; +import org.opendaylight.controller.cluster.datastore.utils.TransactionIdentifierUtils; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -105,8 +106,8 @@ public class RemoteTransactionContext extends AbstractTransactionContext { } private BatchedModifications newBatchedModifications() { - return new BatchedModifications(getIdentifier().toString(), getTransactionVersion(), - getIdentifier().getChainId()); + return new BatchedModifications(TransactionIdentifierUtils.actorNameFor(getIdentifier()), + getTransactionVersion(), RemoteTransactionContextSupport.compatTransactionChainId(getIdentifier())); } private void batchModification(Modification modification) { 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 4a031fa916..4f41d8902e 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 @@ -14,13 +14,14 @@ 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; import org.opendaylight.controller.cluster.datastore.exceptions.ShardLeaderNotRespondingException; -import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; 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.slf4j.Logger; import org.slf4j.LoggerFactory; import scala.concurrent.Future; @@ -116,6 +117,15 @@ final class RemoteTransactionContextSupport { } } + /** + * @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. */ @@ -125,8 +135,8 @@ final class RemoteTransactionContextSupport { primaryShardInfo.getPrimaryShardActor()); } - Object serializedCreateMessage = new CreateTransaction(getIdentifier().toString(), - getTransactionType().ordinal(), getIdentifier().getChainId(), + Object serializedCreateMessage = new CreateTransaction(TransactionIdentifierUtils.actorNameFor(getIdentifier()), + getTransactionType().ordinal(), compatTransactionChainId(getIdentifier()), primaryShardInfo.getPrimaryShardVersion()).toSerializable(); Future createTxFuture = getActorContext().executeOperationAsync( diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SingleCommitCohortProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SingleCommitCohortProxy.java index 9c17bc1a47..505c959337 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SingleCommitCohortProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SingleCommitCohortProxy.java @@ -8,10 +8,12 @@ package org.opendaylight.controller.cluster.datastore; import akka.dispatch.OnComplete; +import com.google.common.base.Preconditions; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; import java.util.Arrays; import java.util.List; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; import org.slf4j.Logger; @@ -30,15 +32,15 @@ class SingleCommitCohortProxy extends AbstractThreePhaseCommitCohort { private final ActorContext actorContext; private final Future cohortFuture; - private final String transactionId; + private final TransactionIdentifier transactionId; private volatile DOMStoreThreePhaseCommitCohort delegateCohort = NoOpDOMStoreThreePhaseCommitCohort.INSTANCE; private final OperationCallback.Reference operationCallbackRef; - SingleCommitCohortProxy(ActorContext actorContext, Future cohortFuture, String transactionId, + SingleCommitCohortProxy(ActorContext actorContext, Future cohortFuture, TransactionIdentifier transactionId, OperationCallback.Reference operationCallbackRef) { this.actorContext = actorContext; this.cohortFuture = cohortFuture; - this.transactionId = transactionId; + this.transactionId = Preconditions.checkNotNull(transactionId); this.operationCallbackRef = operationCallbackRef; } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java index cf00d5fa39..b93f540f20 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java @@ -17,12 +17,11 @@ import java.util.List; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import java.util.function.Function; import javax.annotation.Nonnull; -import org.opendaylight.controller.cluster.datastore.identifiers.TransactionChainIdentifier; -import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; +import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChain; import org.opendaylight.controller.cluster.datastore.messages.PrimaryShardInfo; import org.opendaylight.controller.md.sal.common.api.data.TransactionChainClosedException; @@ -120,11 +119,9 @@ final class TransactionChainProxy extends AbstractTransactionContextFactory STATE_UPDATER = AtomicReferenceFieldUpdater.newUpdater(TransactionChainProxy.class, State.class, "currentState"); - private final TransactionChainIdentifier transactionChainId; private final TransactionContextFactory parent; private volatile State currentState = IDLE_STATE; @@ -149,15 +146,13 @@ final class TransactionChainProxy extends AbstractTransactionContextFactory> priorReadOnlyTxPromises = new ConcurrentHashMap<>(); - TransactionChainProxy(final TransactionContextFactory parent) { - super(parent.getActorContext()); - - transactionChainId = new TransactionChainIdentifier(parent.getActorContext().getCurrentMemberName(), CHAIN_COUNTER.incrementAndGet()); + TransactionChainProxy(final TransactionContextFactory parent, final LocalHistoryIdentifier historyId) { + super(parent.getActorContext(), historyId); this.parent = parent; } public String getTransactionChainId() { - return transactionChainId.toString(); + return getHistoryId().toString(); } @Override @@ -189,7 +184,7 @@ final class TransactionChainProxy extends AbstractTransactionContextFactory() { @Override public Object apply(Short version) { - return new CloseTransactionChain(transactionChainId.toString(), version).toSerializable(); + return new CloseTransactionChain(getHistoryId().toString(), version).toSerializable(); } }); } @@ -337,9 +332,4 @@ final class TransactionChainProxy extends AbstractTransactionContextFactory { + private final AtomicLong nextHistory = new AtomicLong(1); - private TransactionContextFactory(final ActorContext actorContext) { - super(actorContext); - } - - static TransactionContextFactory create(final ActorContext actorContext) { - return new TransactionContextFactory(actorContext); + TransactionContextFactory(final ActorContext actorContext, final ClientIdentifier clientId) { + super(actorContext, new LocalHistoryIdentifier(clientId, 0)); } @Override public void close() { } - @Override - protected TransactionIdentifier nextIdentifier() { - return TransactionIdentifier.create(getMemberName(), TX_COUNTER.getAndIncrement()); - } - @Override protected LocalTransactionFactoryImpl factoryForShard(final String shardName, final ActorSelection shardLeader, final DataTree dataTree) { return new LocalTransactionFactoryImpl(getActorContext(), shardLeader, dataTree); @@ -55,10 +50,11 @@ final class TransactionContextFactory extends AbstractTransactionContextFactory< } DOMStoreTransactionChain createTransactionChain() { - return new TransactionChainProxy(this); + return new TransactionChainProxy(this, new LocalHistoryIdentifier(getHistoryId().getClientId(), + nextHistory.getAndIncrement())); } @Override - protected void onTransactionContextCreated(TransactionIdentifier transactionId) { + protected void onTransactionContextCreated(final TransactionIdentifier transactionId) { } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionContextWrapper.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionContextWrapper.java index e8dab2c17e..ef9ee68bf0 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionContextWrapper.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionContextWrapper.java @@ -16,7 +16,7 @@ import java.util.Collection; import java.util.List; import java.util.concurrent.TimeUnit; import javax.annotation.concurrent.GuardedBy; -import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,7 +48,7 @@ class TransactionContextWrapper { private final OperationLimiter limiter; - TransactionContextWrapper(TransactionIdentifier identifier, final ActorContext actorContext) { + TransactionContextWrapper(final TransactionIdentifier identifier, final ActorContext actorContext) { this.identifier = Preconditions.checkNotNull(identifier); this.limiter = new OperationLimiter(identifier, actorContext.getDatastoreContext().getShardBatchedModificationCount() + 1, // 1 extra permit for the ready operation 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 b03398093c..ddc9912c95 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 @@ -25,7 +25,7 @@ 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; @@ -35,6 +35,7 @@ import org.opendaylight.controller.cluster.datastore.modification.MergeModificat 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.cluster.datastore.utils.TransactionIdentifierUtils; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.sal.core.spi.data.AbstractDOMStoreTransaction; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; @@ -263,8 +264,8 @@ public class TransactionProxy extends AbstractDOMStoreTransaction getDirectCommitFuture(TransactionContext transactionContext, @@ -299,7 +300,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction pendingModifications = new LinkedList<>(); + private final LocalHistoryIdentifier historyId; + private final Logger log; + private BatchedModifications inflightCommit; private Cancellable retryCommitSchedule; + private long transactionIDCounter = 0; EntityOwnershipShardCommitCoordinator(MemberName localMemberName, Logger log) { - this.localMemberName = localMemberName; - this.log = log; + this.log = Preconditions.checkNotNull(log); + historyId = new LocalHistoryIdentifier( + ClientIdentifier.create(FrontendIdentifier.create(localMemberName, FRONTEND_TYPE), 0), 0); } boolean handleMessage(Object message, EntityOwnershipShard shard) { @@ -194,9 +203,8 @@ class EntityOwnershipShardCommitCoordinator { } BatchedModifications newBatchedModifications() { - BatchedModifications modifications = new BatchedModifications( - TransactionIdentifier.create(localMemberName, ++transactionIDCounter).toString(), - DataStoreVersions.CURRENT_VERSION, ""); + BatchedModifications modifications = new BatchedModifications(TransactionIdentifierUtils.actorNameFor( + new TransactionIdentifier(historyId, ++transactionIDCounter)), DataStoreVersions.CURRENT_VERSION, ""); modifications.setDoCommitOnReady(true); modifications.setReady(true); modifications.setTotalMessagesSent(1); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/ChainedTransactionIdentifier.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/ChainedTransactionIdentifier.java deleted file mode 100644 index 4753437d25..0000000000 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/ChainedTransactionIdentifier.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.cluster.datastore.identifiers; - -import com.google.common.base.Preconditions; -import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; - -/** - * A TransactionIdentifier which is tied to a backend transaction chain. - */ -public class ChainedTransactionIdentifier extends TransactionIdentifier { - private final String chainId; - private Supplier stringRepresentation; - - public ChainedTransactionIdentifier(final TransactionChainIdentifier chainId, final long txnCounter) { - super(chainId.getMemberName(), txnCounter); - Preconditions.checkNotNull(chainId); - this.chainId = chainId.toString(); - stringRepresentation = Suppliers.memoize(new Supplier() { - @Override - public String get() { - return new StringBuilder(chainId.toString().length() + TX_SEPARATOR.length() + 21). - append(chainId).append(TX_SEPARATOR).append(getCounter()).append('-'). - append(getTimestamp()).toString(); - } - }); - } - - - @Override - public String getChainId() { - return chainId; - } - - @Override - public String toString() { - return stringRepresentation.get(); - } - -} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/TransactionChainIdentifier.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/TransactionChainIdentifier.java deleted file mode 100644 index 851e23ced0..0000000000 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/TransactionChainIdentifier.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.cluster.datastore.identifiers; - -import com.google.common.base.Supplier; -import com.google.common.base.Suppliers; -import java.util.concurrent.atomic.AtomicLong; -import org.opendaylight.controller.cluster.access.concepts.MemberName; - -public class TransactionChainIdentifier { - - protected static final String CHAIN_SEPARATOR = "-chn-"; - - private final AtomicLong txnCounter = new AtomicLong(); - private final Supplier stringRepresentation; - private final MemberName memberName; - - public TransactionChainIdentifier(final MemberName memberName, final long counter) { - this.memberName = memberName; - stringRepresentation = Suppliers.memoize(() -> { - final StringBuilder sb = new StringBuilder(); - sb.append(memberName.getName()).append(CHAIN_SEPARATOR); - sb.append(counter); - return sb.toString(); - }); - } - @Override - public String toString() { - return stringRepresentation.get(); - } - - public TransactionIdentifier newTransactionIdentifier(){ - return new ChainedTransactionIdentifier(this, txnCounter.incrementAndGet()); - } - - public MemberName getMemberName() { - return memberName; - } -} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/TransactionIdentifier.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/TransactionIdentifier.java deleted file mode 100644 index 1e8620359a..0000000000 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/TransactionIdentifier.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.cluster.datastore.identifiers; - -import com.google.common.base.Preconditions; -import org.opendaylight.controller.cluster.access.concepts.MemberName; - -public class TransactionIdentifier { - protected static final String TX_SEPARATOR = "-txn-"; - - private final MemberName memberName; - private final long counter; - private final long timestamp; - private String stringRepresentation; - - public TransactionIdentifier(MemberName memberName, long counter) { - this.memberName = Preconditions.checkNotNull(memberName, "memberName should not be null"); - this.counter = counter; - this.timestamp = System.currentTimeMillis(); - } - - public String getChainId() { - return ""; - } - - protected MemberName getMemberName() { - return memberName; - } - - protected long getCounter() { - return counter; - } - - protected long getTimestamp() { - return timestamp; - } - - public static TransactionIdentifier create(MemberName memberName, long counter) { - return new TransactionIdentifier(memberName, counter); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - TransactionIdentifier that = (TransactionIdentifier) o; - - if (counter != that.counter) { - return false; - } - - if (timestamp != that.timestamp) { - return false; - } - - if (!memberName.equals(that.memberName)) { - return false; - } - - return true; - } - - @Override - public int hashCode() { - int result = memberName.hashCode(); - result = 31 * result + (int) (counter ^ (counter >>> 32)); - result = 31 * result + (int)(timestamp ^ (timestamp >>> 32)); - return result; - } - - - @Override - public String toString() { - if(stringRepresentation == null) { - stringRepresentation = new StringBuilder(memberName.getName().length() + TX_SEPARATOR.length() + 21). - append(memberName.getName()).append(TX_SEPARATOR).append(counter).append('-').append(timestamp).toString(); - } - - return stringRepresentation; - } - -} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/TransactionIdentifierUtils.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/TransactionIdentifierUtils.java new file mode 100644 index 0000000000..11daa472a2 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/TransactionIdentifierUtils.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.cluster.datastore.utils; + +import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; +import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier; +import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; + +public final class TransactionIdentifierUtils { + private TransactionIdentifierUtils() { + throw new UnsupportedOperationException(); + } + + public static String actorNameFor(final TransactionIdentifier txId) { + final LocalHistoryIdentifier historyId = txId.getHistoryId(); + final ClientIdentifier clientId = historyId.getClientId(); + final FrontendIdentifier frontendId = clientId.getFrontendId(); + + final StringBuilder sb = new StringBuilder(); + sb.append(frontendId.getMemberName().getName()).append(':'); + sb.append(frontendId.getClientType().getName()).append('@'); + sb.append(clientId.getGeneration()).append(':'); + if (historyId.getHistoryId() != 0) { + sb.append(historyId.getHistoryId()).append('-'); + } + + return sb.append(txId.getTransactionId()).toString(); + } +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionProxyTest.java index f7a52035f5..0fa716a7ff 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/AbstractTransactionProxyTest.java @@ -45,6 +45,7 @@ import org.mockito.ArgumentMatcher; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; import org.opendaylight.controller.cluster.access.concepts.MemberName; import org.opendaylight.controller.cluster.datastore.DatastoreContext.Builder; import org.opendaylight.controller.cluster.datastore.TransactionProxyTest.TestException; @@ -171,7 +172,8 @@ public abstract class AbstractTransactionProxyTest { doReturn(mockClusterWrapper).when(mockActorContext).getClusterWrapper(); doReturn(dataStoreContextBuilder.build()).when(mockActorContext).getDatastoreContext(); - mockComponentFactory = TransactionContextFactory.create(mockActorContext); + final ClientIdentifier mockClientId = MockIdentifiers.clientIdentifier(getClass(), memberName); + mockComponentFactory = new TransactionContextFactory(mockActorContext, mockClientId); Timer timer = new MetricRegistry().timer("test"); doReturn(timer).when(mockActorContext).getOperationTimer(any(String.class)); @@ -188,7 +190,7 @@ public abstract class AbstractTransactionProxyTest { public boolean matches(Object argument) { if(CreateTransaction.class.equals(argument.getClass())) { CreateTransaction obj = CreateTransaction.fromSerializable(argument); - return obj.getTransactionId().startsWith(memberName) && + return obj.getTransactionId().startsWith(memberName + ':') && obj.getTransactionType() == type.ordinal(); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DebugThreePhaseCommitCohortTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DebugThreePhaseCommitCohortTest.java index bee1704fab..43fbfea612 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DebugThreePhaseCommitCohortTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DebugThreePhaseCommitCohortTest.java @@ -21,8 +21,7 @@ import com.google.common.util.concurrent.ListenableFuture; import java.util.ArrayList; import java.util.List; import org.junit.Test; -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.slf4j.Logger; import scala.concurrent.Future; @@ -32,6 +31,8 @@ import scala.concurrent.Future; * @author Thomas Pantelis */ public class DebugThreePhaseCommitCohortTest { + private final TransactionIdentifier transactionId = MockIdentifiers.transactionIdentifier( + DebugThreePhaseCommitCohortTest.class, "mock"); @Test public void test() { @@ -48,9 +49,8 @@ public class DebugThreePhaseCommitCohortTest { List> expCohortFutures = new ArrayList<>(); doReturn(expCohortFutures).when(mockDelegate).getCohortFutures(); - TransactionIdentifier transactionId = TransactionIdentifier.create(MemberName.forName("1"), 1); Throwable debugContext = new RuntimeException("mock"); - DebugThreePhaseCommitCohort cohort = new DebugThreePhaseCommitCohort(transactionId , mockDelegate , debugContext ); + DebugThreePhaseCommitCohort cohort = new DebugThreePhaseCommitCohort(transactionId , mockDelegate , debugContext); Logger mockLogger = mock(Logger.class); cohort.setLogger(mockLogger); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContextTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContextTest.java index dd81b6bc68..e32d0e4642 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContextTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/LocalTransactionContextTest.java @@ -21,7 +21,6 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.messages.DataExists; import org.opendaylight.controller.cluster.datastore.messages.ReadData; import org.opendaylight.controller.cluster.datastore.modification.DeleteModification; @@ -37,18 +36,15 @@ import scala.concurrent.Future; public class LocalTransactionContextTest { @Mock - OperationLimiter limiter; + private OperationLimiter limiter; @Mock - TransactionIdentifier identifier; + private DOMStoreReadWriteTransaction readWriteTransaction; @Mock - DOMStoreReadWriteTransaction readWriteTransaction; + private LocalTransactionReadySupport mockReadySupport; - @Mock - LocalTransactionReadySupport mockReadySupport; - - LocalTransactionContext localTransactionContext; + private LocalTransactionContext localTransactionContext; @Before public void setUp() { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/MockIdentifiers.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/MockIdentifiers.java new file mode 100644 index 0000000000..a4062c1193 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/MockIdentifiers.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.cluster.datastore; + +import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; +import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier; +import org.opendaylight.controller.cluster.access.concepts.FrontendType; +import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; +import org.opendaylight.controller.cluster.access.concepts.MemberName; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; + +public final class MockIdentifiers { + public static ClientIdentifier clientIdentifier(final Class clazz, final String memberName) { + return ClientIdentifier.create(FrontendIdentifier.create(MemberName.forName(memberName), + FrontendType.forName(clazz.getSimpleName())), 0); + } + + public static LocalHistoryIdentifier historyIdentifier(final Class clazz, final String memberName) { + return new LocalHistoryIdentifier(clientIdentifier(clazz, memberName), 0); + } + + public static TransactionIdentifier transactionIdentifier(final Class clazz, final String memberName) { + return new TransactionIdentifier(historyIdentifier(clazz, memberName), 0); + }; +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/OperationLimiterTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/OperationLimiterTest.java index 31a8776e5b..91eda66561 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/OperationLimiterTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/OperationLimiterTest.java @@ -9,8 +9,7 @@ package org.opendaylight.controller.cluster.datastore; import static org.junit.Assert.assertEquals; import org.junit.Test; -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.BatchedModificationsReply; import org.opendaylight.controller.cluster.datastore.messages.DataExistsReply; @@ -20,11 +19,13 @@ import org.opendaylight.controller.cluster.datastore.messages.DataExistsReply; * @author Thomas Pantelis */ public class OperationLimiterTest { + private final TransactionIdentifier transactionId = MockIdentifiers.transactionIdentifier( + OperationLimiterTest.class, "mock"); @Test public void testOnComplete() throws Exception { int permits = 10; - OperationLimiter limiter = new OperationLimiter(new TransactionIdentifier(MemberName.forName("foo"), 1), permits, 1); + OperationLimiter limiter = new OperationLimiter(transactionId, permits, 1); limiter.acquire(permits); int availablePermits = 0; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java index ed6a731162..d0af812608 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxyTest.java @@ -28,6 +28,7 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; import org.junit.Assert; import org.junit.Test; +import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier; import org.opendaylight.controller.cluster.datastore.messages.BatchedModifications; import org.opendaylight.controller.cluster.datastore.modification.WriteModification; import org.opendaylight.controller.cluster.datastore.shardstrategy.DefaultShardStrategy; @@ -41,52 +42,49 @@ import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import scala.concurrent.Promise; public class TransactionChainProxyTest extends AbstractTransactionProxyTest { + private LocalHistoryIdentifier historyId; + + @Override + public void setUp() { + super.setUp(); + historyId = MockIdentifiers.historyIdentifier(TransactionChainProxyTest.class, memberName); + } @SuppressWarnings("resource") @Test - public void testNewReadOnlyTransaction() throws Exception { + public void testNewReadOnlyTransaction() { - DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory).newReadOnlyTransaction(); + DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory, historyId).newReadOnlyTransaction(); Assert.assertTrue(dst instanceof DOMStoreReadTransaction); } @SuppressWarnings("resource") @Test - public void testNewReadWriteTransaction() throws Exception { - DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory).newReadWriteTransaction(); + public void testNewReadWriteTransaction() { + DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory, historyId).newReadWriteTransaction(); Assert.assertTrue(dst instanceof DOMStoreReadWriteTransaction); } @SuppressWarnings("resource") @Test - public void testNewWriteOnlyTransaction() throws Exception { - DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory).newWriteOnlyTransaction(); + public void testNewWriteOnlyTransaction() { + DOMStoreTransaction dst = new TransactionChainProxy(mockComponentFactory, historyId).newWriteOnlyTransaction(); Assert.assertTrue(dst instanceof DOMStoreWriteTransaction); } @Test - public void testClose() throws Exception { - new TransactionChainProxy(mockComponentFactory).close(); + public void testClose() { + new TransactionChainProxy(mockComponentFactory, historyId).close(); verify(mockActorContext, times(1)).broadcast(any(Function.class)); } - @Test - public void testTransactionChainsHaveUniqueId() { - try (TransactionChainProxy one = new TransactionChainProxy(mockComponentFactory)) { - try (TransactionChainProxy two = new TransactionChainProxy(mockComponentFactory)) { - - Assert.assertNotEquals(one.getTransactionChainId(), two.getTransactionChainId()); - } - } - } - @Test public void testRateLimitingUsedInReadWriteTxCreation() { - try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory)) { + try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory, historyId)) { txChainProxy.newReadWriteTransaction(); @@ -96,7 +94,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { @Test public void testRateLimitingUsedInWriteOnlyTxCreation() { - try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory)) { + try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory, historyId)) { txChainProxy.newWriteOnlyTransaction(); @@ -106,7 +104,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { @Test public void testRateLimitingNotUsedInReadOnlyTxCreation() { - try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory)) { + try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory, historyId)) { txChainProxy.newReadOnlyTransaction(); @@ -122,7 +120,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { public void testChainedWriteOnlyTransactions() throws Exception { dataStoreContextBuilder.writeOnlyTransactionOptimizationsEnabled(true); - try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory)) { + try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory, historyId)) { ActorRef txActorRef1 = setupActorContextWithoutInitialCreateTransaction(getSystem()); @@ -190,7 +188,7 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { */ @Test public void testChainedReadWriteTransactions() throws Exception { - try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory)) { + try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory, historyId)) { ActorRef txActorRef1 = setupActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE); @@ -258,12 +256,12 @@ public class TransactionChainProxyTest extends AbstractTransactionProxyTest { } @Test(expected = IllegalStateException.class) - public void testChainedWriteTransactionsWithPreviousTxNotReady() throws Exception { + public void testChainedWriteTransactionsWithPreviousTxNotReady() { ActorRef actorRef = setupActorContextWithInitialCreateTransaction(getSystem(), WRITE_ONLY); expectBatchedModifications(actorRef, 1); - try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory)) { + try (TransactionChainProxy txChainProxy = new TransactionChainProxy(mockComponentFactory, historyId)) { DOMStoreWriteTransaction writeTx1 = txChainProxy.newWriteOnlyTransaction(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionContextWrapperTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionContextWrapperTest.java index 10fee5c6d5..af6e782ed7 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionContextWrapperTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionContextWrapperTest.java @@ -15,27 +15,23 @@ import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; public class TransactionContextWrapperTest { - - @Mock - TransactionIdentifier identifier; - @Mock - ActorContext actorContext; + private ActorContext actorContext; @Mock - TransactionContext transactionContext; + private TransactionContext transactionContext; - TransactionContextWrapper transactionContextWrapper; + private TransactionContextWrapper transactionContextWrapper; @Before public void setUp(){ MockitoAnnotations.initMocks(this); doReturn(DatastoreContext.newBuilder().build()).when(actorContext).getDatastoreContext(); - transactionContextWrapper = new TransactionContextWrapper(identifier, actorContext); + transactionContextWrapper = new TransactionContextWrapper(MockIdentifiers.transactionIdentifier( + TransactionContextWrapperTest.class, "mock"), actorContext); } @Test diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java index 7d23c0affc..eb77ed2c23 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/TransactionProxyTest.java @@ -755,7 +755,7 @@ public class TransactionProxyTest extends AbstractTransactionProxyTest { Object id = transactionProxy.getIdentifier(); assertNotNull("getIdentifier returned null", id); - assertTrue("Invalid identifier: " + id, id.toString().startsWith(memberName)); + assertTrue("Invalid identifier: " + id, id.toString().contains(MemberName.forName(memberName).toString())); } @Test diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreBoronTransactionProxyTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreBoronTransactionProxyTest.java index 0bf4f48cea..f4c777ee61 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreBoronTransactionProxyTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/compat/PreBoronTransactionProxyTest.java @@ -53,7 +53,7 @@ public class PreBoronTransactionProxyTest extends AbstractTransactionProxyTest { public boolean matches(Object argument) { if(ShardTransactionMessages.CreateTransaction.class.equals(argument.getClass())) { CreateTransaction obj = CreateTransaction.fromSerializable(argument); - return obj.getTransactionId().startsWith(memberName) && + return obj.getTransactionId().startsWith(memberName + ':') && obj.getTransactionType() == type.ordinal(); } @@ -119,7 +119,7 @@ public class PreBoronTransactionProxyTest extends AbstractTransactionProxyTest { } @Test - public void testClose() throws Exception{ + public void testClose() { ActorRef actorRef = setupPreBoronActorContextWithInitialCreateTransaction(getSystem(), READ_WRITE); expectBatchedModifications(actorRef, 1); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/identifiers/ChainedTransactionIdentifierTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/identifiers/ChainedTransactionIdentifierTest.java deleted file mode 100644 index 64f04add99..0000000000 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/identifiers/ChainedTransactionIdentifierTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.cluster.datastore.identifiers; - -import static org.hamcrest.CoreMatchers.startsWith; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import org.junit.Test; -import org.opendaylight.controller.cluster.access.concepts.MemberName; - -public class ChainedTransactionIdentifierTest { - - @Test - public void testToString(){ - TransactionChainIdentifier chainId = new TransactionChainIdentifier(MemberName.forName("member-1"), 99); - ChainedTransactionIdentifier chainedTransactionIdentifier = new ChainedTransactionIdentifier(chainId, 100); - - String txnId = chainedTransactionIdentifier.toString(); - - assertTrue(txnId.contains("member-1")); - assertTrue(txnId.contains("100")); - assertTrue(txnId.contains("99")); - - assertThat(txnId, startsWith("member-1-chn-99-txn-100-")); - } - -} \ No newline at end of file diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/identifiers/TransactionChainIdentifierTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/identifiers/TransactionChainIdentifierTest.java deleted file mode 100644 index b86c94c90a..0000000000 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/identifiers/TransactionChainIdentifierTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.controller.cluster.datastore.identifiers; - -import static org.hamcrest.CoreMatchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import org.junit.Test; -import org.opendaylight.controller.cluster.access.concepts.MemberName; - -public class TransactionChainIdentifierTest { - private static final MemberName MEMBER_1 = MemberName.forName("member-1"); - - @Test - public void testToString(){ - TransactionChainIdentifier transactionChainIdentifier = new TransactionChainIdentifier(MEMBER_1, 99); - - String id = transactionChainIdentifier.toString(); - - assertEquals("member-1-chn-99", id); - } - - @Test - public void testNewTransactionIdentifier(){ - TransactionChainIdentifier transactionChainIdentifier = new TransactionChainIdentifier(MEMBER_1, 99); - - TransactionIdentifier txId1 = transactionChainIdentifier.newTransactionIdentifier(); - - assertThat(txId1.toString(), startsWith("member-1-chn-99-txn-1-")); - - TransactionIdentifier txId2 = transactionChainIdentifier.newTransactionIdentifier(); - - assertThat(txId2.toString(), startsWith("member-1-chn-99-txn-2-")); - } - -} \ No newline at end of file -- 2.36.6