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=cf9948cf03e0407f47103e4e2085d33a58d0346d;hp=197c90a60bd62ea15aff24b23b1e17d9a47c5cfa;hb=39b7a263d64559bc4f593726f56aa38ab9cc0b1c;hpb=823bd74f34ee1c651f1f90daeef386a35c68d431 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 197c90a60b..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 @@ -8,11 +8,14 @@ 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; 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; @@ -45,6 +48,15 @@ final class SimpleShardDataTreeCohort extends ShardDataTreeCohort { 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 public TransactionIdentifier getIdentifier() { return transactionId; @@ -73,7 +85,12 @@ final 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 @@ -99,13 +116,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 +162,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); } @@ -212,23 +229,26 @@ 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; } 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); + } } @Override public boolean isFailed() { return state == State.FAILED || nextFailure != null; } + + @Override + ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) { + return super.addToStringAttributes(toStringHelper).add("nextFailure", nextFailure); + } }