From: Robert Varga Date: Wed, 9 Mar 2022 11:38:23 +0000 (+0100) Subject: Update DOMStoreThreePhaseCommitCohort design X-Git-Tag: v9.0.0~20 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=mdsal.git;a=commitdiff_plain;h=5e09dedf6a5423744d9d56a464adf3664459db6d Update DOMStoreThreePhaseCommitCohort design Do not use ListenableFuture, 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 --- diff --git a/dom/mdsal-dom-broker/pom.xml b/dom/mdsal-dom-broker/pom.xml index e2f0fdc3cd..a6c9d4a507 100644 --- a/dom/mdsal-dom-broker/pom.xml +++ b/dom/mdsal-dom-broker/pom.xml @@ -52,6 +52,10 @@ org.opendaylight.yangtools yang-data-api + + org.opendaylight.yangtools + yang-data-tree-api + org.opendaylight.yangtools yang-data-impl diff --git a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/TestCommitCohort.java b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/TestCommitCohort.java index a380cf02aa..79aba5f0df 100644 --- a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/TestCommitCohort.java +++ b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/TestCommitCohort.java @@ -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 canCommit; + private final ListenableFuture preCommit; + private final ListenableFuture commit; + private final ListenableFuture 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 canCommit; - private final ListenableFuture preCommit; - private final ListenableFuture commit; - private final ListenableFuture abort; - @Override public ListenableFuture canCommit() { return canCommit; } @Override - public ListenableFuture preCommit() { + public ListenableFuture preCommit() { return preCommit; } @Override - public ListenableFuture abort() { + public ListenableFuture abort() { return abort; } @Override - public ListenableFuture commit() { + public ListenableFuture commit() { return commit; } - private static ListenableFuture immediate(final boolean isSuccess, final Exception except) { - return isSuccess ? Futures.immediateFuture(null) : Futures.immediateFailedFuture(except); + private static ListenableFuture immediate(final boolean isSuccess, final Exception except) { + return isSuccess ? Futures.immediateFuture(Empty.value()) : Futures.immediateFailedFuture(except); } - - - } diff --git a/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/ChainedTransactionCommitImpl.java b/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/ChainedTransactionCommitImpl.java index d47a04a6a2..28d7ef5441 100644 --- a/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/ChainedTransactionCommitImpl.java +++ b/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/ChainedTransactionCommitImpl.java @@ -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 commit() { - ListenableFuture ret = super.commit(); + public ListenableFuture commit() { + ListenableFuture ret = super.commit(); txChain.transactionCommited(getTransaction()); return ret; } diff --git a/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMStoreThreePhaseCommitCohort.java b/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMStoreThreePhaseCommitCohort.java index d7de64d02c..ef1a618591 100644 --- a/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMStoreThreePhaseCommitCohort.java +++ b/dom/mdsal-dom-inmemory-datastore/src/main/java/org/opendaylight/mdsal/dom/store/inmemory/InMemoryDOMStoreThreePhaseCommitCohort.java @@ -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 SUCCESSFUL_FUTURE = Futures.immediateFuture(null); + private static final ListenableFuture SUCCESSFUL_FUTURE = Futures.immediateFuture(Empty.value()); private static final ListenableFuture CAN_COMMIT_FUTURE = Futures.immediateFuture(Boolean.TRUE); private final SnapshotBackedWriteTransaction transaction; @@ -91,7 +93,7 @@ class InMemoryDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseCommit @SuppressWarnings("checkstyle:IllegalCatch") @Override - public final ListenableFuture preCommit() { + public final ListenableFuture preCommit() { try { candidate = store.prepare(modification); return SUCCESSFUL_FUTURE; @@ -102,7 +104,7 @@ class InMemoryDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseCommit } @Override - public final ListenableFuture abort() { + public final ListenableFuture abort() { candidate = null; return SUCCESSFUL_FUTURE; } @@ -112,15 +114,12 @@ class InMemoryDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseCommit } @Override - public ListenableFuture commit() { + public ListenableFuture 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(); } } diff --git a/dom/mdsal-dom-spi/src/main/java/module-info.java b/dom/mdsal-dom-spi/src/main/java/module-info.java index 00222a53b1..c14f74e20f 100644 --- a/dom/mdsal-dom-spi/src/main/java/module-info.java +++ b/dom/mdsal-dom-spi/src/main/java/module-info.java @@ -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; diff --git a/dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/store/DOMStoreThreePhaseCommitCohort.java b/dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/store/DOMStoreThreePhaseCommitCohort.java index 65dad6eebe..d4c2b6a52e 100644 --- a/dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/store/DOMStoreThreePhaseCommitCohort.java +++ b/dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/store/DOMStoreThreePhaseCommitCohort.java @@ -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 preCommit(); + ListenableFuture 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 abort(); + ListenableFuture 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 commit(); + ListenableFuture commit(); } diff --git a/dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/store/ForwardingDOMStoreThreePhaseCommitCohort.java b/dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/store/ForwardingDOMStoreThreePhaseCommitCohort.java index b7d4a144c5..ab908fd11e 100644 --- a/dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/store/ForwardingDOMStoreThreePhaseCommitCohort.java +++ b/dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/store/ForwardingDOMStoreThreePhaseCommitCohort.java @@ -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 preCommit() { + public ListenableFuture preCommit() { return delegate().preCommit(); } @Override - public ListenableFuture abort() { + public ListenableFuture abort() { return delegate().abort(); } @Override - public ListenableFuture commit() { + public ListenableFuture commit() { return delegate().commit(); } }