BUG 2138 - Do not fail on module-based default shard
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DatastoreContext.java
index 0536e4b15a382c4913fa29ee292dcfc6c9b4b12f..eeb6ad3155e2bc91d9e910728d589cca2084603b 100644 (file)
@@ -22,6 +22,7 @@ import org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl;
 import org.opendaylight.controller.cluster.raft.PeerAddressResolver;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreConfigProperties;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import scala.concurrent.duration.Duration;
 import scala.concurrent.duration.FiniteDuration;
 
@@ -71,9 +72,11 @@ public class DatastoreContext {
     private final DefaultConfigParamsImpl raftConfig = new DefaultConfigParamsImpl();
     private String dataStoreName = UNKNOWN_DATA_STORE_TYPE;
     private LogicalDatastoreType logicalStoreType = LogicalDatastoreType.OPERATIONAL;
+    private YangInstanceIdentifier storeRoot = YangInstanceIdentifier.EMPTY;
     private int shardBatchedModificationCount = DEFAULT_SHARD_BATCHED_MODIFICATION_COUNT;
     private boolean writeOnlyTransactionOptimizationsEnabled = true;
     private long shardCommitQueueExpiryTimeoutInMillis = DEFAULT_SHARD_COMMIT_QUEUE_EXPIRY_TIMEOUT_IN_MS;
+    private boolean useTellBasedProtocol = false;
     private boolean transactionDebugContextEnabled = false;
     private String shardManagerPersistenceId;
 
@@ -91,7 +94,7 @@ public class DatastoreContext {
         setShardSnapshotChunkSize(DEFAULT_SHARD_SNAPSHOT_CHUNK_SIZE);
     }
 
-    private DatastoreContext(DatastoreContext other) {
+    private DatastoreContext(final DatastoreContext other) {
         this.dataStoreProperties = other.dataStoreProperties;
         this.shardTransactionIdleTimeout = other.shardTransactionIdleTimeout;
         this.operationTimeoutInMillis = other.operationTimeoutInMillis;
@@ -105,11 +108,13 @@ public class DatastoreContext {
         this.transactionCreationInitialRateLimit = other.transactionCreationInitialRateLimit;
         this.dataStoreName = other.dataStoreName;
         this.logicalStoreType = other.logicalStoreType;
+        this.storeRoot = other.storeRoot;
         this.shardBatchedModificationCount = other.shardBatchedModificationCount;
         this.writeOnlyTransactionOptimizationsEnabled = other.writeOnlyTransactionOptimizationsEnabled;
         this.shardCommitQueueExpiryTimeoutInMillis = other.shardCommitQueueExpiryTimeoutInMillis;
         this.transactionDebugContextEnabled = other.transactionDebugContextEnabled;
         this.shardManagerPersistenceId = other.shardManagerPersistenceId;
+        this.useTellBasedProtocol = other.useTellBasedProtocol;
 
         setShardJournalRecoveryLogBatchSize(other.raftConfig.getJournalRecoveryLogBatchSize());
         setSnapshotBatchCount(other.raftConfig.getSnapshotBatchCount());
@@ -120,6 +125,8 @@ public class DatastoreContext {
         setCustomRaftPolicyImplementation(other.raftConfig.getCustomRaftPolicyImplementationClass());
         setShardSnapshotChunkSize(other.raftConfig.getSnapshotChunkSize());
         setPeerAddressResolver(other.raftConfig.getPeerAddressResolver());
+        setTempFileDirectory(other.getTempFileDirectory());
+        setFileBackedStreamingThreshold(other.getFileBackedStreamingThreshold());
     }
 
     public static Builder newBuilder() {
@@ -186,6 +193,10 @@ public class DatastoreContext {
         return logicalStoreType;
     }
 
+    public YangInstanceIdentifier getStoreRoot() {
+        return storeRoot;
+    }
+
     public long getTransactionCreationInitialRateLimit() {
         return transactionCreationInitialRateLimit;
     }
@@ -194,6 +205,22 @@ public class DatastoreContext {
         return shardManagerPersistenceId;
     }
 
+    public String getTempFileDirectory() {
+        return raftConfig.getTempFileDirectory();
+    }
+
+    private void setTempFileDirectory(String tempFileDirectory) {
+        raftConfig.setTempFileDirectory(tempFileDirectory);
+    }
+
+    public int getFileBackedStreamingThreshold() {
+        return raftConfig.getFileBackedStreamingThreshold();
+    }
+
+    private void setFileBackedStreamingThreshold(int fileBackedStreamingThreshold) {
+        raftConfig.setFileBackedStreamingThreshold(fileBackedStreamingThreshold);
+    }
+
     private void setPeerAddressResolver(PeerAddressResolver resolver) {
         raftConfig.setPeerAddressResolver(resolver);
     }
@@ -251,6 +278,10 @@ public class DatastoreContext {
         return transactionDebugContextEnabled;
     }
 
+    public boolean isUseTellBasedProtocol() {
+        return useTellBasedProtocol;
+    }
+
     public int getShardSnapshotChunkSize() {
         return raftConfig.getSnapshotChunkSize();
     }
@@ -407,13 +438,18 @@ public class DatastoreContext {
             return this;
         }
 
+        public Builder storeRoot(final YangInstanceIdentifier storeRoot) {
+            datastoreContext.storeRoot = storeRoot;
+            return this;
+        }
+
         public Builder dataStoreName(String dataStoreName) {
             datastoreContext.dataStoreName = Preconditions.checkNotNull(dataStoreName);
             datastoreContext.dataStoreMXBeanType = "Distributed" + WordUtils.capitalize(dataStoreName) + "Datastore";
             return this;
         }
 
-        public Builder shardBatchedModificationCount(int shardBatchedModificationCount) {
+        public Builder shardBatchedModificationCount(final int shardBatchedModificationCount) {
             datastoreContext.shardBatchedModificationCount = shardBatchedModificationCount;
             return this;
         }
@@ -459,6 +495,11 @@ public class DatastoreContext {
             return this;
         }
 
+        public Builder useTellBasedProtocol(boolean value) {
+            datastoreContext.useTellBasedProtocol = value;
+            return this;
+        }
+
         /**
          * For unit tests only.
          */
@@ -494,5 +535,15 @@ public class DatastoreContext {
             datastoreContext.setPeerAddressResolver(resolver);
             return this;
         }
+
+        public Builder tempFileDirectory(String tempFileDirectory) {
+            datastoreContext.setTempFileDirectory(tempFileDirectory);
+            return this;
+        }
+
+        public Builder fileBackedStreamingThresholdInMegabytes(int  fileBackedStreamingThreshold) {
+            datastoreContext.setFileBackedStreamingThreshold(fileBackedStreamingThreshold * ConfigParams.MEGABYTE);
+            return this;
+        }
     }
 }