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=091bfa01e4db0346b85fbb432ddace51e7e8857c;hp=267513fc2f1264943f82c5da11d2363dd18cbd5e;hb=118cd0216b0c6b0ec1a01689ec2025a13e090861;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..091bfa01e4 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 @@ -7,17 +7,23 @@ */ package org.opendaylight.controller.cluster.datastore; +import static java.util.Objects.requireNonNull; + 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 java.util.Optional; +import java.util.SortedSet; +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; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; -import org.opendaylight.controller.sal.core.spi.data.SnapshotBackedWriteTransaction; -import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification; +import org.opendaylight.controller.cluster.datastore.utils.ActorUtils; +import org.opendaylight.mdsal.common.api.CommitInfo; +import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort; +import org.opendaylight.mdsal.dom.spi.store.SnapshotBackedWriteTransaction; +import org.opendaylight.yangtools.yang.common.Empty; +import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import scala.concurrent.Future; @@ -29,65 +35,84 @@ 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 ActorUtils actorUtils; private final ActorSelection leader; + private final Exception operationError; + + protected LocalThreePhaseCommitCohort(final ActorUtils actorUtils, final ActorSelection leader, + final SnapshotBackedWriteTransaction transaction, + final DataTreeModification modification, + final Exception operationError) { + this.actorUtils = requireNonNull(actorUtils); + this.leader = requireNonNull(leader); + this.transaction = requireNonNull(transaction); + this.modification = requireNonNull(modification); + this.operationError = operationError; + } - protected LocalThreePhaseCommitCohort(final ActorContext actorContext, final ActorSelection leader, - final SnapshotBackedWriteTransaction transaction, final DataTreeModification modification) { - this.actorContext = Preconditions.checkNotNull(actorContext); - this.leader = Preconditions.checkNotNull(leader); - this.transaction = Preconditions.checkNotNull(transaction); - this.modification = Preconditions.checkNotNull(modification); + protected LocalThreePhaseCommitCohort(final ActorUtils actorUtils, final ActorSelection leader, + final SnapshotBackedWriteTransaction transaction, final Exception operationError) { + this.actorUtils = requireNonNull(actorUtils); + this.leader = requireNonNull(leader); + this.transaction = requireNonNull(transaction); + this.operationError = requireNonNull(operationError); + modification = null; } - private Future initiateCommit(final boolean immediate) { - final ReadyLocalTransaction message = new ReadyLocalTransaction(transaction.getIdentifier().toString(), - modification, immediate); - return actorContext.executeOperationAsync(leader, message, actorContext.getTransactionCommitOperationTimeout()); + private Future initiateCommit(final boolean immediate, + final Optional> participatingShardNames) { + if (operationError != null) { + return Futures.failed(operationError); + } + + final ReadyLocalTransaction message = new ReadyLocalTransaction(transaction.getIdentifier(), + modification, immediate, participatingShardNames); + return actorUtils.executeOperationAsync(leader, message, actorUtils.getTransactionCommitOperationTimeout()); } - Future initiateCoordinatedCommit() { - final Future messageFuture = initiateCommit(false); - final Future ret = TransactionReadyReplyMapper.transform(messageFuture, actorContext, + Future initiateCoordinatedCommit(final Optional> participatingShardNames) { + final Future messageFuture = initiateCommit(false, participatingShardNames); + final Future ret = TransactionReadyReplyMapper.transform(messageFuture, actorUtils, transaction.getIdentifier()); ret.onComplete(new OnComplete() { @Override - public void onComplete(final Throwable failure, final ActorSelection success) throws Throwable { + public void onComplete(final Throwable failure, final ActorSelection success) { if (failure != null) { - LOG.info("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure); + LOG.warn("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure); transactionAborted(transaction); return; } LOG.debug("Transaction {} resolved to actor {}", transaction.getIdentifier(), success); } - }, actorContext.getClientDispatcher()); + }, actorUtils.getClientDispatcher()); return ret; } Future initiateDirectCommit() { - final Future messageFuture = initiateCommit(true); - messageFuture.onComplete(new OnComplete() { + final Future messageFuture = initiateCommit(true, Optional.empty()); + messageFuture.onComplete(new OnComplete<>() { @Override - public void onComplete(final Throwable failure, final Object message) throws Throwable { + public void onComplete(final Throwable failure, final Object message) { if (failure != null) { - LOG.error("Failed to prepare transaction {} on backend", transaction.getIdentifier(), failure); + LOG.warn("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 { - LOG.error("Transaction {} resulted in unhandled message type {}, aborting", message.getClass()); + LOG.error("Transaction {} resulted in unhandled message type {}, aborting", + transaction.getIdentifier(), message.getClass()); transactionAborted(transaction); } } - }, actorContext.getClientDispatcher()); + }, actorUtils.getClientDispatcher()); return messageFuture; } @@ -99,23 +124,26 @@ abstract class LocalThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCo } @Override - public final ListenableFuture preCommit() { + public final ListenableFuture preCommit() { // Intended no-op throw new UnsupportedOperationException(); } @Override - public final ListenableFuture abort() { + public final ListenableFuture abort() { // Intended no-op throw new UnsupportedOperationException(); } @Override - public final ListenableFuture commit() { + public final ListenableFuture commit() { // Intended no-op throw new UnsupportedOperationException(); } - protected abstract void transactionAborted(SnapshotBackedWriteTransaction transaction); - protected abstract void transactionCommitted(SnapshotBackedWriteTransaction transaction); + protected void transactionAborted(final SnapshotBackedWriteTransaction aborted) { + } + + protected void transactionCommitted(final SnapshotBackedWriteTransaction comitted) { + } }