CDS: Introduce ChainedTransactionIdentifier 47/19147/5
authorRobert Varga <rovarga@cisco.com>
Mon, 27 Apr 2015 12:40:45 +0000 (14:40 +0200)
committerTom Pantelis <tpanteli@brocade.com>
Fri, 8 May 2015 22:05:05 +0000 (18:05 -0400)
Conceptually the identifier of a a transaction is an extension point,
which allows passing of arbitratry, extensible identifier. It can thus
be reused to track the chain identifier as well as the normal source
coordinates.

Introduce ChainedTransactionIdentifier to carry the transaction chain ID
attached to the transaction on the frontend. This is not used in this
commit directly, but rather in the follow-up patch.

Change-Id: Iad24a1b59c6231e003579bb25149b73b11d6db25
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionContextImpl.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/compat/PreLithiumTransactionContextImpl.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/ChainedTransactionIdentifier.java [new file with mode: 0644]
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/identifiers/TransactionIdentifier.java

index 63690b0..b6fe2c2 100644 (file)
@@ -37,7 +37,6 @@ import scala.concurrent.Future;
 public class TransactionContextImpl extends AbstractTransactionContext {
     private static final Logger LOG = LoggerFactory.getLogger(TransactionContextImpl.class);
 
-    private final String transactionChainId;
     private final ActorContext actorContext;
     private final ActorSelection actor;
     private final boolean isTxActorLocal;
@@ -48,11 +47,10 @@ public class TransactionContextImpl extends AbstractTransactionContext {
     private int totalBatchedModificationsSent;
 
     protected TransactionContextImpl(ActorSelection actor, TransactionIdentifier identifier,
-            String transactionChainId, ActorContext actorContext, boolean isTxActorLocal,
+            ActorContext actorContext, boolean isTxActorLocal,
             short remoteTransactionVersion, OperationCompleter operationCompleter) {
         super(identifier);
         this.actor = actor;
-        this.transactionChainId = transactionChainId;
         this.actorContext = actorContext;
         this.isTxActorLocal = isTxActorLocal;
         this.remoteTransactionVersion = remoteTransactionVersion;
@@ -141,7 +139,7 @@ public class TransactionContextImpl extends AbstractTransactionContext {
     }
 
     private BatchedModifications newBatchedModifications() {
-        return new BatchedModifications(getIdentifier().toString(), remoteTransactionVersion, transactionChainId);
+        return new BatchedModifications(getIdentifier().toString(), remoteTransactionVersion, getIdentifier().getChainId());
     }
 
     private void batchModification(Modification modification) {
index 9504343..5081c9b 100644 (file)
@@ -97,7 +97,6 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
 
     private final TransactionType transactionType;
     final ActorContext actorContext;
-    private final String transactionChainId;
     private final SchemaContext schemaContext;
     private TransactionState state = TransactionState.OPEN;
 
@@ -110,25 +109,24 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
     }
 
     public TransactionProxy(ActorContext actorContext, TransactionType transactionType, String transactionChainId) {
-        super(createIdentifier(actorContext));
+        super(createIdentifier(actorContext, transactionChainId));
         this.actorContext = Preconditions.checkNotNull(actorContext,
             "actorContext should not be null");
         this.transactionType = Preconditions.checkNotNull(transactionType,
             "transactionType should not be null");
         this.schemaContext = Preconditions.checkNotNull(actorContext.getSchemaContext(),
             "schemaContext should not be null");
-        this.transactionChainId = transactionChainId;
 
         LOG.debug("Created txn {} of type {} on chain {}", getIdentifier(), transactionType, transactionChainId);
     }
 
-    private static TransactionIdentifier createIdentifier(ActorContext actorContext) {
+    private static TransactionIdentifier createIdentifier(ActorContext actorContext, String transactionChainId) {
         String memberName = actorContext.getCurrentMemberName();
         if (memberName == null) {
             memberName = "UNKNOWN-MEMBER";
         }
 
-        return new TransactionIdentifier(memberName, counter.getAndIncrement());
+        return TransactionIdentifier.create(memberName, counter.getAndIncrement(), transactionChainId);
     }
 
     @VisibleForTesting
@@ -364,7 +362,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
         TransactionFutureCallback txFutureCallback = txFutureCallbackMap.values().iterator().next();
 
         LOG.debug("Tx {} Readying transaction for shard {} on chain {}", getIdentifier(),
-                txFutureCallback.getShardName(), transactionChainId);
+                txFutureCallback.getShardName(), getTransactionChainId());
 
         final OperationCallback.Reference operationCallbackRef =
                 new OperationCallback.Reference(OperationCallback.NO_OP_CALLBACK);
@@ -404,7 +402,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
         for(TransactionFutureCallback txFutureCallback : txFutureCallbackMap.values()) {
 
             LOG.debug("Tx {} Readying transaction for shard {} on chain {}", getIdentifier(),
-                        txFutureCallback.getShardName(), transactionChainId);
+                        txFutureCallback.getShardName(), getTransactionChainId());
 
             final TransactionContext transactionContext = txFutureCallback.getTransactionContext();
             final Future<ActorSelection> future;
@@ -504,7 +502,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
     }
 
     String getTransactionChainId() {
-        return transactionChainId;
+        return getIdentifier().getChainId();
     }
 
     protected ActorContext getActorContext() {
@@ -541,10 +539,10 @@ public class TransactionProxy extends AbstractDOMStoreTransaction<TransactionIde
 
         if(remoteTransactionVersion < DataStoreVersions.LITHIUM_VERSION) {
             return new PreLithiumTransactionContextImpl(transactionPath, transactionActor, getIdentifier(),
-                    transactionChainId, actorContext, isTxActorLocal, remoteTransactionVersion,
+                    actorContext, isTxActorLocal, remoteTransactionVersion,
                     operationCompleter);
         } else {
-            return new TransactionContextImpl(transactionActor, getIdentifier(), transactionChainId,
+            return new TransactionContextImpl(transactionActor, getIdentifier(),
                     actorContext, isTxActorLocal, remoteTransactionVersion, operationCompleter);
         }
     }
index 1c7cff9..249a115 100644 (file)
@@ -36,10 +36,9 @@ public class PreLithiumTransactionContextImpl extends TransactionContextImpl {
     private final String transactionPath;
 
     public PreLithiumTransactionContextImpl(String transactionPath, ActorSelection actor, TransactionIdentifier identifier,
-            String transactionChainId, ActorContext actorContext, boolean isTxActorLocal,
+            ActorContext actorContext, boolean isTxActorLocal,
             short remoteTransactionVersion, OperationCompleter operationCompleter) {
-        super(actor, identifier, transactionChainId, actorContext, isTxActorLocal,
-                remoteTransactionVersion, operationCompleter);
+        super(actor, identifier, actorContext, isTxActorLocal, remoteTransactionVersion, operationCompleter);
         this.transactionPath = transactionPath;
     }
 
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
new file mode 100644 (file)
index 0000000..1aec854
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * 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;
+
+/**
+ * A TransactionIdentifier which is tied to a backend transaction chain.
+ */
+public class ChainedTransactionIdentifier extends TransactionIdentifier {
+    private final String chainId;
+
+    public ChainedTransactionIdentifier(final String memberName, final long counter, final String chainId) {
+        super(memberName, counter);
+        this.chainId = Preconditions.checkNotNull(chainId);
+    }
+
+    @Override
+    public String getChainId() {
+        return chainId;
+    }
+}
index 32637a5..6742b5c 100644 (file)
@@ -9,6 +9,7 @@
 package org.opendaylight.controller.cluster.datastore.identifiers;
 
 import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
 
 public class TransactionIdentifier {
     private static final String TX_SEPARATOR = "-txn-";
@@ -22,6 +23,18 @@ public class TransactionIdentifier {
         this.counter = counter;
     }
 
+    public String getChainId() {
+        return "";
+    }
+
+    public static TransactionIdentifier create(String memberName, long counter, String chainId) {
+        if (Strings.isNullOrEmpty(chainId)) {
+            return new TransactionIdentifier(memberName, counter);
+        } else {
+            return new ChainedTransactionIdentifier(memberName, counter, chainId);
+        }
+    }
+
     @Override
     public boolean equals(Object o) {
         if (this == o) {