X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FSimpleShardDataTreeCohort.java;h=197c90a60bd62ea15aff24b23b1e17d9a47c5cfa;hp=0527d013f246357ba68def42af0b76146b009741;hb=823bd74f34ee1c651f1f90daeef386a35c68d431;hpb=5fd8e6506248cc34da72281a1662612f6c2b2f9a diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java index 0527d013f2..197c90a60b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/SimpleShardDataTreeCohort.java @@ -13,8 +13,6 @@ import com.google.common.base.Preconditions; import com.google.common.base.Verify; import com.google.common.primitives.UnsignedLong; import com.google.common.util.concurrent.FutureCallback; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; @@ -28,7 +26,7 @@ import scala.concurrent.Future; final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { private static final Logger LOG = LoggerFactory.getLogger(SimpleShardDataTreeCohort.class); - private static final ListenableFuture VOID_FUTURE = Futures.immediateFuture(null); + private final DataTreeModification transaction; private final ShardDataTree dataTree; private final TransactionIdentifier transactionId; @@ -58,7 +56,6 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { } @Override - DataTreeModification getDataTreeModification() { return transaction; } @@ -92,21 +89,25 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { } } - @Override - public void abort(final FutureCallback callback) { - dataTree.startAbort(this); + public void abort(final FutureCallback abortCallback) { + if (!dataTree.startAbort(this)) { + abortCallback.onSuccess(null); + return; + } + + candidate = null; state = State.ABORTED; final Optional>> maybeAborts = userCohorts.abort(); if (!maybeAborts.isPresent()) { - callback.onSuccess(null); + abortCallback.onSuccess(null); return; } final Future> aborts = maybeAborts.get(); if (aborts.isCompleted()) { - callback.onSuccess(null); + abortCallback.onSuccess(null); return; } @@ -114,9 +115,9 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { @Override public void onComplete(final Throwable failure, final Iterable objs) { if (failure != null) { - callback.onFailure(failure); + abortCallback.onFailure(failure); } else { - callback.onSuccess(null); + abortCallback.onSuccess(null); } } }, ExecutionContexts.global()); @@ -127,7 +128,12 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { checkState(State.PRE_COMMIT_COMPLETE); this.callback = Preconditions.checkNotNull(newCallback); state = State.COMMIT_PENDING; - dataTree.startCommit(this, candidate); + + if (nextFailure == null) { + dataTree.startCommit(this, candidate); + } else { + failedCommit(nextFailure); + } } private FutureCallback switchState(final State newState) { @@ -139,6 +145,11 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { return ret; } + void setNewCandidate(DataTreeCandidateTip dataTreeCandidate) { + checkState(State.PRE_COMMIT_COMPLETE); + this.candidate = Verify.verifyNotNull(dataTreeCandidate); + } + void successfulCanCommit() { switchState(State.CAN_COMMIT_COMPLETE).onSuccess(null); } @@ -157,6 +168,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { */ // FIXME: this should be asynchronous void userPreCommit(final DataTreeCandidate dataTreeCandidate) throws ExecutionException, TimeoutException { + userCohorts.reset(); userCohorts.canCommit(dataTreeCandidate); userCohorts.preCommit(); } @@ -200,6 +212,12 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { switchState(State.FAILED).onFailure(cause); } + void finishCommitPending() { + checkState(State.COMMIT_PENDING); + // We want to switch the state but keep the callback. + callback = switchState(State.FINISH_COMMIT_PENDING); + } + @Override public State getState() { return state;