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=cf9948cf03e0407f47103e4e2085d33a58d0346d;hb=d7c9a8ccfcb57f005490a226803d094289997ef9;hp=b9e39975e5c869529a31fa2a56dad6e0c0db9378;hpb=0b3bfca7f39ee1bb6dcf5379f44d0b402adeb7fe;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 b9e39975e5..cf9948cf03 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 @@ -10,6 +10,7 @@ package org.opendaylight.controller.cluster.datastore; import akka.dispatch.ExecutionContexts; import akka.dispatch.Futures; import akka.dispatch.OnComplete; +import com.google.common.base.MoreObjects.ToStringHelper; import com.google.common.base.Preconditions; import com.google.common.base.Verify; import com.google.common.primitives.UnsignedLong; @@ -26,34 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import scala.concurrent.Future; -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 - } - } - +final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { private static final Logger LOG = LoggerFactory.getLogger(SimpleShardDataTreeCohort.class); private final DataTreeModification transaction; @@ -71,7 +45,16 @@ abstract class SimpleShardDataTreeCohort extends ShardDataTreeCohort { this.dataTree = Preconditions.checkNotNull(dataTree); this.transaction = Preconditions.checkNotNull(transaction); this.transactionId = Preconditions.checkNotNull(transactionId); - this.userCohorts = userCohorts; + this.userCohorts = Preconditions.checkNotNull(userCohorts); + } + + SimpleShardDataTreeCohort(final ShardDataTree dataTree, final DataTreeModification transaction, + final TransactionIdentifier transactionId, final Exception nextFailure) { + this.dataTree = Preconditions.checkNotNull(dataTree); + this.transaction = Preconditions.checkNotNull(transaction); + this.transactionId = Preconditions.checkNotNull(transactionId); + this.userCohorts = null; + this.nextFailure = Preconditions.checkNotNull(nextFailure); } @Override @@ -102,7 +85,12 @@ abstract class SimpleShardDataTreeCohort extends ShardDataTreeCohort { checkState(State.READY); this.callback = Preconditions.checkNotNull(newCallback); state = State.CAN_COMMIT_PENDING; - dataTree.startCanCommit(this); + + if (nextFailure == null) { + dataTree.startCanCommit(this); + } else { + failedCanCommit(nextFailure); + } } @Override @@ -247,18 +235,20 @@ abstract class SimpleShardDataTreeCohort extends ShardDataTreeCohort { } void reportFailure(final Exception cause) { - this.nextFailure = Preconditions.checkNotNull(cause); + if (nextFailure == null) { + this.nextFailure = Preconditions.checkNotNull(cause); + } else { + LOG.debug("Transaction {} already has a set failure, not updating it", transactionId, 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; } + + @Override + ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { + return super.addToStringAttributes(toStringHelper).add("nextFailure", nextFailure); + } }