Harden ShardCommitCoordinator to survive EOS write retries
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / CohortEntry.java
index a66a49685fa2f1552b269a9c71b65e058cfab571..5e5d0f16cd220759c7ad3d1a99dfa8e6c8f61f06 100644 (file)
@@ -11,6 +11,8 @@ import akka.actor.ActorRef;
 import com.google.common.base.Preconditions;
 import com.google.common.primitives.UnsignedLong;
 import com.google.common.util.concurrent.FutureCallback;
+import java.util.Optional;
+import java.util.SortedSet;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
 import org.opendaylight.controller.cluster.datastore.ShardCommitCoordinator.CohortDecorator;
 import org.opendaylight.controller.cluster.datastore.modification.Modification;
@@ -30,6 +32,7 @@ final class CohortEntry {
     private Shard shard;
 
     private CohortEntry(final ReadWriteShardDataTreeTransaction transaction, final short clientVersion) {
+        this.cohort = null;
         this.transaction = Preconditions.checkNotNull(transaction);
         this.transactionId = transaction.getIdentifier();
         this.clientVersion = clientVersion;
@@ -109,10 +112,10 @@ final class CohortEntry {
         cohort.abort(callback);
     }
 
-    void ready(final CohortDecorator cohortDecorator) {
+    void ready(final Optional<SortedSet<String>> participatingShardNames, final CohortDecorator cohortDecorator) {
         Preconditions.checkState(cohort == null, "cohort was already set");
 
-        cohort = transaction.ready();
+        cohort = transaction.ready(participatingShardNames);
 
         if (cohortDecorator != null) {
             // Call the hook for unit tests.
@@ -120,6 +123,14 @@ final class CohortEntry {
         }
     }
 
+    boolean isSealed() {
+        return cohort != null;
+    }
+
+    Optional<SortedSet<String>> getParticipatingShardNames() {
+        return cohort != null ? cohort.getParticipatingShardNames() : Optional.empty();
+    }
+
     boolean isDoImmediateCommit() {
         return doImmediateCommit;
     }