From dc10cce59fd3f2e11af715605f094dfeabc4c73a Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 2 Apr 2015 12:52:08 +0200 Subject: [PATCH] CDS: introduce AbstractThreePhaseCommitCohort This is a rework of ChainedTransactionProxy/TransactionProxy interactions. Rather than invoking a callback from TransactionProxy to ChainedTransactionProxy, wrap the ready() call in ChainedTransactionProxy and extract the required information from the returned cohort object. Also make sure we preallocate the cohort future collection. Change-Id: I539ffb085800e4d62f1eab5bc8dae284e73c6aab Signed-off-by: Robert Varga --- .../AbstractThreePhaseCommitCohort.java | 22 +++++++++++++++++++ .../datastore/ChainedTransactionProxy.java | 8 ++++--- .../NoOpDOMStoreThreePhaseCommitCohort.java | 17 ++++++++++---- .../ThreePhaseCommitCohortProxy.java | 6 ++--- .../cluster/datastore/TransactionProxy.java | 18 ++------------- 5 files changed, 44 insertions(+), 27 deletions(-) create mode 100644 opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractThreePhaseCommitCohort.java diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractThreePhaseCommitCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractThreePhaseCommitCohort.java new file mode 100644 index 0000000000..cac0f51354 --- /dev/null +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractThreePhaseCommitCohort.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2015 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, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.cluster.datastore; + +import akka.actor.ActorSelection; +import java.util.List; +import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; +import scala.concurrent.Future; + +/** + * Abstract base class for {@link DOMStoreThreePhaseCommitCohort} instances returned by this + * implementation. In addition to the usual set of methods it also contains the list of actor + * futures. + */ +abstract class AbstractThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort { + abstract List> getCohortFutures(); +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ChainedTransactionProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ChainedTransactionProxy.java index c59a277fa8..ed3aa85c1f 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ChainedTransactionProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ChainedTransactionProxy.java @@ -44,10 +44,12 @@ final class ChainedTransactionProxy extends TransactionProxy { } @Override - protected void onTransactionReady(List> readyFutures) { + public AbstractThreePhaseCommitCohort ready() { + final AbstractThreePhaseCommitCohort ret = super.ready(); + readyFutures = ret.getCohortFutures(); LOG.debug("onTransactionReady {} pending readyFutures size {} chain {}", getIdentifier(), - readyFutures.size(), getTransactionChainId()); - this.readyFutures = readyFutures; + readyFutures.size(), getTransactionChainId()); + return ret; } /** diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/NoOpDOMStoreThreePhaseCommitCohort.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/NoOpDOMStoreThreePhaseCommitCohort.java index 766cf1d578..376b658046 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/NoOpDOMStoreThreePhaseCommitCohort.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/NoOpDOMStoreThreePhaseCommitCohort.java @@ -7,14 +7,18 @@ */ package org.opendaylight.controller.cluster.datastore; +import akka.actor.ActorSelection; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; +import java.util.Collections; +import java.util.List; +import scala.concurrent.Future; /** - * A {@link DOMStoreThreePhaseCommitCohort} instance given out for empty transactions. + * A {@link org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort} + * instance given out for empty transactions. */ -final class NoOpDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseCommitCohort { +final class NoOpDOMStoreThreePhaseCommitCohort extends AbstractThreePhaseCommitCohort { static final NoOpDOMStoreThreePhaseCommitCohort INSTANCE = new NoOpDOMStoreThreePhaseCommitCohort(); private static final ListenableFuture IMMEDIATE_VOID_SUCCESS = Futures.immediateFuture(null); @@ -43,4 +47,9 @@ final class NoOpDOMStoreThreePhaseCommitCohort implements DOMStoreThreePhaseComm public ListenableFuture commit() { return IMMEDIATE_VOID_SUCCESS; } -} \ No newline at end of file + + @Override + List> getCohortFutures() { + return Collections.emptyList(); + } +} diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java index 0b826071ec..3a2bcf2336 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/ThreePhaseCommitCohortProxy.java @@ -11,7 +11,6 @@ package org.opendaylight.controller.cluster.datastore; import akka.actor.ActorSelection; import akka.dispatch.Futures; import akka.dispatch.OnComplete; -import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Lists; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.SettableFuture; @@ -25,7 +24,6 @@ import org.opendaylight.controller.cluster.datastore.messages.CanCommitTransacti import org.opendaylight.controller.cluster.datastore.messages.CommitTransaction; import org.opendaylight.controller.cluster.datastore.messages.CommitTransactionReply; import org.opendaylight.controller.cluster.datastore.utils.ActorContext; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import scala.concurrent.Future; @@ -34,7 +32,7 @@ import scala.runtime.AbstractFunction1; /** * ThreePhaseCommitCohortProxy represents a set of remote cohort proxies */ -public class ThreePhaseCommitCohortProxy implements DOMStoreThreePhaseCommitCohort{ +public class ThreePhaseCommitCohortProxy extends AbstractThreePhaseCommitCohort { private static final Logger LOG = LoggerFactory.getLogger(ThreePhaseCommitCohortProxy.class); @@ -322,7 +320,7 @@ public class ThreePhaseCommitCohortProxy implements DOMStoreThreePhaseCommitCoho }, actorContext.getClientDispatcher()); } - @VisibleForTesting + @Override List> getCohortFutures() { return Collections.unmodifiableList(cohortFutures); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java index a2a7a12044..0b863623b4 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/TransactionProxy.java @@ -21,7 +21,6 @@ import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.SettableFuture; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -42,7 +41,6 @@ import org.opendaylight.controller.cluster.datastore.utils.ActorContext; import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException; import org.opendaylight.controller.sal.core.spi.data.AbstractDOMStoreTransaction; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; -import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort; import org.opendaylight.yangtools.util.concurrent.MappingCheckedFuture; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; @@ -396,7 +394,7 @@ public class TransactionProxy extends AbstractDOMStoreTransaction>emptyList()); TransactionRateLimitingCallback.adjustRateLimitForUnusedTransaction(actorContext); return NoOpDOMStoreThreePhaseCommitCohort.INSTANCE; } throttleOperation(txFutureCallbackMap.size()); - List> cohortFutures = Lists.newArrayList(); - + List> cohortFutures = new ArrayList<>(txFutureCallbackMap.size()); for(TransactionFutureCallback txFutureCallback : txFutureCallbackMap.values()) { LOG.debug("Tx {} Readying transaction for shard {} chain {}", getIdentifier(), @@ -440,20 +436,10 @@ public class TransactionProxy extends AbstractDOMStoreTransaction> cohortFutures) { - } - @Override public void close() { if (!seal(TransactionState.CLOSED)) { -- 2.36.6