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=80d5417e0bf392d6150f64d73c9a519e3d58efaf;hp=0ea1029a9d87c4cfc8537b81798a957d5d269749;hb=7292faba613ab556babd7bbcdd78984f5668bf9b;hpb=daaef05cbf70e6cbec9af181258faead6d9620a6 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 0ea1029a9d..80d5417e0b 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,10 +8,11 @@ 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; -import org.opendaylight.controller.cluster.datastore.identifiers.TransactionIdentifier; +import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply; import org.opendaylight.controller.cluster.datastore.messages.ReadyLocalTransaction; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; @@ -29,26 +30,43 @@ 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) { + final SnapshotBackedWriteTransaction transaction, + final DataTreeModification modification, + final Exception operationError) { this.actorContext = Preconditions.checkNotNull(actorContext); this.leader = Preconditions.checkNotNull(leader); this.transaction = Preconditions.checkNotNull(transaction); this.modification = Preconditions.checkNotNull(modification); + this.operationError = operationError; + } + + 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) { - final ReadyLocalTransaction message = new ReadyLocalTransaction(transaction.getIdentifier().toString(), + if (operationError != null) { + return Futures.failed(operationError); + } + + final ReadyLocalTransaction message = new ReadyLocalTransaction(transaction.getIdentifier(), modification, immediate); - return actorContext.executeOperationAsync(leader, message); + return actorContext.executeOperationAsync(leader, message, actorContext.getTransactionCommitOperationTimeout()); } Future initiateCoordinatedCommit() { @@ -79,7 +97,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 +134,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 aborted) { + } + + protected void transactionCommitted(SnapshotBackedWriteTransaction comitted) { + } }