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;
28 * @deprecated Replaced by the clustered data store.
31 public final class DomInmemoryDataBrokerModule extends
32 org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractDomInmemoryDataBrokerModule {
34 private static final String JMX_BEAN_TYPE = "DOMDataBroker";
36 public DomInmemoryDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
37 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
38 super(identifier, dependencyResolver);
41 public DomInmemoryDataBrokerModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
42 final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
43 final DomInmemoryDataBrokerModule oldModule, final java.lang.AutoCloseable oldInstance) {
45 super(identifier, dependencyResolver, oldModule, oldInstance);
49 protected void customValidation() {
50 // Add custom validation for module attributes here.
54 public java.lang.AutoCloseable createInstance() {
55 //Initializing Operational DOM DataStore defaulting to InMemoryDOMDataStore if one is not configured
56 DOMStore operStore = getOperationalDataStoreDependency();
57 if(operStore == null){
58 //we will default to InMemoryDOMDataStore creation
59 operStore = InMemoryDOMDataStoreFactory.create("DOM-OPER", getSchemaServiceDependency());
62 DOMStore configStore = getConfigDataStoreDependency();
63 if(configStore == null){
64 //we will default to InMemoryDOMDataStore creation
65 configStore = InMemoryDOMDataStoreFactory.create("DOM-CFG", getSchemaServiceDependency());
68 final Map<LogicalDatastoreType, DOMStore> datastores = new EnumMap<>(LogicalDatastoreType.class);
69 datastores.put(LogicalDatastoreType.OPERATIONAL, operStore);
70 datastores.put(LogicalDatastoreType.CONFIGURATION, configStore);
73 * We use an executor for commit ListenableFuture callbacks that favors reusing available
74 * threads over creating new threads at the expense of execution time. The assumption is
75 * that most ListenableFuture callbacks won't execute a lot of business logic where we want
76 * it to run quicker - many callbacks will likely just handle error conditions and do
77 * nothing on success. The executor queue capacity is bounded and, if the capacity is
78 * reached, subsequent submitted tasks will block the caller.
80 ExecutorService listenableFutureExecutor = SpecialExecutors.newBlockingBoundedCachedThreadPool(
81 getMaxDataBrokerFutureCallbackPoolSize(), getMaxDataBrokerFutureCallbackQueueSize(),
82 "CommitFutures", SerializedDOMDataBroker.class);
84 final List<AbstractMXBean> mBeans = Lists.newArrayList();
85 final DurationStatisticsTracker commitStatsTracker;
88 * We use a single-threaded executor for commits with a bounded queue capacity. If the
89 * queue capacity is reached, subsequent commit tasks will be rejected and the commits will
90 * fail. This is done to relieve back pressure. This should be an extreme scenario - either
91 * there's deadlock(s) somewhere and the controller is unstable or some rogue component is
92 * continuously hammering commits too fast or the controller is just over-capacity for the
93 * system it's running on.
95 ExecutorService commitExecutor = SpecialExecutors.newBoundedSingleThreadExecutor(
96 getMaxDataBrokerCommitQueueSize(), "WriteTxCommit", SerializedDOMDataBroker.class);
98 SerializedDOMDataBroker sdb = new SerializedDOMDataBroker(datastores,
99 new DeadlockDetectingListeningExecutorService(commitExecutor,
100 TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER,
101 listenableFutureExecutor));
102 commitStatsTracker = sdb.getCommitStatsTracker();
104 final AbstractMXBean commitExecutorStatsMXBean =
105 ThreadExecutorStatsMXBeanImpl.create(commitExecutor, "CommitExecutorStats",
106 JMX_BEAN_TYPE, null);
107 if(commitExecutorStatsMXBean != null) {
108 mBeans.add(commitExecutorStatsMXBean);
111 if(commitStatsTracker != null) {
112 final CommitStatsMXBeanImpl commitStatsMXBean = new CommitStatsMXBeanImpl(
113 commitStatsTracker, JMX_BEAN_TYPE);
114 commitStatsMXBean.registerMBean();
115 mBeans.add(commitStatsMXBean);
118 final AbstractMXBean commitFutureStatsMXBean =
119 ThreadExecutorStatsMXBeanImpl.create(listenableFutureExecutor,
120 "CommitFutureExecutorStats", JMX_BEAN_TYPE, null);
121 if(commitFutureStatsMXBean != null) {
122 mBeans.add(commitFutureStatsMXBean);
125 sdb.setCloseable(() -> mBeans.forEach(AbstractMXBean::unregisterMBean));