Bug-4214 - Add support for configurable snapshot chunk size. 04/26204/2
authorShaleen Saxena <ssaxena@brocade.com>
Mon, 31 Aug 2015 02:25:19 +0000 (22:25 -0400)
committerShaleen Saxena <ssaxena@brocade.com>
Mon, 31 Aug 2015 17:07:29 +0000 (13:07 -0400)
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 <ssaxena@brocade.com>
opendaylight/md-sal/sal-akka-raft/src/main/java/org/opendaylight/controller/cluster/raft/DefaultConfigParamsImpl.java
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/behaviors/LeaderTest.java
opendaylight/md-sal/sal-clustering-config/src/main/resources/initial/datastore.cfg
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContext.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/DatastoreConfigurationMXBean.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/jmx/mbeans/DatastoreConfigurationMXBeanImpl.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedConfigDataStoreProviderModule.java
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/config/yang/config/distributed_datastore_provider/DistributedOperationalDataStoreProviderModule.java
opendaylight/md-sal/sal-distributed-datastore/src/main/yang/distributed-datastore-provider.yang
opendaylight/md-sal/sal-distributed-datastore/src/test/java/org/opendaylight/controller/cluster/datastore/DatastoreContextTest.java

index 6828c85e20525c8cf2ecc6f2304206a8046d71ea..c8cc88c3edd45256011f050a5a4c83b749b37730 100644 (file)
@@ -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
index ee6e5776e15161c693ebd8aab83a6895f501353f..4b05ed36d586a26f8b1b415e052048f91490507f 100644 (file)
@@ -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());
index 13ccf93f5ee2311494e159ba68752129b70c94bb..cafe375f8b5f27653b26e3347bb94c83d9477383 100644 (file)
@@ -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
index 3afc966c8db1a34cb5b75d2a02ebcac13f3afa40..40816098a971ae6155f9d3d15dcaa377b7e4d450 100644 (file)
@@ -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<String> 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;
+        }
     }
 }
index 9cc41d632aff660a97d969b84bba9b93c3bc8c4d..b2ff9fba40ab5fc7df32397b4d91eaa5c2bcca40 100644 (file)
@@ -128,4 +128,10 @@ public class DatastoreConfigurationMXBeanImpl extends AbstractMXBean implements
     public int getMaxShardDataStoreExecutorQueueSize() {
         return context.getDataStoreProperties().getMaxDataStoreExecutorQueueSize();
     }
+
+    @Override
+    public int getShardSnapshotChunkSize() {
+        return context.getShardSnapshotChunkSize();
+    }
+
 }
index 878c0351a2f4eda07ac92ebbca3653b801cbcb1b..f43f13d9045941f714234f16f4630f0de15e88c9 100644 (file)
@@ -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(),
index 2db784a918c94976cd25888c319172955aa017d2..85dddde44378be768e1758255a951a6353a799f2 100644 (file)
@@ -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(),
index fcd4a301dbeeaff30085fd8476b2972346271847..91c4279f24d2a30a9dc0a9baab6baa0806c8a717 100644 (file)
@@ -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.
index 004399314228720c725d70740934880eeb75e3d4..8cc0186233649fb8b1779592d9c8274eaa71e355 100644 (file)
@@ -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());
     }
 }