BUG-5414 introduce EOS inJeopardy flag
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / entityownership / EntityOwnershipShardCommitCoordinator.java
index 6c15ef6ed05cb2fb41b7b837e3655b0fef167beb..2da7e5ec238a0808ef4f6fd1169cf2dbc5aa6f69 100644 (file)
@@ -28,7 +28,12 @@ import scala.concurrent.duration.FiniteDuration;
  * @author Thomas Pantelis
  */
 class EntityOwnershipShardCommitCoordinator {
-    private static final Object COMMIT_RETRY_MESSAGE = "entityCommitRetry";
+    private static final Object COMMIT_RETRY_MESSAGE = new Object() {
+        @Override
+        public String toString() {
+            return "entityCommitRetry";
+        }
+    };
 
     private final Logger log;
     private int transactionIDCounter = 0;
@@ -44,13 +49,13 @@ class EntityOwnershipShardCommitCoordinator {
 
     boolean handleMessage(Object message, EntityOwnershipShard shard) {
         boolean handled = true;
-        if(CommitTransactionReply.SERIALIZABLE_CLASS.isInstance(message)) {
+        if(CommitTransactionReply.isSerializedType(message)) {
             // Successful reply from a local commit.
             inflightCommitSucceeded(shard);
         } else if(message instanceof akka.actor.Status.Failure) {
             // Failure reply from a local commit.
             inflightCommitFailure(((Failure)message).cause(), shard);
-        } else if(message.equals(COMMIT_RETRY_MESSAGE)) {
+        } else if(COMMIT_RETRY_MESSAGE.equals(message)) {
             retryInflightCommit(shard);
         } else {
             handled = false;
@@ -140,18 +145,26 @@ class EntityOwnershipShardCommitCoordinator {
     }
 
     void commitModification(Modification modification, EntityOwnershipShard shard) {
+        BatchedModifications modifications = newBatchedModifications();
+        modifications.addModification(modification);
+        commitModifications(modifications, shard);
+    }
+
+    void commitModifications(BatchedModifications modifications, EntityOwnershipShard shard) {
+        if(modifications.getModifications().isEmpty()) {
+            return;
+        }
+
         boolean hasLeader = shard.hasLeader();
         if(inflightCommit != null || !hasLeader) {
             if(log.isDebugEnabled()) {
-                log.debug("{} - adding modification to pending",
+                log.debug("{} - adding modifications to pending",
                         (inflightCommit != null ? "A commit is inflight" : "No shard leader"));
             }
 
-            pendingModifications.add(modification);
+            pendingModifications.addAll(modifications.getModifications());
         } else {
-            inflightCommit = newBatchedModifications();
-            inflightCommit.addModification(modification);
-
+            inflightCommit = modifications;
             shard.tryCommitModifications(inflightCommit);
         }
     }
@@ -179,7 +192,7 @@ class EntityOwnershipShardCommitCoordinator {
         inflightCommit = newBatchedModifications;
     }
 
-    private BatchedModifications newBatchedModifications() {
+    BatchedModifications newBatchedModifications() {
         BatchedModifications modifications = new BatchedModifications(
                 TransactionIdentifier.create(localMemberName, ++transactionIDCounter).toString(),
                 DataStoreVersions.CURRENT_VERSION, "");