From 79418d81cd6accb12ee52d33d5add6f495d7db3c Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 25 Apr 2017 16:58:47 +0200 Subject: [PATCH] Handle AbortLocalTransactionRequest When local transactions are aborted from the frontend, it is done via a dedicated message which we failed to account for. This can happen only as an alternative to CommitLocalTransactionRequest, hence needs to be handled only in FrontendReadWriteTransaction. Change-Id: I350a103f132da473d397a7d5f7de7e45850911f3 Signed-off-by: Robert Varga --- .../datastore/AbstractFrontendHistory.java | 2 +- .../FrontendReadWriteTransaction.java | 23 +++++++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java index e7fd894594..8b437863e8 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java @@ -177,7 +177,7 @@ abstract class AbstractFrontendHistory implements Identifiable) request).isSnapshotOnly()) { - LOG.debug("{}: allocatint new open snapshot {}", persistenceId(), id); + LOG.debug("{}: allocating new open snapshot {}", persistenceId(), id); tree.getStats().incrementReadOnlyTransactionCount(); return createOpenSnapshot(id); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendReadWriteTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendReadWriteTransaction.java index 64aef6838b..9f1df4c8ab 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendReadWriteTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendReadWriteTransaction.java @@ -14,6 +14,7 @@ import com.google.common.util.concurrent.FutureCallback; import java.util.Collection; import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; +import org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest; import org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest; import org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest; import org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess; @@ -101,7 +102,10 @@ final class FrontendReadWriteTransaction extends FrontendTransaction { handleTransactionDoCommit((TransactionDoCommitRequest) request, envelope, now); return null; } else if (request instanceof TransactionAbortRequest) { - handleTransactionAbort((TransactionAbortRequest) request, envelope, now); + handleTransactionAbort(request.getSequence(), envelope, now); + return null; + } else if (request instanceof AbortLocalTransactionRequest) { + handleLocalTransactionAbort(request.getSequence(), envelope, now); return null; } else { LOG.warn("Rejecting unsupported request {}", request); @@ -142,11 +146,17 @@ final class FrontendReadWriteTransaction extends FrontendTransaction { }); } - private void handleTransactionAbort(final TransactionAbortRequest request, - final RequestEnvelope envelope, final long now) throws RequestException { + private void handleLocalTransactionAbort(final long sequence, final RequestEnvelope envelope, final long now) { + Preconditions.checkState(readyCohort == null, "Transaction {} encountered local abort with commit underway", + getIdentifier()); + openTransaction.abort(() -> recordAndSendSuccess(envelope, now, new TransactionAbortSuccess(getIdentifier(), + sequence))); + } + + private void handleTransactionAbort(final long sequence, final RequestEnvelope envelope, final long now) { if (readyCohort == null) { - openTransaction.abort(() -> recordAndSendSuccess(envelope, now, - new TransactionAbortSuccess(getIdentifier(), request.getSequence()))); + openTransaction.abort(() -> recordAndSendSuccess(envelope, now, new TransactionAbortSuccess(getIdentifier(), + sequence))); return; } @@ -154,8 +164,7 @@ final class FrontendReadWriteTransaction extends FrontendTransaction { @Override public void onSuccess(final Void result) { readyCohort = null; - recordAndSendSuccess(envelope, now, new TransactionAbortSuccess(getIdentifier(), - request.getSequence())); + recordAndSendSuccess(envelope, now, new TransactionAbortSuccess(getIdentifier(), sequence)); LOG.debug("Transaction {} aborted", getIdentifier()); } -- 2.36.6