X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=dom%2Fmdsal-dom-spi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fdom%2Fspi%2Fstore%2FAbstractSnapshotBackedTransactionChain.java;h=85012c39b2dc727082302cd566b1c8836040a1f5;hb=11408d627adca7eb71ac956c3ad01f75b6b91596;hp=9d85559b5f967da2a05b15c71c38e24ddbc80804;hpb=abb11d1d838a6c19a3f190b677f4a13cf3b33bb0;p=mdsal.git diff --git a/dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/store/AbstractSnapshotBackedTransactionChain.java b/dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/store/AbstractSnapshotBackedTransactionChain.java index 9d85559b5f..85012c39b2 100644 --- a/dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/store/AbstractSnapshotBackedTransactionChain.java +++ b/dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/store/AbstractSnapshotBackedTransactionChain.java @@ -7,14 +7,17 @@ */ package org.opendaylight.mdsal.dom.spi.store; +import static com.google.common.base.Preconditions.checkState; +import static java.util.Objects.requireNonNull; + import com.google.common.annotations.Beta; -import com.google.common.base.Preconditions; import java.util.AbstractMap.SimpleEntry; import java.util.Map.Entry; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; +import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedReadTransaction.TransactionClosePrototype; import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction.TransactionReadyPrototype; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,7 +29,7 @@ import org.slf4j.LoggerFactory; */ @Beta public abstract class AbstractSnapshotBackedTransactionChain - extends TransactionReadyPrototype implements DOMStoreTransactionChain { + extends TransactionReadyPrototype implements DOMStoreTransactionChain, TransactionClosePrototype { private abstract static class State { /** * Allocate a new snapshot. @@ -40,7 +43,7 @@ public abstract class AbstractSnapshotBackedTransactionChain private final AbstractSnapshotBackedTransactionChain chain; Idle(final AbstractSnapshotBackedTransactionChain chain) { - this.chain = Preconditions.checkNotNull(chain); + this.chain = requireNonNull(chain); } @Override @@ -59,7 +62,7 @@ public abstract class AbstractSnapshotBackedTransactionChain private volatile DataTreeSnapshot snapshot; Allocated(final DOMStoreWriteTransaction transaction) { - this.transaction = Preconditions.checkNotNull(transaction); + this.transaction = requireNonNull(transaction); } public DOMStoreWriteTransaction getTransaction() { @@ -69,15 +72,13 @@ public abstract class AbstractSnapshotBackedTransactionChain @Override protected DataTreeSnapshot getSnapshot() { final DataTreeSnapshot ret = snapshot; - Preconditions.checkState(ret != null, - "Previous transaction %s is not ready yet", transaction.getIdentifier()); + checkState(ret != null, "Previous transaction %s is not ready yet", transaction.getIdentifier()); return ret; } void setSnapshot(final DataTreeSnapshot snapshot) { final boolean success = SNAPSHOT_UPDATER.compareAndSet(this, null, snapshot); - Preconditions.checkState(success, - "Transaction %s has already been marked as ready", transaction.getIdentifier()); + checkState(success, "Transaction %s has already been marked as ready", transaction.getIdentifier()); } } @@ -88,7 +89,7 @@ public abstract class AbstractSnapshotBackedTransactionChain private final String message; Shutdown(final String message) { - this.message = Preconditions.checkNotNull(message); + this.message = requireNonNull(message); } @Override @@ -128,10 +129,15 @@ public abstract class AbstractSnapshotBackedTransactionChain return newReadOnlyTransaction(nextTransactionIdentifier()); } - protected DOMStoreReadTransaction newReadOnlyTransaction(T transactionId) { + protected DOMStoreReadTransaction newReadOnlyTransaction(final T transactionId) { final Entry entry = getSnapshot(); return SnapshotBackedTransactions.newReadTransaction(transactionId, - getDebugTransactions(), entry.getValue()); + getDebugTransactions(), entry.getValue(), this); + } + + @Override + public void transactionClosed(final SnapshotBackedReadTransaction tx) { + // Defaults to no-op } @Override @@ -139,13 +145,13 @@ public abstract class AbstractSnapshotBackedTransactionChain return newReadWriteTransaction(nextTransactionIdentifier()); } - protected DOMStoreReadWriteTransaction newReadWriteTransaction(T transactionId) { + protected DOMStoreReadWriteTransaction newReadWriteTransaction(final T transactionId) { Entry entry; DOMStoreReadWriteTransaction ret; do { entry = getSnapshot(); - ret = new SnapshotBackedReadWriteTransaction(transactionId, + ret = new SnapshotBackedReadWriteTransaction<>(transactionId, getDebugTransactions(), entry.getValue(), this); } while (!recordTransaction(entry.getKey(), ret)); @@ -157,13 +163,13 @@ public abstract class AbstractSnapshotBackedTransactionChain return newWriteOnlyTransaction(nextTransactionIdentifier()); } - protected DOMStoreWriteTransaction newWriteOnlyTransaction(T transactionId) { + protected DOMStoreWriteTransaction newWriteOnlyTransaction(final T transactionId) { Entry entry; DOMStoreWriteTransaction ret; do { entry = getSnapshot(); - ret = new SnapshotBackedWriteTransaction(transactionId, + ret = new SnapshotBackedWriteTransaction<>(transactionId, getDebugTransactions(), entry.getValue(), this); } while (!recordTransaction(entry.getKey(), ret)); @@ -178,9 +184,8 @@ public abstract class AbstractSnapshotBackedTransactionChain if (allocated.getTransaction().equals(tx)) { final boolean success = STATE_UPDATER.compareAndSet(this, localState, idleState); if (!success) { - LOG.warn("Transaction {} aborted, but chain {} s" - + "tate already transitioned from {} to {}, very strange", - tx, this, localState, state); + LOG.warn("Transaction {} aborted, but chain {} state already transitioned from {} to {}, " + + "very strange", tx, this, localState, state); } } } @@ -188,20 +193,22 @@ public abstract class AbstractSnapshotBackedTransactionChain @Override protected final DOMStoreThreePhaseCommitCohort transactionReady( - final SnapshotBackedWriteTransaction tx, final DataTreeModification tree) { + final SnapshotBackedWriteTransaction tx, + final DataTreeModification tree, + final Exception readyError) { final State localState = state; if (localState instanceof Allocated) { final Allocated allocated = (Allocated)localState; final DOMStoreWriteTransaction transaction = allocated.getTransaction(); - Preconditions.checkState(tx.equals(transaction), - "Mis-ordered ready transaction %s last allocated was %s", tx, transaction); + checkState(tx.equals(transaction), "Mis-ordered ready transaction %s last allocated was %s", tx, + transaction); allocated.setSnapshot(tree); } else { LOG.debug("Ignoring transaction {} readiness due to state {}", tx, localState); } - return createCohort(tx, tree); + return createCohort(tx, tree, readyError); } @Override @@ -209,8 +216,7 @@ public abstract class AbstractSnapshotBackedTransactionChain final State localState = state; do { - Preconditions.checkState(!CLOSED.equals(localState), - "Transaction chain {} has been closed", this); + checkState(!CLOSED.equals(localState), "Transaction chain {} has been closed", this); if (FAILED.equals(localState)) { LOG.debug("Ignoring user close in failed state"); @@ -283,8 +289,10 @@ public abstract class AbstractSnapshotBackedTransactionChain * Create a cohort for driving the transaction through the commit process. * @param transaction Transaction handle * @param modification {@link DataTreeModification} which needs to be applied to the backend + * @param operationError Any previous error that could be reported through three phase commit * @return A {@link DOMStoreThreePhaseCommitCohort} cohort. */ - protected abstract DOMStoreThreePhaseCommitCohort createCohort( - final SnapshotBackedWriteTransaction transaction, final DataTreeModification modification); + protected abstract DOMStoreThreePhaseCommitCohort createCohort(SnapshotBackedWriteTransaction transaction, + DataTreeModification modification, + Exception operationError); }