X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-common-api%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fcommon%2Fapi%2Fdata%2FTransactionChain.java;h=c46910402d4d3092b9b053e421b922175186363a;hp=32e32f94eb34e59d5b956095235883a717d3f95b;hb=99f994b3e45963f6ef46bc2b71ab4dd8eea8b9ac;hpb=e90bec01888e6b2a2503d21de25f3a674d607163 diff --git a/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChain.java b/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChain.java index 32e32f94eb..c46910402d 100644 --- a/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChain.java +++ b/opendaylight/md-sal/sal-common-api/src/main/java/org/opendaylight/controller/md/sal/common/api/data/TransactionChain.java @@ -15,25 +15,30 @@ import org.opendaylight.yangtools.concepts.Path; * as they occurred. A chain makes no guarantees of atomicity across the chained transactions - * the transactions are committed as soon as possible in the order that they were submitted. * + *

* This behaviour is different from the default AsyncDataBroker, where a * transaction is always created from the current global state, not taking into * account any transactions previously committed by the calling thread. Due to * the asynchronous nature of transaction submission this can lead to surprising * results. If a thread executes the following sequence sufficiently quickly: * + *

* AsyncWriteTransaction t1 = broker.newWriteOnlyTransaction(); * t1.put(id, data); * t1.submit(); * + *

* AsyncReadTransaction t2 = broker.newReadOnlyTransaction(); - * Optional maybeData = t2.read(id).get(); + * Optional<?> maybeData = t2.read(id).get(); * + *

* it may happen, that it sees maybeData.isPresent() == false, simply because * t1 has not completed the processes of being applied and t2 is actually * allocated from the previous state. This is obviously bad for users who create * incremental state in the datastore and actually read what they write in * subsequent transactions. * + *

* Using a TransactionChain instead of a broker solves this particular problem, * and leads to expected behavior: t2 will always see the data written in t1 * present. @@ -48,6 +53,7 @@ public interface TransactionChain

, D> extends AutoCloseable, * The previous write transaction has to be either SUBMITTED * ({@link AsyncWriteTransaction#submit submit} was invoked) or CANCELLED * ({@link #close close} was invoked). + * *

* The returned read-only transaction presents an isolated view of the data if the previous * write transaction was successful - in other words, this read-only transaction will see the @@ -62,7 +68,7 @@ public interface TransactionChain

, D> extends AutoCloseable, * if the chain has been closed. */ @Override - public AsyncReadOnlyTransaction newReadOnlyTransaction(); + AsyncReadOnlyTransaction newReadOnlyTransaction(); /** * Create a new read-write transaction which will continue the chain. @@ -71,12 +77,14 @@ public interface TransactionChain

, D> extends AutoCloseable, * The previous write transaction has to be either SUBMITTED * ({@link AsyncWriteTransaction#submit submit} was invoked) or CANCELLED * ({@link #close close} was invoked). + * *

* The returned read-write transaction presents an isolated view of the data if the previous * write transaction was successful - in other words, this read-write transaction will see the * state changes made by the previous write transaction in the chain. However, state which * was introduced by other transactions outside this transaction chain after creation of * the previous transaction is not visible. + * *

* Committing this read-write transaction using {@link AsyncWriteTransaction#submit submit} * will submit the state changes in this transaction to be visible to any subsequent @@ -89,7 +97,7 @@ public interface TransactionChain

, D> extends AutoCloseable, * if the chain has been closed. */ @Override - public AsyncReadWriteTransaction newReadWriteTransaction(); + AsyncReadWriteTransaction newReadWriteTransaction(); /** * Create a new write-only transaction which will continue the chain. @@ -98,12 +106,14 @@ public interface TransactionChain

, D> extends AutoCloseable, * The previous write transaction has to be either SUBMITTED * ({@link AsyncWriteTransaction#submit submit} was invoked) or CANCELLED * ({@link #close close} was invoked). + * *

* The returned write-only transaction presents an isolated view of the data if the previous * write transaction was successful - in other words, this write-only transaction will see the * state changes made by the previous write transaction in the chain. However, state which * was introduced by other transactions outside this transaction chain after creation of * the previous transaction is not visible. + * *

* Committing this write-only transaction using {@link AsyncWriteTransaction#submit submit} * will submit the state changes in this transaction to be visible to any subsequent @@ -116,7 +126,7 @@ public interface TransactionChain

, D> extends AutoCloseable, * if the chain has been closed. */ @Override - public AsyncWriteTransaction newWriteOnlyTransaction(); + AsyncWriteTransaction newWriteOnlyTransaction(); @Override void close();