2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.config.yang.md.sal.dom.impl;
10 import com.google.common.collect.Lists;
11 import java.util.EnumMap;
12 import java.util.List;
14 import java.util.concurrent.ExecutorService;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitDeadlockException;
17 import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean;
18 import org.opendaylight.controller.md.sal.common.util.jmx.ThreadExecutorStatsMXBeanImpl;
19 import org.opendaylight.controller.md.sal.dom.broker.impl.SerializedDOMDataBroker;
20 import org.opendaylight.controller.md.sal.dom.broker.impl.jmx.CommitStatsMXBeanImpl;
21 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreFactory;
22 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
23 import org.opendaylight.yangtools.util.DurationStatisticsTracker;
24 import org.opendaylight.yangtools.util.concurrent.DeadlockDetectingListeningExecutorService;
25 import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
30 * @deprecated Replaced by the clustered data store.
33 public final class DomInmemoryDataBrokerModule extends
34 org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractDomInmemoryDataBrokerModule {
36 private static final String JMX_BEAN_TYPE = "DOMDataBroker";
38 public DomInmemoryDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
39 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
40 super(identifier, dependencyResolver);
43 public DomInmemoryDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
44 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
45 final DomInmemoryDataBrokerModule oldModule, final java.lang.AutoCloseable oldInstance) {
47 super(identifier, dependencyResolver, oldModule, oldInstance);
51 protected void customValidation() {
52 // Add custom validation for module attributes here.
56 public java.lang.AutoCloseable createInstance() {
57 //Initializing Operational DOM DataStore defaulting to InMemoryDOMDataStore if one is not configured
58 DOMStore operStore = getOperationalDataStoreDependency();
59 if (operStore == null) {
60 // we will default to InMemoryDOMDataStore creation
61 operStore = InMemoryDOMDataStoreFactory.create("DOM-OPER", getSchemaServiceDependency());
64 DOMStore configStore = getConfigDataStoreDependency();
65 if (configStore == null) {
66 // we will default to InMemoryDOMDataStore creation
67 configStore = InMemoryDOMDataStoreFactory.create("DOM-CFG", getSchemaServiceDependency());
70 final Map<LogicalDatastoreType, DOMStore> datastores = new EnumMap<>(LogicalDatastoreType.class);
71 datastores.put(LogicalDatastoreType.OPERATIONAL, operStore);
72 datastores.put(LogicalDatastoreType.CONFIGURATION, configStore);
75 * We use an executor for commit ListenableFuture callbacks that favors reusing available
76 * threads over creating new threads at the expense of execution time. The assumption is
77 * that most ListenableFuture callbacks won't execute a lot of business logic where we want
78 * it to run quicker - many callbacks will likely just handle error conditions and do
79 * nothing on success. The executor queue capacity is bounded and, if the capacity is
80 * reached, subsequent submitted tasks will block the caller.
82 ExecutorService listenableFutureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(
83 getMaxDataBrokerFutureCallbackPoolSize(), getMaxDataBrokerFutureCallbackQueueSize(),
84 "CommitFutures", SerializedDOMDataBroker.class);
86 final List<AbstractMXBean> mBeans = Lists.newArrayList();
87 final DurationStatisticsTracker commitStatsTracker;
90 * We use a single-threaded executor for commits with a bounded queue capacity. If the
91 * queue capacity is reached, subsequent commit tasks will be rejected and the commits will
92 * fail. This is done to relieve back pressure. This should be an extreme scenario - either
93 * there's deadlock(s) somewhere and the controller is unstable or some rogue component is
94 * continuously hammering commits too fast or the controller is just over-capacity for the
95 * system it's running on.
97 ExecutorService commitExecutor = SpecialExecutors.newBoundedSingleThreadExecutor(
98 getMaxDataBrokerCommitQueueSize(), "WriteTxCommit", SerializedDOMDataBroker.class);
100 SerializedDOMDataBroker sdb = new SerializedDOMDataBroker(datastores,
101 new DeadlockDetectingListeningExecutorService(commitExecutor,
102 TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER,
103 listenableFutureExecutor));
104 commitStatsTracker = sdb.getCommitStatsTracker();
106 final AbstractMXBean commitExecutorStatsMXBean =
107 ThreadExecutorStatsMXBeanImpl.create(commitExecutor, "CommitExecutorStats",
108 JMX_BEAN_TYPE, null);
109 if (commitExecutorStatsMXBean != null) {
110 mBeans.add(commitExecutorStatsMXBean);
113 if (commitStatsTracker != null) {
114 final CommitStatsMXBeanImpl commitStatsMXBean = new CommitStatsMXBeanImpl(
115 commitStatsTracker, JMX_BEAN_TYPE);
116 commitStatsMXBean.registerMBean();
117 mBeans.add(commitStatsMXBean);
120 final AbstractMXBean commitFutureStatsMXBean =
121 ThreadExecutorStatsMXBeanImpl.create(listenableFutureExecutor,
122 "CommitFutureExecutorStats", JMX_BEAN_TYPE, null);
123 if (commitFutureStatsMXBean != null) {
124 mBeans.add(commitFutureStatsMXBean);
127 sdb.setCloseable(() -> mBeans.forEach(AbstractMXBean::unregisterMBean));