Bug-4214 - Add support for configurable snapshot chunk size. 13/26413/3
authorShaleen Saxena <ssaxena@brocade.com>
Mon, 31 Aug 2015 02:25:19 +0000 (22:25 -0400)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 17 Sep 2015 18:40:37 +0000 (18:40 +0000)
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>
(cherry picked from commit f3c38988cc31e07bab473cace946aebf5152c61f)

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 a391fdd342cdef3c85320c5a3bd8f9f687066393..507c30095240f22c9d282d92c69a9f5f9bf8871c 100644 (file)
@@ -1649,7 +1649,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 26d1a6eb97a82abdcee1bd8ddcf73ecc606ab2fc..e0c243b5b41ddf3612248e8fc3fec6ab31fd84d3 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 d04697072c7ddc26bc19461d78f7dda09f4da296..eee46aeb7df800688366c0c3d0d6d19afbc958aa 100644 (file)
@@ -25,6 +25,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;
@@ -62,6 +63,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
@@ -96,6 +98,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();
 
@@ -145,5 +148,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());
     }
 }