Update DOMStoreThreePhaseCommitCohort design 21/100021/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 9 Mar 2022 11:38:23 +0000 (12:38 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 9 Mar 2022 11:44:48 +0000 (12:44 +0100)
Do not use ListenableFuture<Void>, which promotes propagation of nulls
across the system. Use instead yang.common.Empty, which has a non-null
singleton value. Also allow commit() to propagate more information
through CommitInfo.

Change-Id: Ib3874c2c84cadcf1f5fb386a38ae5d0a2cb796be
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
dom/mdsal-dom-broker/pom.xml
dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/TestCommitCohort.java
dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/ChainedTransactionCommitImpl.java
dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMStoreThreePhaseCommitCohort.java
dom/mdsal-dom-spi/src/main/java/module-info.java
dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/store/DOMStoreThreePhaseCommitCohort.java
dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/store/ForwardingDOMStoreThreePhaseCommitCohort.java

index e2f0fdc3cddd2cd6992aff2ffd07f2656369cde6..a6c9d4a507515aaeffbb58c24b97c4d55a4c67c4 100644 (file)
             <groupId>org.opendaylight.yangtools</groupId>
             <artifactId>yang-data-api</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>yang-data-tree-api</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.yangtools</groupId>
             <artifactId>yang-data-impl</artifactId>
index a380cf02aa68e0e4f6bd29d4c31ae806ba56b1b5..79aba5f0df2bc10f9f9c2ebbf5ce5c809566fdbe 100644 (file)
@@ -9,53 +9,52 @@ package org.opendaylight.mdsal.dom.broker;
 
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
+import org.opendaylight.yangtools.yang.common.Empty;
 
 public enum TestCommitCohort implements DOMStoreThreePhaseCommitCohort {
+    ALLWAYS_SUCCESS(true, true, true, true),
+    CAN_COMMIT_FAILED(false, false, false, true),
+    PRE_COMMIT_FAILED(true, false, false, true),
+    COMMIT_FAILED(true, true, false, true);
 
-
-    ALLWAYS_SUCCESS(true, true, true, true), CAN_COMMIT_FAILED(false, false, false, true), PRE_COMMIT_FAILED(true,
-            false, false, true), COMMIT_FAILED(true, true, false, true);
-
+    private final ListenableFuture<Boolean> canCommit;
+    private final ListenableFuture<Empty> preCommit;
+    private final ListenableFuture<CommitInfo> commit;
+    private final ListenableFuture<Empty> abort;
 
     TestCommitCohort(final boolean canCommit, final boolean preCommit,
             final boolean commit, final boolean abort) {
         this.canCommit = Futures.immediateFuture(canCommit);
         this.preCommit = immediate(canCommit, new IllegalStateException());
-        this.commit = immediate(commit, new IllegalStateException());
+        this.commit = commit ? CommitInfo.emptyFluentFuture()
+            : Futures.immediateFailedFuture(new IllegalStateException());
         this.abort = immediate(abort, new IllegalStateException());
     }
 
 
-    private final ListenableFuture<Boolean> canCommit;
-    private final ListenableFuture<Void> preCommit;
-    private final ListenableFuture<Void> commit;
-    private final ListenableFuture<Void> abort;
-
     @Override
     public ListenableFuture<Boolean> canCommit() {
         return canCommit;
     }
 
     @Override
-    public ListenableFuture<Void> preCommit() {
+    public ListenableFuture<Empty> preCommit() {
         return preCommit;
     }
 
     @Override
-    public ListenableFuture<Void> abort() {
+    public ListenableFuture<Empty> abort() {
         return abort;
     }
 
     @Override
-    public ListenableFuture<Void> commit() {
+    public ListenableFuture<CommitInfo> commit() {
         return commit;
     }
 
-    private static ListenableFuture<Void> immediate(final boolean isSuccess, final Exception except) {
-        return isSuccess ? Futures.immediateFuture(null) : Futures.immediateFailedFuture(except);
+    private static ListenableFuture<Empty> immediate(final boolean isSuccess, final Exception except) {
+        return isSuccess ? Futures.immediateFuture(Empty.value()) : Futures.immediateFailedFuture(except);
     }
-
-
-
 }
index d47a04a6a2d874d9021980c0d6ff2a922b275f1d..28d7ef54417e717ceec3bc837eab094e1ad4b470 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.mdsal.dom.store.inmemory;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
 
@@ -26,8 +27,8 @@ final class ChainedTransactionCommitImpl extends InMemoryDOMStoreThreePhaseCommi
     }
 
     @Override
-    public ListenableFuture<Void> commit() {
-        ListenableFuture<Void> ret = super.commit();
+    public ListenableFuture<CommitInfo> commit() {
+        ListenableFuture<CommitInfo> ret = super.commit();
         txChain.transactionCommited(getTransaction());
         return ret;
     }
index d7de64d02c33581adf89ce601485c065b4bd1cec..ef1a61859134db94e985f4e7f8e8907662f1b4e2 100644 (file)
@@ -14,11 +14,13 @@ import static java.util.Objects.requireNonNull;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.mdsal.common.api.CommitInfo;
 import org.opendaylight.mdsal.common.api.OptimisticLockFailedException;
 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
 import org.opendaylight.mdsal.dom.spi.store.AbstractDOMStoreTransaction;
 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
 import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction;
+import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
@@ -28,7 +30,7 @@ import org.slf4j.LoggerFactory;
 
 class InMemoryDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort {
     private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMStoreThreePhaseCommitCohort.class);
-    private static final ListenableFuture<Void> SUCCESSFUL_FUTURE = Futures.immediateFuture(null);
+    private static final ListenableFuture<Empty> SUCCESSFUL_FUTURE = Futures.immediateFuture(Empty.value());
     private static final ListenableFuture<Boolean> CAN_COMMIT_FUTURE = Futures.immediateFuture(Boolean.TRUE);
 
     private final SnapshotBackedWriteTransaction<String> transaction;
@@ -91,7 +93,7 @@ class InMemoryDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseCommit
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
-    public final ListenableFuture<Void> preCommit() {
+    public final ListenableFuture<Empty> preCommit() {
         try {
             candidate = store.prepare(modification);
             return SUCCESSFUL_FUTURE;
@@ -102,7 +104,7 @@ class InMemoryDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseCommit
     }
 
     @Override
-    public final ListenableFuture<Void> abort() {
+    public final ListenableFuture<Empty> abort() {
         candidate = null;
         return SUCCESSFUL_FUTURE;
     }
@@ -112,15 +114,12 @@ class InMemoryDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseCommit
     }
 
     @Override
-    public ListenableFuture<Void> commit() {
+    public ListenableFuture<CommitInfo> commit() {
         checkState(candidate != null, "Proposed subtree must be computed");
 
-        /*
-         * The commit has to occur atomically with regard to listener
-         * registrations.
-         */
+        // The commit has to occur atomically with regard to listener registrations.
         store.commit(candidate);
-        return SUCCESSFUL_FUTURE;
+        return CommitInfo.emptyFluentFuture();
     }
 }
 
index 00222a53b181c41168590386edd3ed561f8dc143..c14f74e20f7f15049ae6a442ffd964a89f1d6634 100644 (file)
@@ -10,7 +10,9 @@ module org.opendaylight.mdsal.dom.spi {
     exports org.opendaylight.mdsal.dom.spi.query;
     exports org.opendaylight.mdsal.dom.spi.store;
 
+    requires transitive org.opendaylight.mdsal.common.api;
     requires transitive org.opendaylight.mdsal.dom.api;
+    requires transitive org.opendaylight.yangtools.yang.common;
     requires transitive org.opendaylight.yangtools.yang.data.tree.api;
     requires transitive org.opendaylight.yangtools.yang.model.api;
     requires transitive org.opendaylight.yangtools.yang.repo.api;
index 65dad6eebe591ac4fb3262d9030be1cceef3cc2c..d4c2b6a52eff7b2ff82781012e67f5570742852f 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.mdsal.dom.spi.store;
 
 import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.yangtools.yang.common.Empty;
 
 /**
  * Interface implemented by the {@link DOMStore} and exposed for each
@@ -42,7 +44,7 @@ public interface DOMStoreThreePhaseCommitCohort {
      * @return ListenableFuture representing acknowledgment for participant
      *        that pre-commit message was received and processed.
      */
-    ListenableFuture<Void> preCommit();
+    ListenableFuture<Empty> preCommit();
 
     /**
      * Initiates a abort phase of associated transaction on data store.
@@ -50,7 +52,7 @@ public interface DOMStoreThreePhaseCommitCohort {
      * @return ListenableFuture representing acknowledgment for participant
      *        that abort message was received.
      */
-    ListenableFuture<Void> abort();
+    ListenableFuture<Empty> abort();
 
     /**
      * Initiates a commit phase on of associated transaction on data store.
@@ -59,5 +61,5 @@ public interface DOMStoreThreePhaseCommitCohort {
      *        that commit message was received and commit of transaction was
      *        processed.
      */
-    ListenableFuture<Void> commit();
+    ListenableFuture<? extends CommitInfo> commit();
 }
index b7d4a144c54d2bf8a562d0ffd00f28a8edae724b..ab908fd11eb282222d0966bcfa84014ddbbf74d5 100644 (file)
@@ -10,10 +10,12 @@ package org.opendaylight.mdsal.dom.spi.store;
 import com.google.common.annotations.Beta;
 import com.google.common.collect.ForwardingObject;
 import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.yangtools.yang.common.Empty;
 
 /**
- * Abstract base class for {@link DOMStoreThreePhaseCommitCohort} implementations,
- * which forward most of their functionality to a backend {@link #delegate()}.
+ * Abstract base class for {@link DOMStoreThreePhaseCommitCohort} implementations, which forward most of their
+ * functionality to a backend {@link #delegate()}.
  */
 @Beta
 public abstract class ForwardingDOMStoreThreePhaseCommitCohort
@@ -28,17 +30,17 @@ public abstract class ForwardingDOMStoreThreePhaseCommitCohort
     }
 
     @Override
-    public ListenableFuture<Void> preCommit() {
+    public ListenableFuture<Empty> preCommit() {
         return delegate().preCommit();
     }
 
     @Override
-    public ListenableFuture<Void> abort() {
+    public ListenableFuture<Empty> abort() {
         return delegate().abort();
     }
 
     @Override
-    public ListenableFuture<Void> commit() {
+    public ListenableFuture<? extends CommitInfo> commit() {
         return delegate().commit();
     }
 }