From f5f6ffd70f78e81106c04e1f1bb252e1e51a7617 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 25 Jun 2020 23:35:55 +0200 Subject: [PATCH] Split TransactionChainProxy.combineWithPriorReadOnlyTxFutures() There is a common and uncommon path here, where we expect majority of high-performance uses to short-circuit to no combining at all. Split that simple case out, so that we aid JIT inlining and also know in profiling runs which branches are usually taken. Change-Id: I18aaa12837c472308b46b770551e606096f7c983 Signed-off-by: Robert Varga --- .../datastore/TransactionChainProxy.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java index 7c36adb70e..4ef89b4684 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionChainProxy.java @@ -256,38 +256,42 @@ final class TransactionChainProxy extends AbstractTransactionContextFactory Future combineFutureWithPossiblePriorReadOnlyTxFutures(final Future future, final TransactionIdentifier txId) { - if (!priorReadOnlyTxPromises.containsKey(txId) && !priorReadOnlyTxPromises.isEmpty()) { - Collection>> priorReadOnlyTxPromiseEntries = - new ArrayList<>(priorReadOnlyTxPromises.entrySet()); - if (priorReadOnlyTxPromiseEntries.isEmpty()) { - return future; - } + return priorReadOnlyTxPromises.isEmpty() || priorReadOnlyTxPromises.containsKey(txId) ? future + // Tough luck, we need do some work + : combineWithPriorReadOnlyTxFutures(future, txId); + } - List> priorReadOnlyTxFutures = new ArrayList<>(priorReadOnlyTxPromiseEntries.size()); - for (Entry> entry: priorReadOnlyTxPromiseEntries) { - LOG.debug("Tx: {} - waiting on future for prior read-only Tx {}", txId, entry.getKey()); - priorReadOnlyTxFutures.add(entry.getValue().future()); - } + // Split out of the common path + private Future combineWithPriorReadOnlyTxFutures(final Future future, final TransactionIdentifier txId) { + // Take a stable snapshot, and check if we raced + final List>> priorReadOnlyTxPromiseEntries = + new ArrayList<>(priorReadOnlyTxPromises.entrySet()); + if (priorReadOnlyTxPromiseEntries.isEmpty()) { + return future; + } - Future> combinedFutures = Futures.sequence(priorReadOnlyTxFutures, - getActorUtils().getClientDispatcher()); + final List> priorReadOnlyTxFutures = new ArrayList<>(priorReadOnlyTxPromiseEntries.size()); + for (Entry> entry: priorReadOnlyTxPromiseEntries) { + LOG.debug("Tx: {} - waiting on future for prior read-only Tx {}", txId, entry.getKey()); + priorReadOnlyTxFutures.add(entry.getValue().future()); + } - final Promise returnPromise = Futures.promise(); - final OnComplete> onComplete = new OnComplete>() { - @Override - public void onComplete(final Throwable failure, final Iterable notUsed) { - LOG.debug("Tx: {} - prior read-only Tx futures complete", txId); + final Future> combinedFutures = Futures.sequence(priorReadOnlyTxFutures, + getActorUtils().getClientDispatcher()); - // Complete the returned Promise with the original Future. - returnPromise.completeWith(future); - } - }; + final Promise returnPromise = Futures.promise(); + final OnComplete> onComplete = new OnComplete<>() { + @Override + public void onComplete(final Throwable failure, final Iterable notUsed) { + LOG.debug("Tx: {} - prior read-only Tx futures complete", txId); - combinedFutures.onComplete(onComplete, getActorUtils().getClientDispatcher()); - return returnPromise.future(); - } else { - return future; - } + // Complete the returned Promise with the original Future. + returnPromise.completeWith(future); + } + }; + + combinedFutures.onComplete(onComplete, getActorUtils().getClientDispatcher()); + return returnPromise.future(); } @Override -- 2.36.6