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%2Fdatabroker%2Factors%2Fdds%2FProxyHistory.java;h=ad105c31f2f194ff610bac75ff8c3d432324b853;hb=db3d7caeeb310f76a9a159f9a8d7e9beff89f645;hp=e75a2df4c0d6084ba6629ff2926357a7b6a8a0f1;hpb=31316f39aecc6bad171de539292ff5d7f4743419;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ProxyHistory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ProxyHistory.java index e75a2df4c0..ad105c31f2 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ProxyHistory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/databroker/actors/dds/ProxyHistory.java @@ -19,7 +19,6 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; -import java.util.function.BiConsumer; import java.util.function.Consumer; import javax.annotation.concurrent.GuardedBy; import org.opendaylight.controller.cluster.access.client.AbstractClientConnection; @@ -128,10 +127,9 @@ abstract class ProxyHistory implements Identifiable { @Override void onTransactionCompleted(final AbstractProxyTransaction tx) { Verify.verify(tx instanceof LocalProxyTransaction); - if (tx instanceof LocalReadWriteProxyTransaction) { - if (LAST_SEALED_UPDATER.compareAndSet(this, (LocalReadWriteProxyTransaction) tx, null)) { - LOG.debug("Completed last sealed transaction {}", tx); - } + if (tx instanceof LocalReadWriteProxyTransaction + && LAST_SEALED_UPDATER.compareAndSet(this, (LocalReadWriteProxyTransaction) tx, null)) { + LOG.debug("Completed last sealed transaction {}", tx); } } @@ -272,22 +270,34 @@ abstract class ProxyHistory implements Identifiable { } @Override - void forwardRequest(final Request request, final Consumer> callback, - final BiConsumer, Consumer>> forwardTo) throws RequestException { - // FIXME: do not use sendRequest() once we have throttling in place, as we have already waited the - // period required to get into the queue. + void replayEntry(final ConnectionEntry entry, final Consumer replayTo) + throws RequestException { + final Request request = entry.getRequest(); if (request instanceof TransactionRequest) { - forwardTransactionRequest((TransactionRequest) request, callback); + lookupProxy(request).replayRequest((TransactionRequest) request, entry.getCallback(), + entry.getEnqueuedTicks()); } else if (request instanceof LocalHistoryRequest) { - forwardTo.accept(request, callback); + replayTo.accept(entry); } else { throw new IllegalArgumentException("Unhandled request " + request); } } - private void forwardTransactionRequest(final TransactionRequest request, - final Consumer> callback) throws RequestException { + @Override + void forwardEntry(final ConnectionEntry entry, final Consumer forwardTo) + throws RequestException { + final Request request = entry.getRequest(); + if (request instanceof TransactionRequest) { + lookupProxy(request).forwardRequest((TransactionRequest) request, entry.getCallback()); + } else if (request instanceof LocalHistoryRequest) { + forwardTo.accept(entry); + } else { + throw new IllegalArgumentException("Unhandled request " + request); + } + } + private AbstractProxyTransaction lookupProxy(final Request request) + throws RequestReplayException { final AbstractProxyTransaction proxy; lock.lock(); try { @@ -295,11 +305,11 @@ abstract class ProxyHistory implements Identifiable { } finally { lock.unlock(); } - if (proxy == null) { - throw new RequestReplayException("Failed to find proxy for %s", request); + if (proxy != null) { + return proxy; } - proxy.forwardRequest(request, callback); + throw new RequestReplayException("Failed to find proxy for %s", request); } } @@ -439,9 +449,11 @@ abstract class ProxyHistory implements Identifiable { } @GuardedBy("lock") + @SuppressWarnings("checkstyle:hiddenField") abstract AbstractProxyTransaction doCreateTransactionProxy(AbstractClientConnection connection, TransactionIdentifier txId, boolean snapshotOnly, boolean isDone); + @SuppressWarnings("checkstyle:hiddenField") abstract ProxyHistory createSuccessor(AbstractClientConnection connection); @SuppressFBWarnings(value = "UL_UNRELEASED_LOCK", justification = "Lock is released asynchronously via the cohort")