X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-dom-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fyang%2Fmd%2Fsal%2Fdom%2Fimpl%2FDomInmemoryDataBrokerModule.java;h=948f3c8d8b637b8dfb72fdd376fa7ee1f49aa3c3;hb=26d0e25159bf3b73ca38a88e17268cf17f876d8d;hp=667c0fc2826a100b2fc6ae77f4c0344a52d723f6;hpb=ef9d39a391a436a7920f2a72a42a646979955b20;p=controller.git diff --git a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/DomInmemoryDataBrokerModule.java b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/DomInmemoryDataBrokerModule.java index 667c0fc282..948f3c8d8b 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/DomInmemoryDataBrokerModule.java +++ b/opendaylight/md-sal/sal-dom-broker/src/main/java/org/opendaylight/controller/config/yang/md/sal/dom/impl/DomInmemoryDataBrokerModule.java @@ -7,16 +7,18 @@ */ package org.opendaylight.controller.config.yang.md.sal.dom.impl; -import java.util.concurrent.Executors; - +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitDeadlockException; import org.opendaylight.controller.md.sal.dom.broker.impl.DOMDataBrokerImpl; -import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; +import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreFactory; import org.opendaylight.controller.sal.core.spi.data.DOMStore; +import org.opendaylight.yangtools.util.concurrent.DeadlockDetectingListeningExecutorService; +import org.opendaylight.yangtools.util.concurrent.SpecialExecutors; +import org.opendaylight.yangtools.util.PropertyUtils; import com.google.common.collect.ImmutableMap; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; /** * @@ -24,6 +26,17 @@ import com.google.common.util.concurrent.MoreExecutors; public final class DomInmemoryDataBrokerModule extends org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractDomInmemoryDataBrokerModule { + private static final String FUTURE_CALLBACK_EXECUTOR_MAX_QUEUE_SIZE_PROP = + "mdsal.datastore-future-callback-queue.size"; + private static final int DEFAULT_FUTURE_CALLBACK_EXECUTOR_MAX_QUEUE_SIZE = 1000; + + private static final String FUTURE_CALLBACK_EXECUTOR_MAX_POOL_SIZE_PROP = + "mdsal.datastore-future-callback-pool.size"; + private static final int DEFAULT_FUTURE_CALLBACK_EXECUTOR_MAX_POOL_SIZE = 20; + private static final String COMMIT_EXECUTOR_MAX_QUEUE_SIZE_PROP = + "mdsal.datastore-commit-queue.size"; + private static final int DEFAULT_COMMIT_EXECUTOR_MAX_QUEUE_SIZE = 5000; + public DomInmemoryDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) { super(identifier, dependencyResolver); @@ -43,28 +56,55 @@ public final class DomInmemoryDataBrokerModule extends @Override public java.lang.AutoCloseable createInstance() { - ListeningExecutorService storeExecutor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(2)); //Initializing Operational DOM DataStore defaulting to InMemoryDOMDataStore if one is not configured DOMStore operStore = getOperationalDataStoreDependency(); if(operStore == null){ //we will default to InMemoryDOMDataStore creation - operStore = new InMemoryDOMDataStore("DOM-OPER", storeExecutor); - //here we will register the SchemaContext listener - getSchemaServiceDependency().registerSchemaContextListener((InMemoryDOMDataStore)operStore); + operStore = InMemoryDOMDataStoreFactory.create("DOM-OPER", getSchemaServiceDependency()); } DOMStore configStore = getConfigDataStoreDependency(); if(configStore == null){ //we will default to InMemoryDOMDataStore creation - configStore = new InMemoryDOMDataStore("DOM-CFG", storeExecutor); - //here we will register the SchemaContext listener - getSchemaServiceDependency().registerSchemaContextListener((InMemoryDOMDataStore)configStore); + configStore = InMemoryDOMDataStoreFactory.create("DOM-CFG", getSchemaServiceDependency()); } ImmutableMap datastores = ImmutableMap . builder().put(LogicalDatastoreType.OPERATIONAL, operStore) .put(LogicalDatastoreType.CONFIGURATION, configStore).build(); - DOMDataBrokerImpl newDataBroker = new DOMDataBrokerImpl(datastores, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor())); + /* + * We use a single-threaded executor for commits with a bounded queue capacity. If the + * queue capacity is reached, subsequent commit tasks will be rejected and the commits will + * fail. This is done to relieve back pressure. This should be an extreme scenario - either + * there's deadlock(s) somewhere and the controller is unstable or some rogue component is + * continuously hammering commits too fast or the controller is just over-capacity for the + * system it's running on. + */ + ExecutorService commitExecutor = SpecialExecutors.newBoundedSingleThreadExecutor( + PropertyUtils.getIntSystemProperty( + COMMIT_EXECUTOR_MAX_QUEUE_SIZE_PROP, + DEFAULT_COMMIT_EXECUTOR_MAX_QUEUE_SIZE), "WriteTxCommit"); + + /* + * We use an executor for commit ListenableFuture callbacks that favors reusing available + * threads over creating new threads at the expense of execution time. The assumption is + * that most ListenableFuture callbacks won't execute a lot of business logic where we want + * it to run quicker - many callbacks will likely just handle error conditions and do + * nothing on success. The executor queue capacity is bounded and, if the capacity is + * reached, subsequent submitted tasks will block the caller. + */ + Executor listenableFutureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool( + PropertyUtils.getIntSystemProperty( + FUTURE_CALLBACK_EXECUTOR_MAX_POOL_SIZE_PROP, + DEFAULT_FUTURE_CALLBACK_EXECUTOR_MAX_POOL_SIZE), + PropertyUtils.getIntSystemProperty( + FUTURE_CALLBACK_EXECUTOR_MAX_QUEUE_SIZE_PROP, + DEFAULT_FUTURE_CALLBACK_EXECUTOR_MAX_QUEUE_SIZE), "CommitFutures"); + + DOMDataBrokerImpl newDataBroker = new DOMDataBrokerImpl(datastores, + new DeadlockDetectingListeningExecutorService(commitExecutor, + TransactionCommitDeadlockException.DEADLOCK_EXECUTOR_FUNCTION, + listenableFutureExecutor)); return newDataBroker; }