X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FSimpleShardDataTreeCohort.java;h=b9e39975e5c869529a31fa2a56dad6e0c0db9378;hb=4447f81c26b851e46acd3f111768bb498f0d553f;hp=9791a596117ffc085efc89abbb815c16adb78381;hpb=a0332590d14ab7aad0247ae12bff4205c90cac94;p=controller.git 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 9791a59611..b9e39975e5 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 @@ -8,11 +8,13 @@ package org.opendaylight.controller.cluster.datastore; import akka.dispatch.ExecutionContexts; +import akka.dispatch.Futures; import akka.dispatch.OnComplete; 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 java.util.List; import java.util.Optional; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; @@ -24,7 +26,34 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import scala.concurrent.Future; -final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { +abstract class SimpleShardDataTreeCohort extends ShardDataTreeCohort { + static final class DeadOnArrival extends SimpleShardDataTreeCohort { + private final Exception failure; + + DeadOnArrival(final ShardDataTree dataTree, final DataTreeModification transaction, + final TransactionIdentifier transactionId, final Exception failure) { + super(dataTree, transaction, transactionId, null); + this.failure = Preconditions.checkNotNull(failure); + } + + @Override + void throwCanCommitFailure() throws Exception { + throw failure; + } + } + + static final class Normal extends SimpleShardDataTreeCohort { + Normal(final ShardDataTree dataTree, final DataTreeModification transaction, + final TransactionIdentifier transactionId, final CompositeDataTreeCohort userCohorts) { + super(dataTree, transaction, transactionId, Preconditions.checkNotNull(userCohorts)); + } + + @Override + void throwCanCommitFailure() { + // No-op + } + } + private static final Logger LOG = LoggerFactory.getLogger(SimpleShardDataTreeCohort.class); private final DataTreeModification transaction; @@ -42,7 +71,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { this.dataTree = Preconditions.checkNotNull(dataTree); this.transaction = Preconditions.checkNotNull(transaction); this.transactionId = Preconditions.checkNotNull(transactionId); - this.userCohorts = Preconditions.checkNotNull(userCohorts); + this.userCohorts = userCohorts; } @Override @@ -99,13 +128,13 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { candidate = null; state = State.ABORTED; - final Optional>> maybeAborts = userCohorts.abort(); + final Optional>> maybeAborts = userCohorts.abort(); if (!maybeAborts.isPresent()) { abortCallback.onSuccess(null); return; } - final Future> aborts = maybeAborts.get(); + final Future> aborts = Futures.sequence(maybeAborts.get(), ExecutionContexts.global()); if (aborts.isCompleted()) { abortCallback.onSuccess(null); return; @@ -145,7 +174,7 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { return ret; } - void setNewCandidate(DataTreeCandidateTip dataTreeCandidate) { + void setNewCandidate(final DataTreeCandidateTip dataTreeCandidate) { checkState(State.PRE_COMMIT_COMPLETE); this.candidate = Verify.verifyNotNull(dataTreeCandidate); } @@ -168,6 +197,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(); } @@ -220,6 +250,13 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { this.nextFailure = Preconditions.checkNotNull(cause); } + /** + * If there is an initial failure, throw it so the caller can process it. + * + * @throws Exception reported failure. + */ + abstract void throwCanCommitFailure() throws Exception; + @Override public boolean isFailed() { return state == State.FAILED || nextFailure != null;