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=ec7b46d5bbd5ef278489560d534728999820ef65;hp=267513fc2f1264943f82c5da11d2363dd18cbd5e;hb=93e6f3bfc003d4ce2d968761dff963615a0b799d;hpb=34e38a415bc299403657315a5b61afd432dcbbee 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 267513fc2f..ec7b46d5bb 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; @@ -29,13 +30,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 final Exception operationError; protected LocalThreePhaseCommitCohort(final ActorContext actorContext, final ActorSelection leader, final SnapshotBackedWriteTransaction transaction, final DataTreeModification modification) { @@ -43,9 +45,23 @@ abstract class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCo this.leader = Preconditions.checkNotNull(leader); this.transaction = Preconditions.checkNotNull(transaction); this.modification = Preconditions.checkNotNull(modification); + this.operationError = null; + } + + 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()); @@ -79,7 +95,7 @@ abstract class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCo if (failure != null) { LOG.error("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure); transactionAborted(transaction); - } else if (CommitTransactionReply.SERIALIZABLE_CLASS.isInstance(message)) { + } else if (CommitTransactionReply.isSerializedType(message)) { LOG.debug("Transaction {} committed successfully", transaction.getIdentifier()); transactionCommitted(transaction); } else { @@ -116,6 +132,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) { + } }