From 6098a157bd462484c311c8871507deeb3fb631f1 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 20 Sep 2014 12:07:05 +0200 Subject: [PATCH] BUG-650: remove executor abstraction This patch removes sameThreadExecutor from the commit path, eliminating associated overhead. Relevant benchmarks show improvement pretty much across the board: BEFORE millis error write100KSingleNodeWithOneInnerItemInCommitPerWriteBenchmark 2213.735 77.597 write100KSingleNodeWithOneInnerItemInOneCommitBenchmark 171.524 2.289 write10KSingleNodeWithTenInnerItemsInCommitPerWriteBenchmark 164.282 1.391 write10KSingleNodeWithTenInnerItemsInOneCommitBenchmark 14.161 0.196 write50KSingleNodeWithTwoInnerItemsInCommitPerWriteBenchmark 982.697 29.397 write50KSingleNodeWithTwoInnerItemsInOneCommitBenchmark 93.233 2.174 AFTER millis error delta write100KSingleNodeWithOneInnerItemInCommitPerWriteBenchmark 2138.900 75.844 -3.4% write100KSingleNodeWithOneInnerItemInOneCommitBenchmark 177.839 3.997 +3.5% write10KSingleNodeWithTenInnerItemsInCommitPerWriteBenchmark 158.666 1.090 -3.5% write10KSingleNodeWithTenInnerItemsInOneCommitBenchmark 13.022 0.105 -8.0% write50KSingleNodeWithTwoInnerItemsInCommitPerWriteBenchmark 935.490 30.395 -4.8% write50KSingleNodeWithTwoInnerItemsInOneCommitBenchmark 89.907 1.204 -3.6% Furthermore it cleans up and marks FIXMEs for defunct statistics. These will need to be replaced with implementation which does not assume underlying implementation. Change-Id: I01c51462a8529a2f874ecd2f9af05faba503bc58 Signed-off-by: Robert Varga --- ...MemoryBrokerWriteTransactionBenchmark.java | 6 +- ...DataStoreWithExecutorServiceBenchmark.java | 69 ----------------- ...toreWithSameThreadedExecutorBenchmark.java | 4 +- ...oryDataStoreWriteTransactionBenchmark.java | 3 +- .../mock/util/DataBrokerTestCustomizer.java | 6 +- .../test/DataBrokerTestCustomizer.java | 6 +- .../binding/test/util/BindingTestContext.java | 7 +- .../controller/cluster/datastore/Shard.java | 63 ++++++++-------- .../jmx/mbeans/shard/ShardMBeanFactory.java | 8 +- .../jmx/mbeans/shard/ShardStats.java | 42 +++++------ .../DataChangeListenerRegistrationTest.java | 13 +--- .../cluster/datastore/ShardTest.java | 5 +- .../ShardTransactionFailureTest.java | 7 +- .../datastore/ShardTransactionTest.java | 6 +- .../AbstractModificationTest.java | 7 +- .../broker/impl/DOMBrokerPerformanceTest.java | 21 ++---- .../md/sal/dom/broker/impl/DOMBrokerTest.java | 4 +- .../broker/impl/DOMTransactionChainTest.java | 19 ++--- ...InMemoryConfigDataStoreProviderModule.java | 4 +- ...oryOperationalDataStoreProviderModule.java | 3 +- .../dom/store/impl/InMemoryDOMDataStore.java | 75 ++++++++----------- .../impl/InMemoryDOMDataStoreFactory.java | 6 +- .../impl/jmx/InMemoryDataStoreStats.java | 18 ++--- .../impl/AbstractDataChangeListenerTest.java | 6 +- .../dom/store/impl/InMemoryDataStoreTest.java | 6 +- .../impl/SchemaUpdateForTransactionTest.java | 10 +-- .../mock/util/DataBrokerTestCustomizer.java | 6 +- 27 files changed, 136 insertions(+), 294 deletions(-) delete mode 100644 opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryDataStoreWithExecutorServiceBenchmark.java diff --git a/opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryBrokerWriteTransactionBenchmark.java b/opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryBrokerWriteTransactionBenchmark.java index a46a6d1e79..276f4ec2d0 100644 --- a/opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryBrokerWriteTransactionBenchmark.java +++ b/opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryBrokerWriteTransactionBenchmark.java @@ -41,10 +41,8 @@ public class InMemoryBrokerWriteTransactionBenchmark extends AbstractInMemoryBro executor = MoreExecutors.listeningDecorator( MoreExecutors.getExitingExecutorService((ThreadPoolExecutor)Executors.newFixedThreadPool(1), 1L, TimeUnit.SECONDS)); - InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", dsExec, - MoreExecutors.sameThreadExecutor()); - InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", dsExec, - MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", dsExec); + InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", dsExec); Map datastores = ImmutableMap.of( LogicalDatastoreType.OPERATIONAL, (DOMStore)operStore, LogicalDatastoreType.CONFIGURATION, configStore); diff --git a/opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryDataStoreWithExecutorServiceBenchmark.java b/opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryDataStoreWithExecutorServiceBenchmark.java deleted file mode 100644 index 77a4966ec3..0000000000 --- a/opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryDataStoreWithExecutorServiceBenchmark.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2013 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.md.sal.dom.store.benchmark; - -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.TimeUnit; -import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; -import org.opendaylight.yangtools.util.concurrent.SpecialExecutors; -import org.openjdk.jmh.annotations.BenchmarkMode; -import org.openjdk.jmh.annotations.Fork; -import org.openjdk.jmh.annotations.Level; -import org.openjdk.jmh.annotations.Mode; -import org.openjdk.jmh.annotations.OutputTimeUnit; -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.Setup; -import org.openjdk.jmh.annotations.State; -import org.openjdk.jmh.annotations.TearDown; - -/** - * Benchmark for testing of performance of write operations for InMemoryDataStore. The instance - * of benchmark creates InMemoryDataStore with Data Change Listener Executor Service as BlockingBoundedFastThreadPool - * and DOM Store Executor Service as Blocking Bounded Fast Thread Pool. - * - * @see org.opendaylight.yangtools.util.concurrent.SpecialExecutors - * @see org.opendaylight.controller.md.sal.dom.store.benchmark.AbstractInMemoryDatastoreWriteTransactionBenchmark - * - * @author Lukas Sedlak - */ -@State(Scope.Thread) -@BenchmarkMode(Mode.AverageTime) -@OutputTimeUnit(TimeUnit.MILLISECONDS) -@Fork(1) -public class InMemoryDataStoreWithExecutorServiceBenchmark extends AbstractInMemoryDatastoreWriteTransactionBenchmark { - - private static final int MAX_DATA_CHANGE_EXECUTOR_POOL_SIZE = 20; - private static final int MAX_DATA_CHANGE_EXECUTOR_QUEUE_SIZE = 1000; - private static final int MAX_DATA_STORE_EXECUTOR_QUEUE_SIZE = 5000; - - @Override - @Setup(Level.Trial) - public void setUp() throws Exception { - final String name = "DS_BENCHMARK"; - final ExecutorService dataChangeListenerExecutor = SpecialExecutors.newBlockingBoundedFastThreadPool( - MAX_DATA_CHANGE_EXECUTOR_POOL_SIZE, MAX_DATA_CHANGE_EXECUTOR_QUEUE_SIZE, name + "-DCL"); - - final ListeningExecutorService domStoreExecutor = MoreExecutors.listeningDecorator(SpecialExecutors.newBoundedSingleThreadExecutor( - MAX_DATA_STORE_EXECUTOR_QUEUE_SIZE, "DOMStore-" + name )); - - domStore = new InMemoryDOMDataStore(name, domStoreExecutor, - dataChangeListenerExecutor); - schemaContext = BenchmarkModel.createTestContext(); - domStore.onGlobalContextUpdated(schemaContext); - initTestNode(); - } - - @Override - @TearDown - public void tearDown() { - schemaContext = null; - domStore = null; - } -} diff --git a/opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryDataStoreWithSameThreadedExecutorBenchmark.java b/opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryDataStoreWithSameThreadedExecutorBenchmark.java index 6a0ceccd53..1aa19b2fe7 100644 --- a/opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryDataStoreWithSameThreadedExecutorBenchmark.java +++ b/opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryDataStoreWithSameThreadedExecutorBenchmark.java @@ -7,7 +7,6 @@ */ package org.opendaylight.controller.md.sal.dom.store.benchmark; -import com.google.common.util.concurrent.MoreExecutors; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; @@ -44,8 +43,7 @@ public class InMemoryDataStoreWithSameThreadedExecutorBenchmark extends Abstract final ExecutorService dataChangeListenerExecutor = SpecialExecutors.newBlockingBoundedFastThreadPool( MAX_DATA_CHANGE_EXECUTOR_POOL_SIZE, MAX_DATA_CHANGE_EXECUTOR_QUEUE_SIZE, name + "-DCL"); - domStore = new InMemoryDOMDataStore("SINGLE_THREADED_DS_BENCHMARK", MoreExecutors.sameThreadExecutor(), - dataChangeListenerExecutor); + domStore = new InMemoryDOMDataStore("SINGLE_THREADED_DS_BENCHMARK", dataChangeListenerExecutor); schemaContext = BenchmarkModel.createTestContext(); domStore.onGlobalContextUpdated(schemaContext); initTestNode(); diff --git a/opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryDataStoreWriteTransactionBenchmark.java b/opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryDataStoreWriteTransactionBenchmark.java index d3dda96af5..d697f3ca98 100644 --- a/opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryDataStoreWriteTransactionBenchmark.java +++ b/opendaylight/md-sal/benchmark-data-store/src/main/java/org/opendaylight/controller/md/sal/dom/store/benchmark/InMemoryDataStoreWriteTransactionBenchmark.java @@ -35,8 +35,7 @@ public class InMemoryDataStoreWriteTransactionBenchmark extends AbstractInMemory @Setup(Level.Trial) public void setUp() throws Exception { - domStore = new InMemoryDOMDataStore("SINGLE_THREADED_DS_BENCHMARK", MoreExecutors.sameThreadExecutor(), - MoreExecutors.sameThreadExecutor()); + domStore = new InMemoryDOMDataStore("SINGLE_THREADED_DS_BENCHMARK", MoreExecutors.sameThreadExecutor()); schemaContext = BenchmarkModel.createTestContext(); domStore.onGlobalContextUpdated(schemaContext); initTestNode(); diff --git a/opendaylight/md-sal/forwardingrules-manager/src/test/java/test/mock/util/DataBrokerTestCustomizer.java b/opendaylight/md-sal/forwardingrules-manager/src/test/java/test/mock/util/DataBrokerTestCustomizer.java index 36ab41fa68..30704997f3 100644 --- a/opendaylight/md-sal/forwardingrules-manager/src/test/java/test/mock/util/DataBrokerTestCustomizer.java +++ b/opendaylight/md-sal/forwardingrules-manager/src/test/java/test/mock/util/DataBrokerTestCustomizer.java @@ -56,15 +56,13 @@ public class DataBrokerTestCustomizer { } public DOMStore createConfigurationDatastore() { - InMemoryDOMDataStore store = new InMemoryDOMDataStore("CFG", - MoreExecutors.sameThreadExecutor(), MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore store = new InMemoryDOMDataStore("CFG", MoreExecutors.sameThreadExecutor()); schemaService.registerSchemaContextListener(store); return store; } public DOMStore createOperationalDatastore() { - InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", - MoreExecutors.sameThreadExecutor(), MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", MoreExecutors.sameThreadExecutor()); schemaService.registerSchemaContextListener(store); return store; } diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/DataBrokerTestCustomizer.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/DataBrokerTestCustomizer.java index c869b1dbd3..d99ac6f2f0 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/DataBrokerTestCustomizer.java +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/DataBrokerTestCustomizer.java @@ -56,15 +56,13 @@ public class DataBrokerTestCustomizer { } public DOMStore createConfigurationDatastore() { - InMemoryDOMDataStore store = new InMemoryDOMDataStore("CFG", - MoreExecutors.sameThreadExecutor(), MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore store = new InMemoryDOMDataStore("CFG", MoreExecutors.sameThreadExecutor()); schemaService.registerSchemaContextListener(store); return store; } public DOMStore createOperationalDatastore() { - InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", - MoreExecutors.sameThreadExecutor(), MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", MoreExecutors.sameThreadExecutor()); schemaService.registerSchemaContextListener(store); return store; } diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java index d0a326adff..7d1b65f628 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/sal/binding/test/util/BindingTestContext.java @@ -8,7 +8,6 @@ package org.opendaylight.controller.sal.binding.test.util; import static com.google.common.base.Preconditions.checkState; - import com.google.common.annotations.Beta; import com.google.common.collect.ClassToInstanceMap; import com.google.common.collect.ImmutableClassToInstanceMap; @@ -138,10 +137,8 @@ public class BindingTestContext implements AutoCloseable { public void startNewDomDataBroker() { checkState(executor != null, "Executor needs to be set"); - InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", executor, - MoreExecutors.sameThreadExecutor()); - InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", executor, - MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.sameThreadExecutor()); newDatastores = ImmutableMap.builder() .put(LogicalDatastoreType.OPERATIONAL, operStore) .put(LogicalDatastoreType.CONFIGURATION, configStore) diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java index 4b130950f2..d53cb48e50 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/Shard.java @@ -139,8 +139,8 @@ public class Shard extends RaftActor { private final Map transactionChains = new HashMap<>(); - protected Shard(ShardIdentifier name, Map peerAddresses, - DatastoreContext datastoreContext, SchemaContext schemaContext) { + protected Shard(final ShardIdentifier name, final Map peerAddresses, + final DatastoreContext datastoreContext, final SchemaContext schemaContext) { super(name.toString(), mapPeerAddresses(peerAddresses), Optional.of(datastoreContext.getShardRaftConfig())); @@ -160,7 +160,6 @@ public class Shard extends RaftActor { shardMBean = ShardMBeanFactory.getShardStatsMBean(name.toString(), datastoreContext.getDataStoreMXBeanType()); - shardMBean.setDataStoreExecutor(store.getDomStoreExecutor()); shardMBean.setNotificationManager(store.getDataChangeListenerNotificationManager()); if (isMetricsCaptureEnabled()) { @@ -175,7 +174,7 @@ public class Shard extends RaftActor { } private static Map mapPeerAddresses( - Map peerAddresses) { + final Map peerAddresses) { Map map = new HashMap<>(); for (Map.Entry entry : peerAddresses @@ -188,7 +187,7 @@ public class Shard extends RaftActor { public static Props props(final ShardIdentifier name, final Map peerAddresses, - DatastoreContext datastoreContext, SchemaContext schemaContext) { + final DatastoreContext datastoreContext, final SchemaContext schemaContext) { Preconditions.checkNotNull(name, "name should not be null"); Preconditions.checkNotNull(peerAddresses, "peerAddresses should not be null"); Preconditions.checkNotNull(datastoreContext, "dataStoreContext should not be null"); @@ -207,7 +206,7 @@ public class Shard extends RaftActor { } @Override - public void onReceiveRecover(Object message) throws Exception { + public void onReceiveRecover(final Object message) throws Exception { if(LOG.isDebugEnabled()) { LOG.debug("onReceiveRecover: Received message {} from {}", message.getClass().toString(), @@ -226,7 +225,7 @@ public class Shard extends RaftActor { } @Override - public void onReceiveCommand(Object message) throws Exception { + public void onReceiveCommand(final Object message) throws Exception { if(LOG.isDebugEnabled()) { LOG.debug("onReceiveCommand: Received message {} from {}", message, getSender()); } @@ -273,7 +272,7 @@ public class Shard extends RaftActor { } } - private void handleCommitTransaction(CommitTransaction commit) { + private void handleCommitTransaction(final CommitTransaction commit) { final String transactionID = commit.getTransactionID(); LOG.debug("Committing transaction {}", transactionID); @@ -368,7 +367,7 @@ public class Shard extends RaftActor { commitCoordinator.currentTransactionComplete(transactionID, true); } - private void handleCanCommitTransaction(CanCommitTransaction canCommit) { + private void handleCanCommitTransaction(final CanCommitTransaction canCommit) { LOG.debug("Can committing transaction {}", canCommit.getTransactionID()); commitCoordinator.handleCanCommit(canCommit, getSender(), self()); } @@ -401,11 +400,11 @@ public class Shard extends RaftActor { readyTransactionReply, getSelf()); } - private void handleAbortTransaction(AbortTransaction abort) { + private void handleAbortTransaction(final AbortTransaction abort) { doAbortTransaction(abort.getTransactionID(), getSender()); } - private void doAbortTransaction(String transactionID, final ActorRef sender) { + private void doAbortTransaction(final String transactionID, final ActorRef sender) { final CohortEntry cohortEntry = commitCoordinator.getCohortEntryIfCurrent(transactionID); if(cohortEntry != null) { LOG.debug("Aborting transaction {}", transactionID); @@ -420,7 +419,7 @@ public class Shard extends RaftActor { Futures.addCallback(future, new FutureCallback() { @Override - public void onSuccess(Void v) { + public void onSuccess(final Void v) { shardMBean.incrementAbortTransactionsCount(); if(sender != null) { @@ -429,7 +428,7 @@ public class Shard extends RaftActor { } @Override - public void onFailure(Throwable t) { + public void onFailure(final Throwable t) { LOG.error(t, "An exception happened during abort"); if(sender != null) { @@ -440,7 +439,7 @@ public class Shard extends RaftActor { } } - private void handleCreateTransaction(Object message) { + private void handleCreateTransaction(final Object message) { if (isLeader()) { createTransaction(CreateTransaction.fromSerializable(message)); } else if (getLeader() != null) { @@ -453,7 +452,7 @@ public class Shard extends RaftActor { } } - private void handleReadDataReply(Object message) { + private void handleReadDataReply(final Object message) { // This must be for install snapshot. Don't want to open this up and trigger // deSerialization @@ -467,7 +466,7 @@ public class Shard extends RaftActor { getSender().tell(PoisonPill.getInstance(), self()); } - private void closeTransactionChain(CloseTransactionChain closeTransactionChain) { + private void closeTransactionChain(final CloseTransactionChain closeTransactionChain) { DOMStoreTransactionChain chain = transactionChains.remove(closeTransactionChain.getTransactionChainId()); @@ -562,14 +561,14 @@ public class Shard extends RaftActor { return transactionActor; } - private void syncCommitTransaction(DOMStoreWriteTransaction transaction) + private void syncCommitTransaction(final DOMStoreWriteTransaction transaction) throws ExecutionException, InterruptedException { DOMStoreThreePhaseCommitCohort commitCohort = transaction.ready(); commitCohort.preCommit().get(); commitCohort.commit().get(); } - private void commitWithNewTransaction(Modification modification) { + private void commitWithNewTransaction(final Modification modification) { DOMStoreWriteTransaction tx = store.newWriteOnlyTransaction(); modification.apply(tx); try { @@ -582,18 +581,18 @@ public class Shard extends RaftActor { } } - private void updateSchemaContext(UpdateSchemaContext message) { + private void updateSchemaContext(final UpdateSchemaContext message) { this.schemaContext = message.getSchemaContext(); updateSchemaContext(message.getSchemaContext()); store.onGlobalContextUpdated(message.getSchemaContext()); } @VisibleForTesting - void updateSchemaContext(SchemaContext schemaContext) { + void updateSchemaContext(final SchemaContext schemaContext) { store.onGlobalContextUpdated(schemaContext); } - private void registerChangeListener(RegisterChangeListener registerChangeListener) { + private void registerChangeListener(final RegisterChangeListener registerChangeListener) { LOG.debug("registerDataChangeListener for {}", registerChangeListener.getPath()); @@ -621,7 +620,7 @@ public class Shard extends RaftActor { private ListenerRegistration>> doChangeListenerRegistration( - RegisterChangeListener registerChangeListener) { + final RegisterChangeListener registerChangeListener) { ActorSelection dataChangeListenerPath = getContext().system().actorSelection( registerChangeListener.getDataChangeListenerPath()); @@ -651,7 +650,7 @@ public class Shard extends RaftActor { @Override protected - void startLogRecoveryBatch(int maxBatchSize) { + void startLogRecoveryBatch(final int maxBatchSize) { currentLogRecoveryBatch = Lists.newArrayListWithCapacity(maxBatchSize); if(LOG.isDebugEnabled()) { @@ -660,7 +659,7 @@ public class Shard extends RaftActor { } @Override - protected void appendRecoveredLogEntry(Payload data) { + protected void appendRecoveredLogEntry(final Payload data) { if (data instanceof CompositeModificationPayload) { currentLogRecoveryBatch.add(((CompositeModificationPayload) data).getModification()); } else { @@ -669,7 +668,7 @@ public class Shard extends RaftActor { } @Override - protected void applyRecoverySnapshot(ByteString snapshot) { + protected void applyRecoverySnapshot(final ByteString snapshot) { if(recoveryCoordinator == null) { recoveryCoordinator = new ShardRecoveryCoordinator(persistenceId(), schemaContext); } @@ -734,7 +733,7 @@ public class Shard extends RaftActor { } @Override - protected void applyState(ActorRef clientActor, String identifier, Object data) { + protected void applyState(final ActorRef clientActor, final String identifier, final Object data) { if (data instanceof CompositeModificationPayload) { Object modification = ((CompositeModificationPayload) data).getModification(); @@ -793,7 +792,7 @@ public class Shard extends RaftActor { @VisibleForTesting @Override - protected void applySnapshot(ByteString snapshot) { + protected void applySnapshot(final ByteString snapshot) { // Since this will be done only on Recovery or when this actor is a Follower // we can safely commit everything in here. We not need to worry about event notifications // as they would have already been disabled on the follower @@ -858,7 +857,7 @@ public class Shard extends RaftActor { return dataPersistenceProvider; } - @Override protected void onLeaderChanged(String oldLeader, String newLeader) { + @Override protected void onLeaderChanged(final String oldLeader, final String newLeader) { shardMBean.setLeader(newLeader); } @@ -880,8 +879,8 @@ public class Shard extends RaftActor { final DatastoreContext datastoreContext; final SchemaContext schemaContext; - ShardCreator(ShardIdentifier name, Map peerAddresses, - DatastoreContext datastoreContext, SchemaContext schemaContext) { + ShardCreator(final ShardIdentifier name, final Map peerAddresses, + final DatastoreContext datastoreContext, final SchemaContext schemaContext) { this.name = name; this.peerAddresses = peerAddresses; this.datastoreContext = datastoreContext; @@ -914,11 +913,11 @@ public class Shard extends RaftActor { private volatile ListenerRegistration>> delegate; - DelayedListenerRegistration(RegisterChangeListener registerChangeListener) { + DelayedListenerRegistration(final RegisterChangeListener registerChangeListener) { this.registerChangeListener = registerChangeListener; } - void setDelegate( ListenerRegistration>> registration) { this.delegate = registration; } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardMBeanFactory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardMBeanFactory.java index 946e525a6d..4a7752aec1 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardMBeanFactory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardMBeanFactory.java @@ -7,15 +7,13 @@ */ package org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; - /** * @author Basheeruddin syedbahm@cisco.com * @@ -24,7 +22,7 @@ public class ShardMBeanFactory { private static final Logger LOG = LoggerFactory.getLogger(ShardMBeanFactory.class); - private static Cache shardMBeansCache = + private static final Cache shardMBeansCache = CacheBuilder.newBuilder().weakValues().build(); public static ShardStats getShardStatsMBean(final String shardName, final String mxBeanType) { diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardStats.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardStats.java index 0959c2a959..9decd82822 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardStats.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/shard/ShardStats.java @@ -8,20 +8,18 @@ package org.opendaylight.controller.cluster.datastore.jmx.mbeans.shard; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; -import java.util.concurrent.ExecutorService; import java.util.concurrent.atomic.AtomicLong; - import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean; import org.opendaylight.controller.md.sal.common.util.jmx.QueuedNotificationManagerMXBeanImpl; import org.opendaylight.controller.md.sal.common.util.jmx.ThreadExecutorStats; import org.opendaylight.controller.md.sal.common.util.jmx.ThreadExecutorStatsMXBeanImpl; +import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; import org.opendaylight.yangtools.util.concurrent.ListenerNotificationQueueStats; import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager; -import java.text.SimpleDateFormat; -import java.util.Date; - /** * Maintains statistics for a shard. * @@ -62,22 +60,16 @@ public class ShardStats extends AbstractMXBean implements ShardStatsMXBean { private ThreadExecutorStatsMXBeanImpl notificationExecutorStatsBean; - private ThreadExecutorStatsMXBeanImpl dataStoreExecutorStatsBean; - private QueuedNotificationManagerMXBeanImpl notificationManagerStatsBean; private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); - public ShardStats(String shardName, String mxBeanType) { + public ShardStats(final String shardName, final String mxBeanType) { super(shardName, mxBeanType, JMX_CATEGORY_SHARD); } - public void setDataStoreExecutor(ExecutorService dsExecutor) { - this.dataStoreExecutorStatsBean = ThreadExecutorStatsMXBeanImpl.create(dsExecutor); - } - - public void setNotificationManager(QueuedNotificationManager manager) { + public void setNotificationManager(final QueuedNotificationManager manager) { this.notificationManagerStatsBean = new QueuedNotificationManagerMXBeanImpl(manager, "notification-manager", getMBeanType(), getMBeanCategory()); @@ -194,42 +186,42 @@ public class ShardStats extends AbstractMXBean implements ShardStatsMXBean { return abortTransactionsCount.incrementAndGet(); } - public void setLeader(String leader) { + public void setLeader(final String leader) { this.leader = leader; } - public void setRaftState(String raftState) { + public void setRaftState(final String raftState) { this.raftState = raftState; } - public void setLastLogTerm(long lastLogTerm) { + public void setLastLogTerm(final long lastLogTerm) { this.lastLogTerm = lastLogTerm; } - public void setLastLogIndex(long lastLogIndex) { + public void setLastLogIndex(final long lastLogIndex) { this.lastLogIndex = lastLogIndex; } - public void setCurrentTerm(long currentTerm) { + public void setCurrentTerm(final long currentTerm) { this.currentTerm = currentTerm; } - public void setCommitIndex(long commitIndex) { + public void setCommitIndex(final long commitIndex) { this.commitIndex = commitIndex; } - public void setLastApplied(long lastApplied) { + public void setLastApplied(final long lastApplied) { this.lastApplied = lastApplied; } - public void setLastCommittedTransactionTime(long lastCommittedTransactionTime) { + public void setLastCommittedTransactionTime(final long lastCommittedTransactionTime) { this.lastCommittedTransactionTime = lastCommittedTransactionTime; } @Override public ThreadExecutorStats getDataStoreExecutorStats() { - return dataStoreExecutorStatsBean == null ? null : - dataStoreExecutorStatsBean.toThreadExecutorStats(); + // FIXME: this particular thing does not work, as it really is DS-specific + return null; } @Override @@ -269,4 +261,8 @@ public class ShardStats extends AbstractMXBean implements ShardStatsMXBean { abortTransactionsCount.set(0); } + + public void setDataStore(final InMemoryDOMDataStore store) { + setNotificationManager(store.getDataChangeListenerNotificationManager()); + } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationTest.java index eb2c24292a..bf994eb5b6 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DataChangeListenerRegistrationTest.java @@ -1,9 +1,9 @@ package org.opendaylight.controller.cluster.datastore; +import static org.junit.Assert.assertEquals; import akka.actor.ActorRef; import akka.actor.Props; import akka.testkit.JavaTestKit; -import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import org.junit.Test; import org.opendaylight.controller.cluster.datastore.messages.CloseDataChangeListenerRegistration; @@ -16,13 +16,8 @@ import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; -import static org.junit.Assert.assertEquals; - public class DataChangeListenerRegistrationTest extends AbstractActorTest { - private static ListeningExecutorService storeExecutor = MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor()); - - private static final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", storeExecutor, - MoreExecutors.sameThreadExecutor()); + private static final InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", MoreExecutors.sameThreadExecutor()); static { store.onGlobalContextUpdated(TestModel.createTestContext()); @@ -46,7 +41,7 @@ public class DataChangeListenerRegistrationTest extends AbstractActorTest { final String out = new ExpectMsg(duration("1 seconds"), "match hint") { // do not put code outside this method, will run afterwards @Override - protected String match(Object in) { + protected String match(final Object in) { if (in.getClass().equals(CloseDataChangeListenerRegistrationReply.SERIALIZABLE_CLASS)) { return "match"; } else { @@ -68,7 +63,7 @@ public class DataChangeListenerRegistrationTest extends AbstractActorTest { private AsyncDataChangeListener> noOpDataChangeListener(){ return new AsyncDataChangeListener>() { @Override - public void onDataChanged(AsyncDataChangeEvent> change) { + public void onDataChanged(final AsyncDataChangeEvent> change) { } }; diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java index e5b5643297..926cef6ba5 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTest.java @@ -101,7 +101,6 @@ import scala.concurrent.Await; import scala.concurrent.Future; import scala.concurrent.duration.FiniteDuration; - public class ShardTest extends AbstractActorTest { private static final SchemaContext SCHEMA_CONTEXT = TestModel.createTestContext(); @@ -1264,8 +1263,7 @@ public class ShardTest extends AbstractActorTest { */ @Test public void testInMemoryDataStoreRestore() throws ReadFailedException { - InMemoryDOMDataStore store = new InMemoryDOMDataStore("test", MoreExecutors.listeningDecorator( - MoreExecutors.sameThreadExecutor()), MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore store = new InMemoryDOMDataStore("test", MoreExecutors.sameThreadExecutor()); store.onGlobalContextUpdated(SCHEMA_CONTEXT); @@ -1287,7 +1285,6 @@ public class ShardTest extends AbstractActorTest { NormalizedNode actual = readStore(store); assertEquals(expected, actual); - } @Test diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java index 5781c19b25..9f57359429 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionFailureTest.java @@ -14,7 +14,6 @@ import akka.actor.ActorRef; import akka.actor.Props; import akka.pattern.AskTimeoutException; import akka.testkit.TestActorRef; -import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import java.util.Collections; import java.util.concurrent.TimeUnit; @@ -42,12 +41,8 @@ import scala.concurrent.duration.Duration; * @author Basheeruddin Ahmed */ public class ShardTransactionFailureTest extends AbstractActorTest { - private static ListeningExecutorService storeExecutor = - MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor()); - private static final InMemoryDOMDataStore store = - new InMemoryDOMDataStore("OPER", storeExecutor, - MoreExecutors.sameThreadExecutor()); + new InMemoryDOMDataStore("OPER", MoreExecutors.sameThreadExecutor()); private static final SchemaContext testSchemaContext = TestModel.createTestContext(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java index 4ccc9430ac..2d9d05ba15 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/ShardTransactionTest.java @@ -9,7 +9,6 @@ import akka.actor.Props; import akka.actor.Terminated; import akka.testkit.JavaTestKit; import akka.testkit.TestActorRef; -import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import java.util.Collections; import java.util.concurrent.TimeUnit; @@ -48,11 +47,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; import scala.concurrent.duration.Duration; public class ShardTransactionTest extends AbstractActorTest { - private static ListeningExecutorService storeExecutor = - MoreExecutors.listeningDecorator(MoreExecutors.sameThreadExecutor()); - private static final InMemoryDOMDataStore store = - new InMemoryDOMDataStore("OPER", storeExecutor, MoreExecutors.sameThreadExecutor()); + new InMemoryDOMDataStore("OPER", MoreExecutors.sameThreadExecutor()); private static final SchemaContext testSchemaContext = TestModel.createTestContext(); diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/AbstractModificationTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/AbstractModificationTest.java index 84f3b92f1b..abb2d31df3 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/AbstractModificationTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/modification/AbstractModificationTest.java @@ -26,18 +26,17 @@ public abstract class AbstractModificationTest { @Before public void setUp(){ - store = new InMemoryDOMDataStore("test", MoreExecutors.sameThreadExecutor(), - MoreExecutors.sameThreadExecutor()); + store = new InMemoryDOMDataStore("test", MoreExecutors.sameThreadExecutor()); store.onGlobalContextUpdated(TestModel.createTestContext()); } - protected void commitTransaction(DOMStoreWriteTransaction transaction){ + protected void commitTransaction(final DOMStoreWriteTransaction transaction){ DOMStoreThreePhaseCommitCohort cohort = transaction.ready(); cohort.preCommit(); cohort.commit(); } - protected Optional> readData(YangInstanceIdentifier path) throws Exception{ + protected Optional> readData(final YangInstanceIdentifier path) throws Exception{ DOMStoreReadTransaction transaction = store.newReadOnlyTransaction(); ListenableFuture>> future = transaction.read(path); return future.get(); diff --git a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerPerformanceTest.java b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerPerformanceTest.java index e9ed5b1b30..eb51db2398 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerPerformanceTest.java +++ b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerPerformanceTest.java @@ -4,12 +4,16 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION; import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL; - +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableMap; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.Executors; - import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; @@ -25,13 +29,6 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableMap; -import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; - public class DOMBrokerPerformanceTest { private static final Logger log = LoggerFactory.getLogger(DOMBrokerPerformanceTest.class); @@ -63,10 +60,8 @@ public class DOMBrokerPerformanceTest { @Before public void setupStore() { - InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", - MoreExecutors.sameThreadExecutor(), MoreExecutors.sameThreadExecutor()); - InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", - MoreExecutors.sameThreadExecutor(), MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.sameThreadExecutor()); schemaContext = TestModel.createTestContext(); operStore.onGlobalContextUpdated(schemaContext); diff --git a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerTest.java b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerTest.java index 674d2ff44a..80c4201033 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerTest.java +++ b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMBrokerTest.java @@ -57,9 +57,9 @@ public class DOMBrokerTest { public void setupStore() { InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", - MoreExecutors.sameThreadExecutor(), MoreExecutors.sameThreadExecutor()); + MoreExecutors.sameThreadExecutor()); InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", - MoreExecutors.sameThreadExecutor(), MoreExecutors.sameThreadExecutor()); + MoreExecutors.sameThreadExecutor()); schemaContext = TestModel.createTestContext(); operStore.onGlobalContextUpdated(schemaContext); diff --git a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMTransactionChainTest.java b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMTransactionChainTest.java index 18b11c8300..17f477bb0f 100644 --- a/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMTransactionChainTest.java +++ b/opendaylight/md-sal/sal-dom-broker/src/test/java/org/opendaylight/controller/md/sal/dom/broker/impl/DOMTransactionChainTest.java @@ -12,12 +12,15 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION; import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL; - +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableMap; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; - import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; @@ -31,12 +34,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import com.google.common.base.Optional; -import com.google.common.collect.ImmutableMap; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; - public class DOMTransactionChainTest { private SchemaContext schemaContext; @@ -44,10 +41,8 @@ public class DOMTransactionChainTest { @Before public void setupStore() { - InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", - MoreExecutors.sameThreadExecutor(), MoreExecutors.sameThreadExecutor()); - InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", - MoreExecutors.sameThreadExecutor(), MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore operStore = new InMemoryDOMDataStore("OPER", MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.sameThreadExecutor()); schemaContext = TestModel.createTestContext(); operStore.onGlobalContextUpdated(schemaContext); diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/config/yang/inmemory_datastore_provider/InMemoryConfigDataStoreProviderModule.java b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/config/yang/inmemory_datastore_provider/InMemoryConfigDataStoreProviderModule.java index 1ab12ff26f..3f26266fef 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/config/yang/inmemory_datastore_provider/InMemoryConfigDataStoreProviderModule.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/config/yang/inmemory_datastore_provider/InMemoryConfigDataStoreProviderModule.java @@ -28,9 +28,7 @@ public class InMemoryConfigDataStoreProviderModule extends org.opendaylight.cont getMaxDataChangeExecutorQueueSize(), getMaxDataChangeListenerQueueSize(), getMaxDataStoreExecutorQueueSize())); - InMemoryDataStoreStats statsBean = new InMemoryDataStoreStats("InMemoryConfigDataStore", - dataStore.getDataChangeListenerNotificationManager(), dataStore.getDomStoreExecutor()); - + InMemoryDataStoreStats statsBean = new InMemoryDataStoreStats("InMemoryConfigDataStore", dataStore); dataStore.setCloseable(statsBean); return dataStore; diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/config/yang/inmemory_datastore_provider/InMemoryOperationalDataStoreProviderModule.java b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/config/yang/inmemory_datastore_provider/InMemoryOperationalDataStoreProviderModule.java index 9358552579..c91c53aba4 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/config/yang/inmemory_datastore_provider/InMemoryOperationalDataStoreProviderModule.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/config/yang/inmemory_datastore_provider/InMemoryOperationalDataStoreProviderModule.java @@ -28,8 +28,7 @@ public class InMemoryOperationalDataStoreProviderModule extends org.opendaylight getMaxDataStoreExecutorQueueSize())); - InMemoryDataStoreStats statsBean = new InMemoryDataStoreStats("InMemoryOperationalDataStore", - dataStore.getDataChangeListenerNotificationManager(), dataStore.getDomStoreExecutor()); + InMemoryDataStoreStats statsBean = new InMemoryDataStoreStats("InMemoryOperationalDataStore", dataStore); dataStore.setCloseable(statsBean); diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java index 213f60e951..4e01fa98e4 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStore.java @@ -12,8 +12,6 @@ import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.ListeningExecutorService; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; @@ -61,6 +59,7 @@ import org.slf4j.LoggerFactory; public class InMemoryDOMDataStore extends TransactionReadyPrototype implements DOMStore, Identifiable, SchemaContextListener, AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(InMemoryDOMDataStore.class); private static final ListenableFuture SUCCESSFUL_FUTURE = Futures.immediateFuture(null); + private static final ListenableFuture CAN_COMMIT_FUTURE = Futures.immediateFuture(Boolean.TRUE); private static final Invoker, DOMImmutableDataChangeEvent> DCL_NOTIFICATION_MGR_INVOKER = new Invoker, DOMImmutableDataChangeEvent>() { @@ -80,23 +79,18 @@ public class InMemoryDOMDataStore extends TransactionReadyPrototype implements D private final QueuedNotificationManager, DOMImmutableDataChangeEvent> dataChangeListenerNotificationManager; private final ExecutorService dataChangeListenerExecutor; - private final ListeningExecutorService commitExecutor; private final boolean debugTransactions; private final String name; private volatile AutoCloseable closeable; - public InMemoryDOMDataStore(final String name, final ListeningExecutorService commitExecutor, - final ExecutorService dataChangeListenerExecutor) { - this(name, commitExecutor, dataChangeListenerExecutor, - InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_LISTENER_QUEUE_SIZE, false); + public InMemoryDOMDataStore(final String name, final ExecutorService dataChangeListenerExecutor) { + this(name, dataChangeListenerExecutor, InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_LISTENER_QUEUE_SIZE, false); } - public InMemoryDOMDataStore(final String name, final ListeningExecutorService commitExecutor, - final ExecutorService dataChangeListenerExecutor, final int maxDataChangeListenerQueueSize, - final boolean debugTransactions) { + public InMemoryDOMDataStore(final String name, final ExecutorService dataChangeListenerExecutor, + final int maxDataChangeListenerQueueSize, final boolean debugTransactions) { this.name = Preconditions.checkNotNull(name); - this.commitExecutor = Preconditions.checkNotNull(commitExecutor); this.dataChangeListenerExecutor = Preconditions.checkNotNull(dataChangeListenerExecutor); this.debugTransactions = debugTransactions; @@ -114,10 +108,6 @@ public class InMemoryDOMDataStore extends TransactionReadyPrototype implements D return dataChangeListenerNotificationManager; } - public ExecutorService getDomStoreExecutor() { - return commitExecutor; - } - @Override public final String getIdentifier() { return name; @@ -150,7 +140,6 @@ public class InMemoryDOMDataStore extends TransactionReadyPrototype implements D @Override public void close() { - ExecutorServiceUtil.tryGracefulShutdown(commitExecutor, 30, TimeUnit.SECONDS); ExecutorServiceUtil.tryGracefulShutdown(dataChangeListenerExecutor, 30, TimeUnit.SECONDS); if(closeable != null) { @@ -239,38 +228,36 @@ public class InMemoryDOMDataStore extends TransactionReadyPrototype implements D @Override public ListenableFuture canCommit() { - return commitExecutor.submit(new Callable() { - @Override - public Boolean call() throws TransactionCommitFailedException { - try { - dataTree.validate(modification); - LOG.debug("Store Transaction: {} can be committed", transaction.getIdentifier()); - return true; - } catch (ConflictingModificationAppliedException e) { - LOG.warn("Store Tx: {} Conflicting modification for {}.", transaction.getIdentifier(), - e.getPath()); - transaction.warnDebugContext(LOG); - throw new OptimisticLockFailedException("Optimistic lock failed.",e); - } catch (DataValidationFailedException e) { - LOG.warn("Store Tx: {} Data Precondition failed for {}.", transaction.getIdentifier(), - e.getPath(), e); - transaction.warnDebugContext(LOG); - throw new TransactionCommitFailedException("Data did not pass validation.",e); - } - } - }); + try { + dataTree.validate(modification); + LOG.debug("Store Transaction: {} can be committed", transaction.getIdentifier()); + return CAN_COMMIT_FUTURE; + } catch (ConflictingModificationAppliedException e) { + LOG.warn("Store Tx: {} Conflicting modification for {}.", transaction.getIdentifier(), + e.getPath()); + transaction.warnDebugContext(LOG); + return Futures.immediateFailedFuture(new OptimisticLockFailedException("Optimistic lock failed.", e)); + } catch (DataValidationFailedException e) { + LOG.warn("Store Tx: {} Data Precondition failed for {}.", transaction.getIdentifier(), + e.getPath(), e); + transaction.warnDebugContext(LOG); + return Futures.immediateFailedFuture(new TransactionCommitFailedException("Data did not pass validation.", e)); + } catch (Exception e) { + LOG.warn("Unexpected failure in validation phase", e); + return Futures.immediateFailedFuture(e); + } } @Override public ListenableFuture preCommit() { - return commitExecutor.submit(new Callable() { - @Override - public Void call() { - candidate = dataTree.prepare(modification); - listenerResolver = ResolveDataChangeEventsTask.create(candidate, listenerTree); - return null; - } - }); + try { + candidate = dataTree.prepare(modification); + listenerResolver = ResolveDataChangeEventsTask.create(candidate, listenerTree); + return SUCCESSFUL_FUTURE; + } catch (Exception e) { + LOG.warn("Unexpected failure in pre-commit phase", e); + return Futures.immediateFailedFuture(e); + } } @Override diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStoreFactory.java b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStoreFactory.java index 2ee8e182c2..00af3dfdd7 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStoreFactory.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDOMDataStoreFactory.java @@ -7,8 +7,6 @@ */ package org.opendaylight.controller.md.sal.dom.store.impl; -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; import java.util.concurrent.ExecutorService; import javax.annotation.Nullable; import org.opendaylight.controller.sal.core.api.model.SchemaService; @@ -73,9 +71,7 @@ public final class InMemoryDOMDataStoreFactory { ExecutorService dataChangeListenerExecutor = SpecialExecutors.newBlockingBoundedFastThreadPool( dclExecutorMaxPoolSize, dclExecutorMaxQueueSize, name + "-DCL" ); - final ListeningExecutorService commitExecutor = MoreExecutors.sameThreadExecutor(); - final InMemoryDOMDataStore dataStore = new InMemoryDOMDataStore(name, - commitExecutor, dataChangeListenerExecutor, + final InMemoryDOMDataStore dataStore = new InMemoryDOMDataStore(name, dataChangeListenerExecutor, actualProperties.getMaxDataChangeListenerQueueSize(), debugTransactions); if (schemaService != null) { diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/jmx/InMemoryDataStoreStats.java b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/jmx/InMemoryDataStoreStats.java index e00be2446a..cb91b4c81a 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/jmx/InMemoryDataStoreStats.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/main/java/org/opendaylight/controller/md/sal/dom/store/impl/jmx/InMemoryDataStoreStats.java @@ -8,10 +8,10 @@ package org.opendaylight.controller.md.sal.dom.store.impl.jmx; -import java.util.concurrent.ExecutorService; import org.opendaylight.controller.md.sal.common.util.jmx.AbstractMXBean; import org.opendaylight.controller.md.sal.common.util.jmx.QueuedNotificationManagerMXBeanImpl; import org.opendaylight.controller.md.sal.common.util.jmx.ThreadExecutorStatsMXBeanImpl; +import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore; import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager; /** @@ -22,11 +22,9 @@ import org.opendaylight.yangtools.util.concurrent.QueuedNotificationManager; public class InMemoryDataStoreStats implements AutoCloseable { private final AbstractMXBean notificationExecutorStatsBean; - private final AbstractMXBean dataStoreExecutorStatsBean; private final QueuedNotificationManagerMXBeanImpl notificationManagerStatsBean; - public InMemoryDataStoreStats(final String mBeanType, final QueuedNotificationManager manager, - final ExecutorService dataStoreExecutor) { + public InMemoryDataStoreStats(final String mBeanType, final QueuedNotificationManager manager) { notificationManagerStatsBean = new QueuedNotificationManagerMXBeanImpl(manager, "notification-manager", mBeanType, null); @@ -37,12 +35,10 @@ public class InMemoryDataStoreStats implements AutoCloseable { if (notificationExecutorStatsBean != null) { notificationExecutorStatsBean.registerMBean(); } + } - dataStoreExecutorStatsBean = ThreadExecutorStatsMXBeanImpl.create(dataStoreExecutor, - "data-store-executor", mBeanType, null); - if (dataStoreExecutorStatsBean != null) { - dataStoreExecutorStatsBean.registerMBean(); - } + public InMemoryDataStoreStats(final String name, final InMemoryDOMDataStore dataStore) { + this(name, dataStore.getDataChangeListenerNotificationManager()); } @Override @@ -51,10 +47,6 @@ public class InMemoryDataStoreStats implements AutoCloseable { notificationExecutorStatsBean.unregisterMBean(); } - if(dataStoreExecutorStatsBean != null) { - dataStoreExecutorStatsBean.unregisterMBean(); - } - if(notificationManagerStatsBean != null) { notificationManagerStatsBean.unregisterMBean(); } diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/AbstractDataChangeListenerTest.java b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/AbstractDataChangeListenerTest.java index 0e064cd504..8d32962421 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/AbstractDataChangeListenerTest.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/AbstractDataChangeListenerTest.java @@ -7,11 +7,8 @@ */ package org.opendaylight.controller.md.sal.dom.store.impl; -import com.google.common.util.concurrent.MoreExecutors; - import java.util.Collection; import java.util.Map; - import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -63,8 +60,7 @@ public abstract class AbstractDataChangeListenerTest { dclExecutorService = new TestDCLExecutorService( SpecialExecutors.newBlockingBoundedFastThreadPool(1, 10, "DCL" )); - datastore = new InMemoryDOMDataStore("TEST", - MoreExecutors.sameThreadExecutor(), dclExecutorService ); + datastore = new InMemoryDOMDataStore("TEST", dclExecutorService); datastore.onGlobalContextUpdated(schemaContext); } diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java index 04e19493db..4720f4b4b9 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/InMemoryDataStoreTest.java @@ -11,14 +11,11 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; - import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; - import java.util.concurrent.ExecutionException; - import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -48,8 +45,7 @@ public class InMemoryDataStoreTest { @Before public void setupStore() { - domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.sameThreadExecutor(), - MoreExecutors.sameThreadExecutor()); + domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.sameThreadExecutor()); schemaContext = TestModel.createTestContext(); domStore.onGlobalContextUpdated(schemaContext); } diff --git a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaUpdateForTransactionTest.java b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaUpdateForTransactionTest.java index 364712c7b3..15e5f716f6 100644 --- a/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaUpdateForTransactionTest.java +++ b/opendaylight/md-sal/sal-inmemory-datastore/src/test/java/org/opendaylight/controller/md/sal/dom/store/impl/SchemaUpdateForTransactionTest.java @@ -8,9 +8,9 @@ package org.opendaylight.controller.md.sal.dom.store.impl; import static org.junit.Assert.assertNotNull; - +import com.google.common.base.Throwables; +import com.google.common.util.concurrent.MoreExecutors; import java.util.concurrent.ExecutionException; - import org.junit.Before; import org.junit.Test; import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction; @@ -23,9 +23,6 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import com.google.common.base.Throwables; -import com.google.common.util.concurrent.MoreExecutors; - public class SchemaUpdateForTransactionTest { private static final YangInstanceIdentifier TOP_PATH = YangInstanceIdentifier.of(Top.QNAME); @@ -34,8 +31,7 @@ public class SchemaUpdateForTransactionTest { @Before public void setupStore() { - domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.sameThreadExecutor(), - MoreExecutors.sameThreadExecutor()); + domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.sameThreadExecutor()); loadSchemas(RockTheHouseInput.class); } diff --git a/opendaylight/md-sal/statistics-manager/src/test/java/test/mock/util/DataBrokerTestCustomizer.java b/opendaylight/md-sal/statistics-manager/src/test/java/test/mock/util/DataBrokerTestCustomizer.java index 36ab41fa68..30704997f3 100644 --- a/opendaylight/md-sal/statistics-manager/src/test/java/test/mock/util/DataBrokerTestCustomizer.java +++ b/opendaylight/md-sal/statistics-manager/src/test/java/test/mock/util/DataBrokerTestCustomizer.java @@ -56,15 +56,13 @@ public class DataBrokerTestCustomizer { } public DOMStore createConfigurationDatastore() { - InMemoryDOMDataStore store = new InMemoryDOMDataStore("CFG", - MoreExecutors.sameThreadExecutor(), MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore store = new InMemoryDOMDataStore("CFG", MoreExecutors.sameThreadExecutor()); schemaService.registerSchemaContextListener(store); return store; } public DOMStore createOperationalDatastore() { - InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", - MoreExecutors.sameThreadExecutor(), MoreExecutors.sameThreadExecutor()); + InMemoryDOMDataStore store = new InMemoryDOMDataStore("OPER", MoreExecutors.sameThreadExecutor()); schemaService.registerSchemaContextListener(store); return store; } -- 2.36.6