From f3c38988cc31e07bab473cace946aebf5152c61f Mon Sep 17 00:00:00 2001 From: Shaleen Saxena Date: Sun, 30 Aug 2015 22:25:19 -0400 Subject: [PATCH] Bug-4214 - Add support for configurable snapshot chunk size. Added a new variable in the distributed-datastore-provider.yang. This will be used to configure the snapshot chunk size. Added various setters/getters to the DatastoreContext. The support for this variable was added to JMX as well, so that the value can be seen via JConsole. Moreover, added tests in DatastoreContextTest. Also fixed a recurring typo in sal-akka-raft. Snapshot was spelled as snaphot (missing s in shot). This code was unit tested with different entries in datastore.cfg. Also tested the case where no special value was provided in datastore.cfg, and the default value was shown in jconsole. Change-Id: Ie754075cc25f9eadf01cc65aee726735144c1794 Signed-off-by: Shaleen Saxena --- .../cluster/raft/DefaultConfigParamsImpl.java | 8 ++++---- .../cluster/raft/behaviors/LeaderTest.java | 2 +- .../src/main/resources/initial/datastore.cfg | 2 ++ .../cluster/datastore/DatastoreContext.java | 16 ++++++++++++++++ .../jmx/mbeans/DatastoreConfigurationMXBean.java | 2 ++ .../mbeans/DatastoreConfigurationMXBeanImpl.java | 6 ++++++ ...DistributedConfigDataStoreProviderModule.java | 1 + ...ibutedOperationalDataStoreProviderModule.java | 1 + .../yang/distributed-datastore-provider.yang | 7 +++++++ .../cluster/datastore/DatastoreContextTest.java | 4 ++++ 10 files changed, 44 insertions(+), 5 deletions(-) diff --git a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/DefaultConfigParamsImpl.java b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/DefaultConfigParamsImpl.java index 6828c85e20..c8cc88c3ed 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/DefaultConfigParamsImpl.java +++ b/opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/DefaultConfigParamsImpl.java @@ -58,7 +58,7 @@ public class DefaultConfigParamsImpl implements ConfigParams { // in-memory journal can use before it needs to snapshot private int snapshotDataThresholdPercentage = 12; - private int snaphotChunkSize = SNAPSHOT_CHUNK_SIZE; + private int snapshotChunkSize = SNAPSHOT_CHUNK_SIZE; private long electionTimeoutFactor = 2; private String customRaftPolicyImplementationClass; @@ -78,8 +78,8 @@ public class DefaultConfigParamsImpl implements ConfigParams { this.snapshotDataThresholdPercentage = snapshotDataThresholdPercentage; } - public void setSnaphotChunkSize(int snaphotChunkSize) { - this.snaphotChunkSize = snaphotChunkSize; + public void setSnapshotChunkSize(int snapshotChunkSize) { + this.snapshotChunkSize = snapshotChunkSize; } public void setJournalRecoveryLogBatchSize(int journalRecoveryLogBatchSize) { @@ -131,7 +131,7 @@ public class DefaultConfigParamsImpl implements ConfigParams { @Override public int getSnapshotChunkSize() { - return snaphotChunkSize; + return snapshotChunkSize; } @Override diff --git a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java index ee6e5776e1..4b05ed36d5 100644 --- a/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java +++ b/opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java @@ -1484,7 +1484,7 @@ public class LeaderTest extends AbstractLeaderTest { MockRaftActorContext leaderActorContext = createActorContextWithFollower(); ((DefaultConfigParamsImpl)leaderActorContext.getConfigParams()).setHeartBeatInterval( new FiniteDuration(1000, TimeUnit.SECONDS)); - ((DefaultConfigParamsImpl)leaderActorContext.getConfigParams()).setSnaphotChunkSize(2); + ((DefaultConfigParamsImpl)leaderActorContext.getConfigParams()).setSnapshotChunkSize(2); leaderActorContext.setReplicatedLog( new MockRaftActorContext.MockReplicatedLogBuilder().createEntries(0, 4, 1).build()); diff --git a/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/datastore.cfg b/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/datastore.cfg index 13ccf93f5e..cafe375f8b 100644 --- a/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/datastore.cfg +++ b/opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/datastore.cfg @@ -81,3 +81,5 @@ operational.persistent=false # cannot be found then the default raft policy will be applied #custom-raft-policy-implementation= +# The maximum size (in bytes) for snapshot chunks to be sent during sync +#shard-snapshot-chunk-size=20480000 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContext.java index 3afc966c8d..40816098a9 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContext.java @@ -47,6 +47,7 @@ public class DatastoreContext { public static final String UNKNOWN_DATA_STORE_TYPE = "unknown"; public static final int DEFAULT_SHARD_BATCHED_MODIFICATION_COUNT = 1000; public static final long DEFAULT_SHARD_COMMIT_QUEUE_EXPIRY_TIMEOUT_IN_MS = TimeUnit.MILLISECONDS.convert(2, TimeUnit.MINUTES); + public static final int DEFAULT_SHARD_SNAPSHOT_CHUNK_SIZE = 2048000; private static Set globalDatastoreTypes = Sets.newConcurrentHashSet(); @@ -80,6 +81,7 @@ public class DatastoreContext { setIsolatedLeaderCheckInterval(DEFAULT_ISOLATED_LEADER_CHECK_INTERVAL_IN_MILLIS); setSnapshotDataThresholdPercentage(DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE); setElectionTimeoutFactor(DEFAULT_SHARD_ELECTION_TIMEOUT_FACTOR); + setShardSnapshotChunkSize(DEFAULT_SHARD_SNAPSHOT_CHUNK_SIZE); } private DatastoreContext(DatastoreContext other) { @@ -108,6 +110,7 @@ public class DatastoreContext { setSnapshotDataThresholdPercentage(other.raftConfig.getSnapshotDataThresholdPercentage()); setElectionTimeoutFactor(other.raftConfig.getElectionTimeoutFactor()); setCustomRaftPolicyImplementation(other.customRaftPolicyImplementation); + setShardSnapshotChunkSize(other.raftConfig.getSnapshotChunkSize()); } @@ -223,6 +226,14 @@ public class DatastoreContext { return transactionDebugContextEnabled; } + public int getShardSnapshotChunkSize() { + return raftConfig.getSnapshotChunkSize(); + } + + public void setShardSnapshotChunkSize(int shardSnapshotChunkSize) { + raftConfig.setSnapshotChunkSize(shardSnapshotChunkSize); + } + public static class Builder { private final DatastoreContext datastoreContext; private int maxShardDataChangeExecutorPoolSize = @@ -425,5 +436,10 @@ public class DatastoreContext { datastoreContext.setCustomRaftPolicyImplementation(customRaftPolicyImplementation); return this; } + + public Builder shardSnapshotChunkSize(int shardSnapshotChunkSize) { + datastoreContext.setShardSnapshotChunkSize(shardSnapshotChunkSize); + return this; + } } } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/DatastoreConfigurationMXBean.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/DatastoreConfigurationMXBean.java index daf006c3d6..e5b1db98ec 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/DatastoreConfigurationMXBean.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/DatastoreConfigurationMXBean.java @@ -53,4 +53,6 @@ public interface DatastoreConfigurationMXBean { int getMaxShardDataChangeListenerQueueSize(); int getMaxShardDataStoreExecutorQueueSize(); + + int getShardSnapshotChunkSize(); } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/DatastoreConfigurationMXBeanImpl.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/DatastoreConfigurationMXBeanImpl.java index 9cc41d632a..b2ff9fba40 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/DatastoreConfigurationMXBeanImpl.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/DatastoreConfigurationMXBeanImpl.java @@ -128,4 +128,10 @@ public class DatastoreConfigurationMXBeanImpl extends AbstractMXBean implements public int getMaxShardDataStoreExecutorQueueSize() { return context.getDataStoreProperties().getMaxDataStoreExecutorQueueSize(); } + + @Override + public int getShardSnapshotChunkSize() { + return context.getShardSnapshotChunkSize(); + } + } diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java index 878c0351a2..f43f13d904 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java @@ -68,6 +68,7 @@ public class DistributedConfigDataStoreProviderModule extends props.getShardCommitQueueExpiryTimeoutInSeconds().getValue().intValue()) .transactionDebugContextEnabled(props.getTransactionDebugContextEnabled()) .customRaftPolicyImplementation(props.getCustomRaftPolicyImplementation()) + .shardSnapshotChunkSize(props.getShardSnapshotChunkSize().getValue().intValue()) .build(); return DistributedDataStoreFactory.createInstance(getConfigSchemaServiceDependency(), diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java index 2db784a918..85dddde443 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java @@ -69,6 +69,7 @@ public class DistributedOperationalDataStoreProviderModule extends props.getShardCommitQueueExpiryTimeoutInSeconds().getValue().intValue()) .transactionDebugContextEnabled(props.getTransactionDebugContextEnabled()) .customRaftPolicyImplementation(props.getCustomRaftPolicyImplementation()) + .shardSnapshotChunkSize(props.getShardSnapshotChunkSize().getValue().intValue()) .build(); return DistributedDataStoreFactory.createInstance(getOperationalSchemaServiceDependency(), diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/yang/distributed-datastore-provider.yang b/opendaylight/md-sal/sal-distributed-datastore/src/main/yang/distributed-datastore-provider.yang index fcd4a301db..91c4279f24 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/yang/distributed-datastore-provider.yang +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/yang/distributed-datastore-provider.yang @@ -225,6 +225,13 @@ module distributed-datastore-provider { present in the distributed data store module itself. If this property is set to a class which cannot be found then the default raft behavior will be applied"; } + + leaf shard-snapshot-chunk-size { + default 2048000; + type non-zero-uint32-type; + description "When sending a snapshot to a follower, this is the maximum size in bytes for + a chunk of data."; + } } // Augments the 'configuration' choice node under modules/module. diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextTest.java b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextTest.java index 0043993142..8cc0186233 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextTest.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextTest.java @@ -17,6 +17,7 @@ import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEF import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS; import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SNAPSHOT_BATCH_COUNT; import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_TX_CREATION_INITIAL_RATE_LIMIT; +import static org.opendaylight.controller.cluster.datastore.DatastoreContext.DEFAULT_SHARD_SNAPSHOT_CHUNK_SIZE; import java.util.concurrent.TimeUnit; import org.junit.Assert; import org.junit.Test; @@ -54,6 +55,7 @@ public class DatastoreContextTest { context.getDataStoreProperties().getMaxDataChangeListenerQueueSize()); assertEquals(InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_STORE_EXECUTOR_QUEUE_SIZE, context.getDataStoreProperties().getMaxDataStoreExecutorQueueSize()); + assertEquals(DEFAULT_SHARD_SNAPSHOT_CHUNK_SIZE, context.getShardSnapshotChunkSize()); } @Test @@ -88,6 +90,7 @@ public class DatastoreContextTest { InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_LISTENER_QUEUE_SIZE + 1); builder.maxShardDataStoreExecutorQueueSize( InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_STORE_EXECUTOR_QUEUE_SIZE + 1); + builder.shardSnapshotChunkSize(DEFAULT_SHARD_SNAPSHOT_CHUNK_SIZE+1); DatastoreContext context = builder.build(); @@ -137,5 +140,6 @@ public class DatastoreContextTest { context.getDataStoreProperties().getMaxDataChangeListenerQueueSize()); assertEquals(InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_STORE_EXECUTOR_QUEUE_SIZE + 1, context.getDataStoreProperties().getMaxDataStoreExecutorQueueSize()); + assertEquals(DEFAULT_SHARD_SNAPSHOT_CHUNK_SIZE + 1, context.getShardSnapshotChunkSize()); } } -- 2.36.6