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%2FLocalThreePhaseCommitCohort.java;h=442e2f3b4dd77c88cfb3b57e868f5f5ed0a4d4fc;hp=4e085399d2093d2bc84661e1d6f8679fd73f59a1;hb=3f979acfb60c2ffb1ce70c5475bdfce8f8e7df01;hpb=d71b6614d6cdb5a98f086edeb56f5c52f365c61c diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalThreePhaseCommitCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalThreePhaseCommitCohort.java index 4e085399d2..442e2f3b4d 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalThreePhaseCommitCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/LocalThreePhaseCommitCohort.java @@ -8,6 +8,7 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorSelection; +import akka.dispatch.Futures; import akka.dispatch.OnComplete; import com.google.common.base.Preconditions; import com.google.common.util.concurrent.ListenableFuture; @@ -30,13 +31,14 @@ import scala.concurrent.Future; * It is not actually called by the front-end to perform 3PC thus the canCommit/preCommit/commit methods * are no-ops. */ -abstract class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort { +class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort { private static final Logger LOG = LoggerFactory.getLogger(LocalThreePhaseCommitCohort.class); private final SnapshotBackedWriteTransaction transaction; private final DataTreeModification modification; private final ActorContext actorContext; private final ActorSelection leader; + private Exception operationError; protected LocalThreePhaseCommitCohort(final ActorContext actorContext, final ActorSelection leader, final SnapshotBackedWriteTransaction transaction, final DataTreeModification modification) { @@ -46,19 +48,31 @@ abstract class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCo this.modification = Preconditions.checkNotNull(modification); } + protected LocalThreePhaseCommitCohort(final ActorContext actorContext, final ActorSelection leader, + final SnapshotBackedWriteTransaction transaction, final Exception operationError) { + this.actorContext = Preconditions.checkNotNull(actorContext); + this.leader = Preconditions.checkNotNull(leader); + this.transaction = Preconditions.checkNotNull(transaction); + this.operationError = Preconditions.checkNotNull(operationError); + this.modification = null; + } + private Future initiateCommit(final boolean immediate) { + if(operationError != null) { + return Futures.failed(operationError); + } + final ReadyLocalTransaction message = new ReadyLocalTransaction(transaction.getIdentifier().toString(), modification, immediate); return actorContext.executeOperationAsync(leader, message, actorContext.getTransactionCommitOperationTimeout()); } - /** - * Return the {@link ActorContext} associated with this object. - * - * @return An actor context instance. - */ - @Nonnull ActorContext getActorContext() { - return actorContext; + void setOperationError(@Nonnull Exception operationError) { + if (this.operationError != null) { + LOG.info("Cohort {} already had operation error", this, this.operationError); + } + + this.operationError = Preconditions.checkNotNull(operationError); } Future initiateCoordinatedCommit() { @@ -126,6 +140,9 @@ abstract class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCo throw new UnsupportedOperationException(); } - protected abstract void transactionAborted(SnapshotBackedWriteTransaction transaction); - protected abstract void transactionCommitted(SnapshotBackedWriteTransaction transaction); + protected void transactionAborted(SnapshotBackedWriteTransaction transaction) { + } + + protected void transactionCommitted(SnapshotBackedWriteTransaction transaction) { + } }