BUG-7033: Implement pipe-lining in ShardDataTree
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / CompositeDataTreeCohort.java
index 05b9981113a039a75b3679698d9ddd61e8d97318..006555f1f8b97d9007cbe0ba19865e2bcb8f3904 100644 (file)
@@ -70,7 +70,7 @@ class CompositeDataTreeCohort {
          */
         COMMITED,
         /**
-         * Some of cohorts responsed back with unsuccessful message.
+         * Some of cohorts responded back with unsuccessful message.
          */
         FAILED,
         /**
@@ -102,6 +102,23 @@ class CompositeDataTreeCohort {
         this.timeout = Preconditions.checkNotNull(timeout);
     }
 
+    void reset() {
+        switch (state) {
+            case CAN_COMMIT_SENT:
+            case CAN_COMMIT_SUCCESSFUL:
+            case PRE_COMMIT_SENT:
+            case PRE_COMMIT_SUCCESSFUL:
+            case COMMIT_SENT:
+                abort();
+                break;
+            default :
+                break;
+        }
+
+        successfulFromPrevious = null;
+        state = State.IDLE;
+    }
+
     void canCommit(final DataTreeCandidate tip) throws ExecutionException, TimeoutException {
         Collection<CanCommit> messages = registry.createCanCommitMessages(txId, tip, schema);
         // FIXME: Optimize empty collection list with pre-created futures, containing success.
@@ -127,7 +144,8 @@ class CompositeDataTreeCohort {
     }
 
     Optional<Future<Iterable<Object>>> abort() {
-        if (successfulFromPrevious != null) {
+        state = State.ABORTED;
+        if (successfulFromPrevious != null && !Iterables.isEmpty(successfulFromPrevious)) {
             return Optional.of(sendMesageToSuccessful(new DataTreeCohortActor.Abort(txId)));
         }