Code Review
/
controller.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Migrate OSGI compendium reference
[controller.git]
/
opendaylight
/
md-sal
/
sal-dom-spi
/
src
/
main
/
java
/
org
/
opendaylight
/
controller
/
sal
/
core
/
spi
/
data
/
AbstractSnapshotBackedTransactionChain.java
diff --git
a/opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/sal/core/spi/data/AbstractSnapshotBackedTransactionChain.java
b/opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/sal/core/spi/data/AbstractSnapshotBackedTransactionChain.java
index 7b6e68dc512e8e5eacf7c183295d33942332862a..a06b1b155822bac78cbb36d46f1cfdea00ca282d 100644
(file)
--- a/
opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/sal/core/spi/data/AbstractSnapshotBackedTransactionChain.java
+++ b/
opendaylight/md-sal/sal-dom-spi/src/main/java/org/opendaylight/controller/sal/core/spi/data/AbstractSnapshotBackedTransactionChain.java
@@
-7,11
+7,14
@@
*/
package org.opendaylight.controller.sal.core.spi.data;
*/
package org.opendaylight.controller.sal.core.spi.data;
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
import com.google.common.annotations.Beta;
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 java.util.AbstractMap.SimpleEntry;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedReadTransaction.TransactionClosePrototype;
import org.opendaylight.controller.sal.core.spi.data.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.controller.sal.core.spi.data.SnapshotBackedWriteTransaction.TransactionReadyPrototype;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
@@
-19,14
+22,17
@@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
import org.slf4j.LoggerFactory;
/**
- * Abstract implementation of the {@link DOMStoreTransactionChain} interface relying on {@link DataTreeSnapshot}
supplier
- * and backend commit coordinator.
+ * Abstract implementation of the {@link DOMStoreTransactionChain} interface relying on {@link DataTreeSnapshot}
+ *
supplier
and backend commit coordinator.
*
* @param <T> transaction identifier type
*
* @param <T> transaction identifier type
+ * @deprecated Use {@link org.opendaylight.mdsal.dom.spi.store.AbstractSnapshotBackedTransactionChain} instead.
*/
*/
+@Deprecated(forRemoval = true)
@Beta
@Beta
-public abstract class AbstractSnapshotBackedTransactionChain<T> extends TransactionReadyPrototype<T> implements DOMStoreTransactionChain {
- private static abstract class State {
+public abstract class AbstractSnapshotBackedTransactionChain<T> extends TransactionReadyPrototype<T>
+ implements DOMStoreTransactionChain, TransactionClosePrototype<T> {
+ private abstract static class State {
/**
* Allocate a new snapshot.
*
/**
* Allocate a new snapshot.
*
@@
-39,11
+45,11
@@
public abstract class AbstractSnapshotBackedTransactionChain<T> extends Transact
private final AbstractSnapshotBackedTransactionChain<?> chain;
Idle(final AbstractSnapshotBackedTransactionChain<?> chain) {
private final AbstractSnapshotBackedTransactionChain<?> chain;
Idle(final AbstractSnapshotBackedTransactionChain<?> chain) {
- this.chain =
Preconditions.checkNot
Null(chain);
+ this.chain =
requireNon
Null(chain);
}
@Override
}
@Override
- protected DataTreeSnapshot getSnapshot(Object transactionId) {
+ protected DataTreeSnapshot getSnapshot(
final
Object transactionId) {
return chain.takeSnapshot();
}
}
return chain.takeSnapshot();
}
}
@@
-58,7
+64,7
@@
public abstract class AbstractSnapshotBackedTransactionChain<T> extends Transact
private volatile DataTreeSnapshot snapshot;
Allocated(final DOMStoreWriteTransaction transaction) {
private volatile DataTreeSnapshot snapshot;
Allocated(final DOMStoreWriteTransaction transaction) {
- this.transaction =
Preconditions.checkNot
Null(transaction);
+ this.transaction =
requireNon
Null(transaction);
}
public DOMStoreWriteTransaction getTransaction() {
}
public DOMStoreWriteTransaction getTransaction() {
@@
-66,16
+72,17
@@
public abstract class AbstractSnapshotBackedTransactionChain<T> extends Transact
}
@Override
}
@Override
- protected DataTreeSnapshot getSnapshot(Object transactionId) {
+ protected DataTreeSnapshot getSnapshot(
final
Object transactionId) {
final DataTreeSnapshot ret = snapshot;
final DataTreeSnapshot ret = snapshot;
- Preconditions.checkState(ret != null, "Could not get snapshot for transaction %s - previous transaction %s is not ready yet",
+ checkState(ret != null,
+ "Could not get snapshot for transaction %s - previous transaction %s is not ready yet",
transactionId, transaction.getIdentifier());
return ret;
}
void setSnapshot(final DataTreeSnapshot snapshot) {
final boolean success = SNAPSHOT_UPDATER.compareAndSet(this, null, snapshot);
transactionId, 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());
}
}
}
}
@@
-86,11
+93,11
@@
public abstract class AbstractSnapshotBackedTransactionChain<T> extends Transact
private final String message;
Shutdown(final String message) {
private final String message;
Shutdown(final String message) {
- this.message =
Preconditions.checkNot
Null(message);
+ this.message =
requireNon
Null(message);
}
@Override
}
@Override
- protected DataTreeSnapshot getSnapshot(Object transactionId) {
+ protected DataTreeSnapshot getSnapshot(
final
Object transactionId) {
throw new IllegalStateException(message);
}
}
throw new IllegalStateException(message);
}
}
@@
-109,14
+116,14
@@
public abstract class AbstractSnapshotBackedTransactionChain<T> extends Transact
state = idleState;
}
state = idleState;
}
- private Entry<State, DataTreeSnapshot> getSnapshot(T transactionId) {
+ private Entry<State, DataTreeSnapshot> getSnapshot(
final
T transactionId) {
final State localState = state;
return new SimpleEntry<>(localState, localState.getSnapshot(transactionId));
}
private boolean recordTransaction(final State expected, final DOMStoreWriteTransaction transaction) {
final State localState = state;
return new SimpleEntry<>(localState, localState.getSnapshot(transactionId));
}
private boolean recordTransaction(final State expected, final DOMStoreWriteTransaction transaction) {
- final State
s
tate = new Allocated(transaction);
- return STATE_UPDATER.compareAndSet(this, expected,
s
tate);
+ final State
localS
tate = new Allocated(transaction);
+ return STATE_UPDATER.compareAndSet(this, expected,
localS
tate);
}
@Override
}
@Override
@@
-124,9
+131,15
@@
public abstract class AbstractSnapshotBackedTransactionChain<T> extends Transact
return newReadOnlyTransaction(nextTransactionIdentifier());
}
return newReadOnlyTransaction(nextTransactionIdentifier());
}
- protected DOMStoreReadTransaction newReadOnlyTransaction(T transactionId) {
+ protected DOMStoreReadTransaction newReadOnlyTransaction(
final
T transactionId) {
final Entry<State, DataTreeSnapshot> entry = getSnapshot(transactionId);
final Entry<State, DataTreeSnapshot> entry = getSnapshot(transactionId);
- return SnapshotBackedTransactions.newReadTransaction(transactionId, getDebugTransactions(), entry.getValue());
+ return SnapshotBackedTransactions.newReadTransaction(transactionId, getDebugTransactions(), entry.getValue(),
+ this);
+ }
+
+ @Override
+ public void transactionClosed(final SnapshotBackedReadTransaction<T> tx) {
+ // Defaults to no-op
}
@Override
}
@Override
@@
-134,13
+147,14
@@
public abstract class AbstractSnapshotBackedTransactionChain<T> extends Transact
return newReadWriteTransaction(nextTransactionIdentifier());
}
return newReadWriteTransaction(nextTransactionIdentifier());
}
- protected DOMStoreReadWriteTransaction newReadWriteTransaction(T transactionId) {
+ protected DOMStoreReadWriteTransaction newReadWriteTransaction(
final
T transactionId) {
Entry<State, DataTreeSnapshot> entry;
DOMStoreReadWriteTransaction ret;
do {
entry = getSnapshot(transactionId);
Entry<State, DataTreeSnapshot> entry;
DOMStoreReadWriteTransaction ret;
do {
entry = getSnapshot(transactionId);
- ret = new SnapshotBackedReadWriteTransaction<T>(transactionId, getDebugTransactions(), entry.getValue(), this);
+ ret = new SnapshotBackedReadWriteTransaction<>(transactionId, getDebugTransactions(), entry.getValue(),
+ this);
} while (!recordTransaction(entry.getKey(), ret));
return ret;
} while (!recordTransaction(entry.getKey(), ret));
return ret;
@@
-151,13
+165,13
@@
public abstract class AbstractSnapshotBackedTransactionChain<T> extends Transact
return newWriteOnlyTransaction(nextTransactionIdentifier());
}
return newWriteOnlyTransaction(nextTransactionIdentifier());
}
- protected DOMStoreWriteTransaction newWriteOnlyTransaction(T transactionId) {
+ protected DOMStoreWriteTransaction newWriteOnlyTransaction(
final
T transactionId) {
Entry<State, DataTreeSnapshot> entry;
DOMStoreWriteTransaction ret;
do {
entry = getSnapshot(transactionId);
Entry<State, DataTreeSnapshot> entry;
DOMStoreWriteTransaction ret;
do {
entry = getSnapshot(transactionId);
- ret = new SnapshotBackedWriteTransaction<
T
>(transactionId, getDebugTransactions(), entry.getValue(), this);
+ ret = new SnapshotBackedWriteTransaction<>(transactionId, getDebugTransactions(), entry.getValue(), this);
} while (!recordTransaction(entry.getKey(), ret));
return ret;
} while (!recordTransaction(entry.getKey(), ret));
return ret;
@@
-171,7
+185,8
@@
public abstract class AbstractSnapshotBackedTransactionChain<T> extends Transact
if (allocated.getTransaction().equals(tx)) {
final boolean success = STATE_UPDATER.compareAndSet(this, localState, idleState);
if (!success) {
if (allocated.getTransaction().equals(tx)) {
final boolean success = STATE_UPDATER.compareAndSet(this, localState, idleState);
if (!success) {
- LOG.warn("Transaction {} aborted, but chain {} state already transitioned from {} to {}, very strange",
+ LOG.warn(
+ "Transaction {} aborted, but chain {} state already transitioned from {} to {}, very strange",
tx, this, localState, state);
}
}
tx, this, localState, state);
}
}
@@
-179,19
+194,24
@@
public abstract class AbstractSnapshotBackedTransactionChain<T> extends Transact
}
@Override
}
@Override
- protected final DOMStoreThreePhaseCommitCohort transactionReady(final SnapshotBackedWriteTransaction<T> tx, final DataTreeModification tree) {
+ protected final DOMStoreThreePhaseCommitCohort transactionReady(
+ final SnapshotBackedWriteTransaction<T> 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();
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);
}
allocated.setSnapshot(tree);
} else {
LOG.debug("Ignoring transaction {} readiness due to state {}", tx, localState);
}
- return createCohort(tx, tree);
+ return createCohort(tx, tree
, readyError
);
}
@Override
}
@Override
@@
-199,8
+219,7
@@
public abstract class AbstractSnapshotBackedTransactionChain<T> extends Transact
final State localState = state;
do {
final State localState = state;
do {
- Preconditions.checkState(!CLOSED.equals(localState), "Transaction chain {} has been closed", this);
-
+ checkState(!CLOSED.equals(localState), "Transaction chain %s has been closed", this);
if (FAILED.equals(localState)) {
LOG.debug("Ignoring user close in failed state");
return;
if (FAILED.equals(localState)) {
LOG.debug("Ignoring user close in failed state");
return;
@@
-234,7
+253,8
@@
public abstract class AbstractSnapshotBackedTransactionChain<T> extends Transact
}
if (!STATE_UPDATER.compareAndSet(this, localState, idleState)) {
}
if (!STATE_UPDATER.compareAndSet(this, localState, idleState)) {
- LOG.debug("Transaction chain {} has already transitioned from {} to {}, not making it idle", this, localState, state);
+ LOG.debug("Transaction chain {} has already transitioned from {} to {}, not making it idle",
+ this, localState, state);
}
}
}
}
@@
-244,7
+264,8
@@
public abstract class AbstractSnapshotBackedTransactionChain<T> extends Transact
* @param transaction Transaction which failed.
* @param cause Failure cause
*/
* @param transaction Transaction which failed.
* @param cause Failure cause
*/
- protected final void onTransactionFailed(final SnapshotBackedWriteTransaction<T> transaction, final Throwable cause) {
+ protected final void onTransactionFailed(final SnapshotBackedWriteTransaction<T> transaction,
+ final Throwable cause) {
LOG.debug("Transaction chain {} failed on transaction {}", this, transaction, cause);
state = FAILED;
}
LOG.debug("Transaction chain {} failed on transaction {}", this, transaction, cause);
state = FAILED;
}
@@
-275,7
+296,10
@@
public abstract class AbstractSnapshotBackedTransactionChain<T> extends Transact
*
* @param transaction Transaction handle
* @param modification {@link DataTreeModification} which needs to be applied to the backend
*
* @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.
*/
* @return A {@link DOMStoreThreePhaseCommitCohort} cohort.
*/
- protected abstract DOMStoreThreePhaseCommitCohort createCohort(final SnapshotBackedWriteTransaction<T> transaction, final DataTreeModification modification);
+ protected abstract DOMStoreThreePhaseCommitCohort createCohort(SnapshotBackedWriteTransaction<T> transaction,
+ DataTreeModification modification,
+ Exception operationError);
}
}