From: Martin Bobak Date: Sun, 31 Aug 2014 18:22:43 +0000 (+0200) Subject: Bug 1686 - Rework TopologyManager to use transaction chaining in order to not conflic... X-Git-Tag: release/helium~131^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=306f770a9f36e40a940acaed8d1713a5e7d7bef3 Bug 1686 - Rework TopologyManager to use transaction chaining in order to not conflict with itself Change-Id: I43c150559141d1cdc1c118cb252e7cae9b138739 Signed-off-by: Martin Bobak --- diff --git a/opendaylight/md-sal/inventory-manager/src/main/java/org/opendaylight/controller/md/inventory/manager/FlowCapableInventoryProvider.java b/opendaylight/md-sal/inventory-manager/src/main/java/org/opendaylight/controller/md/inventory/manager/FlowCapableInventoryProvider.java index 1e77a5554f..3db929b99d 100644 --- a/opendaylight/md-sal/inventory-manager/src/main/java/org/opendaylight/controller/md/inventory/manager/FlowCapableInventoryProvider.java +++ b/opendaylight/md-sal/inventory-manager/src/main/java/org/opendaylight/controller/md/inventory/manager/FlowCapableInventoryProvider.java @@ -47,7 +47,7 @@ class FlowCapableInventoryProvider implements AutoCloseable, Runnable, Transacti final NodeChangeCommiter changeCommiter = new NodeChangeCommiter(FlowCapableInventoryProvider.this); this.listenerRegistration = this.notificationService.registerNotificationListener(changeCommiter); - this.txChain = dataBroker.createTransactionChain(this); + this.txChain = dataBroker.createTransactionChain(this); thread = new Thread(this); thread.setDaemon(true); thread.setName("FlowCapableInventoryProvider"); @@ -81,7 +81,7 @@ class FlowCapableInventoryProvider implements AutoCloseable, Runnable, Transacti thread.join(); thread = null; } - if(txChain != null) { + if (txChain != null) { txChain.close(); txChain = null; } @@ -137,8 +137,8 @@ class FlowCapableInventoryProvider implements AutoCloseable, Runnable, Transacti @Override public void onTransactionChainFailed(final TransactionChain chain, final AsyncTransaction transaction, - final Throwable cause) { - LOG.error("Failed to export Flow Capable Inventory, Transaction {} failed.",transaction.getIdentifier(),cause); + final Throwable cause) { + LOG.error("Failed to export Flow Capable Inventory, Transaction {} failed.", transaction.getIdentifier(), cause); } diff --git a/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/OperationProcessor.java b/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/OperationProcessor.java index 3800413eb1..1cf648eb97 100644 --- a/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/OperationProcessor.java +++ b/opendaylight/md-sal/topology-manager/src/main/java/org/opendaylight/md/controller/topology/manager/OperationProcessor.java @@ -13,21 +13,27 @@ import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.Futures; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; +import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChain; +import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -final class OperationProcessor implements Runnable { +final class OperationProcessor implements AutoCloseable, Runnable, TransactionChainListener { private static final Logger LOG = LoggerFactory.getLogger(OperationProcessor.class); private static final int MAX_TRANSACTION_OPERATIONS = 100; private static final int OPERATION_QUEUE_DEPTH = 500; private final BlockingQueue queue = new LinkedBlockingQueue<>(OPERATION_QUEUE_DEPTH); private final DataBroker dataBroker; + private final BindingTransactionChain transactionChain; OperationProcessor(final DataBroker dataBroker) { this.dataBroker = Preconditions.checkNotNull(dataBroker); + transactionChain = this.dataBroker.createTransactionChain(this); } void enqueueOperation(final TopologyOperation task) { @@ -45,7 +51,8 @@ final class OperationProcessor implements Runnable { TopologyOperation op = queue.take(); LOG.debug("New operations available, starting transaction"); - final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction(); + final ReadWriteTransaction tx = transactionChain.newReadWriteTransaction(); + int ops = 0; do { @@ -83,4 +90,22 @@ final class OperationProcessor implements Runnable { queue.poll(); } } + + @Override + public void onTransactionChainFailed(TransactionChain chain, AsyncTransaction transaction, Throwable cause) { + LOG.error("Failed to export Topology manager operations, Transaction {} failed.", transaction.getIdentifier(), cause); + } + + @Override + public void onTransactionChainSuccessful(TransactionChain chain) { + //NOOP + } + + @Override + public void close() throws Exception { + if (transactionChain != null) { + transactionChain.close(); + } + + } }