X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FFrontendTransaction.java;h=2a4aeaa49b3d04b30b3859d99e75287e4f308ca5;hb=27b168d3ca3807123b4877f1ad0662b2610f393d;hp=8846467b59d2d924f783014215d947551a498f21;hpb=17a38939f6ba3cbbc1ff0f1f3e00b58f5002813d;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendTransaction.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendTransaction.java index 8846467b59..2a4aeaa49b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendTransaction.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/FrontendTransaction.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016, 2017 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, @@ -15,6 +15,8 @@ import java.util.Iterator; import java.util.Queue; import javax.annotation.Nullable; import javax.annotation.concurrent.NotThreadSafe; +import org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest; +import org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceSuccess; import org.opendaylight.controller.cluster.access.commands.OutOfOrderRequestException; import org.opendaylight.controller.cluster.access.commands.TransactionRequest; import org.opendaylight.controller.cluster.access.commands.TransactionSuccess; @@ -23,6 +25,8 @@ import org.opendaylight.controller.cluster.access.concepts.RequestException; import org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException; import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier; import org.opendaylight.yangtools.concepts.Identifiable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Frontend common transaction state as observed by the shard leader. @@ -31,6 +35,8 @@ import org.opendaylight.yangtools.concepts.Identifiable; */ @NotThreadSafe abstract class FrontendTransaction implements Identifiable { + private static final Logger LOG = LoggerFactory.getLogger(FrontendTransaction.class); + private final AbstractFrontendHistory history; private final TransactionIdentifier id; @@ -44,6 +50,8 @@ abstract class FrontendTransaction implements Identifiable> replaySequence(final long sequence) throws RequestException { // Fast path check: if the requested sequence is the next request, bail early if (expectedSequence == sequence) { @@ -108,9 +120,44 @@ abstract class FrontendTransaction implements Identifiable handleRequest(TransactionRequest request, - RequestEnvelope envelope, long now) throws RequestException; + // Request order has already been checked by caller and replaySequence() + @SuppressWarnings("checkstyle:IllegalCatch") + @Nullable + final TransactionSuccess handleRequest(final TransactionRequest request, final RequestEnvelope envelope, + final long now) throws RequestException { + if (request instanceof IncrementTransactionSequenceRequest) { + final IncrementTransactionSequenceRequest incr = (IncrementTransactionSequenceRequest) request; + expectedSequence += incr.getIncrement(); + + return recordSuccess(incr.getSequence(), + new IncrementTransactionSequenceSuccess(incr.getTarget(), incr.getSequence())); + } + + if (previousFailure != null) { + LOG.debug("{}: Rejecting request {} due to previous failure", persistenceId(), request, previousFailure); + throw previousFailure; + } + + try { + return doHandleRequest(request, envelope, now); + } catch (RuntimeException e) { + /* + * The request failed to process, we should not attempt to ever + * apply it again. Furthermore we cannot accept any further requests + * from this connection, simply because the transaction state is + * undefined. + */ + LOG.debug("{}: Request {} failed to process", persistenceId(), request, e); + previousFailure = new RuntimeRequestException("Request " + request + " failed to process", e); + throw previousFailure; + } + } + + @Nullable + abstract TransactionSuccess doHandleRequest(TransactionRequest request, RequestEnvelope envelope, + long now) throws RequestException; + + abstract void retire(); private void recordResponse(final long sequence, final Object response) { if (replayQueue.isEmpty()) { @@ -148,5 +195,4 @@ abstract class FrontendTransaction implements Identifiable