Fix illegal check in CreateTransactionReply
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / TransactionContextWrapper.java
index 0e1260962d37d807f53233729f3f999e996faed9..38f55f300f52334e15b718d9c2aa094b056199dc 100644 (file)
@@ -15,6 +15,8 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.SortedSet;
 import java.util.concurrent.TimeUnit;
 import javax.annotation.concurrent.GuardedBy;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
@@ -166,9 +168,6 @@ class TransactionContextWrapper {
                     if (!pendingEnqueue) {
                         // We're done invoking the TransactionOperations so we can now publish the TransactionContext.
                         localTransactionContext.operationHandOffComplete();
-                        if (!localTransactionContext.usesOperationLimiting()) {
-                            limiter.releaseAll();
-                        }
 
                         // This is null-to-non-null transition after which we are releasing the lock and not doing
                         // any further processing.
@@ -183,27 +182,32 @@ class TransactionContextWrapper {
                 queuedTxOperations.clear();
             }
 
-            // Invoke TransactionOperations outside the sync block to avoid unnecessary blocking.
-            // A slight down-side is that we need to re-acquire the lock below but this should
-            // be negligible.
+            // Invoke TransactionOperations outside the sync block to avoid unnecessary blocking. A slight down-side is
+            // that we need to re-acquire the lock below but this should be negligible.
             for (Entry<TransactionOperation, Boolean> oper : operationsBatch) {
-                oper.getKey().invoke(localTransactionContext, oper.getValue());
+                final Boolean permit = oper.getValue();
+                if (permit.booleanValue() && !localTransactionContext.usesOperationLimiting()) {
+                    // If the context is not using limiting we need to release operations as we are queueing them, so
+                    // user threads are not charged for them.
+                    limiter.release();
+                }
+                oper.getKey().invoke(localTransactionContext, permit);
             }
         }
     }
 
-    Future<ActorSelection> readyTransaction() {
+    Future<ActorSelection> readyTransaction(Optional<SortedSet<String>> participatingShardNames) {
         // avoid the creation of a promise and a TransactionOperation
         final TransactionContext localContext = transactionContext;
         if (localContext != null) {
-            return localContext.readyTransaction(null);
+            return localContext.readyTransaction(null, participatingShardNames);
         }
 
         final Promise<ActorSelection> promise = Futures.promise();
         enqueueTransactionOperation(new TransactionOperation() {
             @Override
             public void invoke(final TransactionContext newTransactionContext, final Boolean havePermit) {
-                promise.completeWith(newTransactionContext.readyTransaction(havePermit));
+                promise.completeWith(newTransactionContext.readyTransaction(havePermit, participatingShardNames));
             }
         });