2 * Copyright (c) 2014 Brocade Communications Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.datastore;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
13 import akka.util.Timeout;
14 import com.google.common.annotations.VisibleForTesting;
16 import java.util.concurrent.ConcurrentHashMap;
17 import java.util.concurrent.TimeUnit;
18 import org.apache.commons.text.WordUtils;
19 import org.opendaylight.controller.cluster.access.client.AbstractClientConnection;
20 import org.opendaylight.controller.cluster.access.client.ClientActorConfig;
21 import org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader;
22 import org.opendaylight.controller.cluster.common.actor.FileAkkaConfigurationReader;
23 import org.opendaylight.controller.cluster.raft.ConfigParams;
24 import org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl;
25 import org.opendaylight.controller.cluster.raft.PeerAddressResolver;
26 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
27 import org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStoreConfigProperties;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31 import scala.concurrent.duration.FiniteDuration;
34 * Contains contextual data for a data store.
36 * @author Thomas Pantelis
38 // Non-final for mocking
39 public class DatastoreContext implements ClientActorConfig {
40 public static final String METRICS_DOMAIN = "org.opendaylight.controller.cluster.datastore";
42 public static final FiniteDuration DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT = FiniteDuration.create(10,
44 public static final int DEFAULT_OPERATION_TIMEOUT_IN_MS = 5000;
45 public static final int DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS = 30;
46 public static final int DEFAULT_JOURNAL_RECOVERY_BATCH_SIZE = 1;
47 public static final int DEFAULT_SNAPSHOT_BATCH_COUNT = 20000;
48 public static final int DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS = 500;
49 public static final int DEFAULT_ISOLATED_LEADER_CHECK_INTERVAL_IN_MILLIS =
50 DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS * 10;
51 public static final int DEFAULT_SHARD_TX_COMMIT_QUEUE_CAPACITY = 50000;
52 public static final Timeout DEFAULT_SHARD_INITIALIZATION_TIMEOUT = new Timeout(5, TimeUnit.MINUTES);
53 public static final Timeout DEFAULT_SHARD_LEADER_ELECTION_TIMEOUT = new Timeout(30, TimeUnit.SECONDS);
54 public static final int DEFAULT_INITIAL_SETTLE_TIMEOUT_MULTIPLIER = 3;
55 public static final boolean DEFAULT_PERSISTENT = true;
56 public static final FileAkkaConfigurationReader DEFAULT_CONFIGURATION_READER = new FileAkkaConfigurationReader();
57 public static final int DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE = 12;
58 public static final int DEFAULT_SHARD_ELECTION_TIMEOUT_FACTOR = 2;
59 public static final int DEFAULT_SHARD_CANDIDATE_ELECTION_TIMEOUT_DIVISOR = 1;
60 public static final int DEFAULT_TX_CREATION_INITIAL_RATE_LIMIT = 100;
61 public static final String UNKNOWN_DATA_STORE_TYPE = "unknown";
62 public static final int DEFAULT_SHARD_BATCHED_MODIFICATION_COUNT = 1000;
63 public static final long DEFAULT_SHARD_COMMIT_QUEUE_EXPIRY_TIMEOUT_IN_MS =
64 TimeUnit.MILLISECONDS.convert(2, TimeUnit.MINUTES);
65 public static final int DEFAULT_MAX_MESSAGE_SLICE_SIZE = 2048 * 1000; // 2MB
66 public static final int DEFAULT_INITIAL_PAYLOAD_SERIALIZED_BUFFER_CAPACITY = 512;
68 public static final long DEFAULT_SYNC_INDEX_THRESHOLD = 10;
70 private static final Logger LOG = LoggerFactory.getLogger(DatastoreContext.class);
72 private static final Set<String> GLOBAL_DATASTORE_NAMES = ConcurrentHashMap.newKeySet();
74 private final DefaultConfigParamsImpl raftConfig = new DefaultConfigParamsImpl();
76 private InMemoryDOMDataStoreConfigProperties dataStoreProperties;
77 private FiniteDuration shardTransactionIdleTimeout = DatastoreContext.DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT;
78 private long operationTimeoutInMillis = DEFAULT_OPERATION_TIMEOUT_IN_MS;
79 private String dataStoreMXBeanType;
80 private int shardTransactionCommitTimeoutInSeconds = DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS;
81 private int shardTransactionCommitQueueCapacity = DEFAULT_SHARD_TX_COMMIT_QUEUE_CAPACITY;
82 private Timeout shardInitializationTimeout = DEFAULT_SHARD_INITIALIZATION_TIMEOUT;
83 private Timeout shardLeaderElectionTimeout = DEFAULT_SHARD_LEADER_ELECTION_TIMEOUT;
84 private int initialSettleTimeoutMultiplier = DEFAULT_INITIAL_SETTLE_TIMEOUT_MULTIPLIER;
85 private boolean persistent = DEFAULT_PERSISTENT;
86 private AkkaConfigurationReader configurationReader = DEFAULT_CONFIGURATION_READER;
87 private long transactionCreationInitialRateLimit = DEFAULT_TX_CREATION_INITIAL_RATE_LIMIT;
88 private String dataStoreName = UNKNOWN_DATA_STORE_TYPE;
89 private LogicalDatastoreType logicalStoreType = LogicalDatastoreType.OPERATIONAL;
90 private YangInstanceIdentifier storeRoot = YangInstanceIdentifier.empty();
91 private int shardBatchedModificationCount = DEFAULT_SHARD_BATCHED_MODIFICATION_COUNT;
92 private boolean writeOnlyTransactionOptimizationsEnabled = true;
93 private long shardCommitQueueExpiryTimeoutInMillis = DEFAULT_SHARD_COMMIT_QUEUE_EXPIRY_TIMEOUT_IN_MS;
94 private boolean useTellBasedProtocol = false;
95 private boolean transactionDebugContextEnabled = false;
96 private String shardManagerPersistenceId;
97 private int maximumMessageSliceSize = DEFAULT_MAX_MESSAGE_SLICE_SIZE;
98 private long backendAlivenessTimerInterval = AbstractClientConnection.DEFAULT_BACKEND_ALIVE_TIMEOUT_NANOS;
99 private long requestTimeout = AbstractClientConnection.DEFAULT_REQUEST_TIMEOUT_NANOS;
100 private long noProgressTimeout = AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS;
101 private int initialPayloadSerializedBufferCapacity = DEFAULT_INITIAL_PAYLOAD_SERIALIZED_BUFFER_CAPACITY;
103 public static Set<String> getGlobalDatastoreNames() {
104 return GLOBAL_DATASTORE_NAMES;
108 setShardJournalRecoveryLogBatchSize(DEFAULT_JOURNAL_RECOVERY_BATCH_SIZE);
109 setSnapshotBatchCount(DEFAULT_SNAPSHOT_BATCH_COUNT);
110 setHeartbeatInterval(DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS);
111 setIsolatedLeaderCheckInterval(DEFAULT_ISOLATED_LEADER_CHECK_INTERVAL_IN_MILLIS);
112 setSnapshotDataThresholdPercentage(DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE);
113 setElectionTimeoutFactor(DEFAULT_SHARD_ELECTION_TIMEOUT_FACTOR);
114 setCandidateElectionTimeoutDivisor(DEFAULT_SHARD_CANDIDATE_ELECTION_TIMEOUT_DIVISOR);
115 setSyncIndexThreshold(DEFAULT_SYNC_INDEX_THRESHOLD);
116 setMaximumMessageSliceSize(DEFAULT_MAX_MESSAGE_SLICE_SIZE);
119 private DatastoreContext(final DatastoreContext other) {
120 this.dataStoreProperties = other.dataStoreProperties;
121 this.shardTransactionIdleTimeout = other.shardTransactionIdleTimeout;
122 this.operationTimeoutInMillis = other.operationTimeoutInMillis;
123 this.dataStoreMXBeanType = other.dataStoreMXBeanType;
124 this.shardTransactionCommitTimeoutInSeconds = other.shardTransactionCommitTimeoutInSeconds;
125 this.shardTransactionCommitQueueCapacity = other.shardTransactionCommitQueueCapacity;
126 this.shardInitializationTimeout = other.shardInitializationTimeout;
127 this.shardLeaderElectionTimeout = other.shardLeaderElectionTimeout;
128 this.initialSettleTimeoutMultiplier = other.initialSettleTimeoutMultiplier;
129 this.persistent = other.persistent;
130 this.configurationReader = other.configurationReader;
131 this.transactionCreationInitialRateLimit = other.transactionCreationInitialRateLimit;
132 this.dataStoreName = other.dataStoreName;
133 this.logicalStoreType = other.logicalStoreType;
134 this.storeRoot = other.storeRoot;
135 this.shardBatchedModificationCount = other.shardBatchedModificationCount;
136 this.writeOnlyTransactionOptimizationsEnabled = other.writeOnlyTransactionOptimizationsEnabled;
137 this.shardCommitQueueExpiryTimeoutInMillis = other.shardCommitQueueExpiryTimeoutInMillis;
138 this.transactionDebugContextEnabled = other.transactionDebugContextEnabled;
139 this.shardManagerPersistenceId = other.shardManagerPersistenceId;
140 this.useTellBasedProtocol = other.useTellBasedProtocol;
141 this.backendAlivenessTimerInterval = other.backendAlivenessTimerInterval;
142 this.requestTimeout = other.requestTimeout;
143 this.noProgressTimeout = other.noProgressTimeout;
144 this.initialPayloadSerializedBufferCapacity = other.initialPayloadSerializedBufferCapacity;
146 setShardJournalRecoveryLogBatchSize(other.raftConfig.getJournalRecoveryLogBatchSize());
147 setSnapshotBatchCount(other.raftConfig.getSnapshotBatchCount());
148 setHeartbeatInterval(other.raftConfig.getHeartBeatInterval().toMillis());
149 setIsolatedLeaderCheckInterval(other.raftConfig.getIsolatedCheckIntervalInMillis());
150 setSnapshotDataThresholdPercentage(other.raftConfig.getSnapshotDataThresholdPercentage());
151 setElectionTimeoutFactor(other.raftConfig.getElectionTimeoutFactor());
152 setCandidateElectionTimeoutDivisor(other.raftConfig.getCandidateElectionTimeoutDivisor());
153 setCustomRaftPolicyImplementation(other.raftConfig.getCustomRaftPolicyImplementationClass());
154 setMaximumMessageSliceSize(other.getMaximumMessageSliceSize());
155 setShardSnapshotChunkSize(other.raftConfig.getSnapshotChunkSize());
156 setPeerAddressResolver(other.raftConfig.getPeerAddressResolver());
157 setTempFileDirectory(other.getTempFileDirectory());
158 setFileBackedStreamingThreshold(other.getFileBackedStreamingThreshold());
159 setSyncIndexThreshold(other.raftConfig.getSyncIndexThreshold());
162 public static Builder newBuilder() {
163 return new Builder(new DatastoreContext());
166 public static Builder newBuilderFrom(final DatastoreContext context) {
167 return new Builder(new DatastoreContext(context));
170 public InMemoryDOMDataStoreConfigProperties getDataStoreProperties() {
171 return dataStoreProperties;
174 public FiniteDuration getShardTransactionIdleTimeout() {
175 return shardTransactionIdleTimeout;
178 public String getDataStoreMXBeanType() {
179 return dataStoreMXBeanType;
182 public long getOperationTimeoutInMillis() {
183 return operationTimeoutInMillis;
186 public ConfigParams getShardRaftConfig() {
190 public int getShardTransactionCommitTimeoutInSeconds() {
191 return shardTransactionCommitTimeoutInSeconds;
194 public int getShardTransactionCommitQueueCapacity() {
195 return shardTransactionCommitQueueCapacity;
198 public Timeout getShardInitializationTimeout() {
199 return shardInitializationTimeout;
202 public Timeout getShardLeaderElectionTimeout() {
203 return shardLeaderElectionTimeout;
207 * Return the multiplier of {@link #getShardLeaderElectionTimeout()} which the frontend will wait for all shards
208 * on the local node to settle.
210 * @return Non-negative multiplier. Value of {@code 0} indicates to wait indefinitely.
212 public int getInitialSettleTimeoutMultiplier() {
213 return initialSettleTimeoutMultiplier;
216 public boolean isPersistent() {
220 public AkkaConfigurationReader getConfigurationReader() {
221 return configurationReader;
224 public long getShardElectionTimeoutFactor() {
225 return raftConfig.getElectionTimeoutFactor();
228 public String getDataStoreName() {
229 return dataStoreName;
232 public LogicalDatastoreType getLogicalStoreType() {
233 return logicalStoreType;
236 public YangInstanceIdentifier getStoreRoot() {
240 public long getTransactionCreationInitialRateLimit() {
241 return transactionCreationInitialRateLimit;
244 public String getShardManagerPersistenceId() {
245 return shardManagerPersistenceId;
249 public String getTempFileDirectory() {
250 return raftConfig.getTempFileDirectory();
253 private void setTempFileDirectory(final String tempFileDirectory) {
254 raftConfig.setTempFileDirectory(tempFileDirectory);
258 public int getFileBackedStreamingThreshold() {
259 return raftConfig.getFileBackedStreamingThreshold();
262 private void setFileBackedStreamingThreshold(final int fileBackedStreamingThreshold) {
263 raftConfig.setFileBackedStreamingThreshold(fileBackedStreamingThreshold);
266 private void setPeerAddressResolver(final PeerAddressResolver resolver) {
267 raftConfig.setPeerAddressResolver(resolver);
270 private void setHeartbeatInterval(final long shardHeartbeatIntervalInMillis) {
271 raftConfig.setHeartBeatInterval(new FiniteDuration(shardHeartbeatIntervalInMillis,
272 TimeUnit.MILLISECONDS));
275 private void setShardJournalRecoveryLogBatchSize(final int shardJournalRecoveryLogBatchSize) {
276 raftConfig.setJournalRecoveryLogBatchSize(shardJournalRecoveryLogBatchSize);
280 private void setIsolatedLeaderCheckInterval(final long shardIsolatedLeaderCheckIntervalInMillis) {
281 raftConfig.setIsolatedLeaderCheckInterval(
282 new FiniteDuration(shardIsolatedLeaderCheckIntervalInMillis, TimeUnit.MILLISECONDS));
285 private void setElectionTimeoutFactor(final long shardElectionTimeoutFactor) {
286 raftConfig.setElectionTimeoutFactor(shardElectionTimeoutFactor);
289 private void setCandidateElectionTimeoutDivisor(final long candidateElectionTimeoutDivisor) {
290 raftConfig.setCandidateElectionTimeoutDivisor(candidateElectionTimeoutDivisor);
293 private void setCustomRaftPolicyImplementation(final String customRaftPolicyImplementation) {
294 raftConfig.setCustomRaftPolicyImplementationClass(customRaftPolicyImplementation);
297 private void setSnapshotDataThresholdPercentage(final int shardSnapshotDataThresholdPercentage) {
298 checkArgument(shardSnapshotDataThresholdPercentage >= 0 && shardSnapshotDataThresholdPercentage <= 100);
299 raftConfig.setSnapshotDataThresholdPercentage(shardSnapshotDataThresholdPercentage);
302 private void setSnapshotBatchCount(final long shardSnapshotBatchCount) {
303 raftConfig.setSnapshotBatchCount(shardSnapshotBatchCount);
307 private void setShardSnapshotChunkSize(final int shardSnapshotChunkSize) {
308 // We'll honor the shardSnapshotChunkSize setting for backwards compatibility but only if it doesn't exceed
309 // maximumMessageSliceSize.
310 if (shardSnapshotChunkSize < maximumMessageSliceSize) {
311 raftConfig.setSnapshotChunkSize(shardSnapshotChunkSize);
315 private void setMaximumMessageSliceSize(final int maximumMessageSliceSize) {
316 raftConfig.setSnapshotChunkSize(maximumMessageSliceSize);
317 this.maximumMessageSliceSize = maximumMessageSliceSize;
320 private void setSyncIndexThreshold(final long syncIndexThreshold) {
321 raftConfig.setSyncIndexThreshold(syncIndexThreshold);
324 public int getShardBatchedModificationCount() {
325 return shardBatchedModificationCount;
328 public boolean isWriteOnlyTransactionOptimizationsEnabled() {
329 return writeOnlyTransactionOptimizationsEnabled;
332 public long getShardCommitQueueExpiryTimeoutInMillis() {
333 return shardCommitQueueExpiryTimeoutInMillis;
336 public boolean isTransactionDebugContextEnabled() {
337 return transactionDebugContextEnabled;
340 public boolean isUseTellBasedProtocol() {
341 return useTellBasedProtocol;
345 public int getMaximumMessageSliceSize() {
346 return maximumMessageSliceSize;
350 public long getBackendAlivenessTimerInterval() {
351 return backendAlivenessTimerInterval;
355 public long getRequestTimeout() {
356 return requestTimeout;
360 public long getNoProgressTimeout() {
361 return noProgressTimeout;
364 public int getInitialPayloadSerializedBufferCapacity() {
365 return initialPayloadSerializedBufferCapacity;
368 public static class Builder implements org.opendaylight.yangtools.concepts.Builder<DatastoreContext> {
369 private final DatastoreContext datastoreContext;
370 private int maxShardDataChangeExecutorPoolSize =
371 InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_EXECUTOR_POOL_SIZE;
372 private int maxShardDataChangeExecutorQueueSize =
373 InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_EXECUTOR_QUEUE_SIZE;
374 private int maxShardDataChangeListenerQueueSize =
375 InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_LISTENER_QUEUE_SIZE;
376 private int maxShardDataStoreExecutorQueueSize =
377 InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_STORE_EXECUTOR_QUEUE_SIZE;
379 Builder(final DatastoreContext datastoreContext) {
380 this.datastoreContext = datastoreContext;
382 if (datastoreContext.getDataStoreProperties() != null) {
383 maxShardDataChangeExecutorPoolSize =
384 datastoreContext.getDataStoreProperties().getMaxDataChangeExecutorPoolSize();
385 maxShardDataChangeExecutorQueueSize =
386 datastoreContext.getDataStoreProperties().getMaxDataChangeExecutorQueueSize();
387 maxShardDataChangeListenerQueueSize =
388 datastoreContext.getDataStoreProperties().getMaxDataChangeListenerQueueSize();
389 maxShardDataStoreExecutorQueueSize =
390 datastoreContext.getDataStoreProperties().getMaxDataStoreExecutorQueueSize();
394 public Builder boundedMailboxCapacity(final int boundedMailboxCapacity) {
395 // TODO - this is defined in the yang DataStoreProperties but not currently used.
399 public Builder enableMetricCapture(final boolean enableMetricCapture) {
400 // TODO - this is defined in the yang DataStoreProperties but not currently used.
405 public Builder shardTransactionIdleTimeout(final long timeout, final TimeUnit unit) {
406 datastoreContext.shardTransactionIdleTimeout = FiniteDuration.create(timeout, unit);
410 public Builder shardTransactionIdleTimeoutInMinutes(final long timeout) {
411 return shardTransactionIdleTimeout(timeout, TimeUnit.MINUTES);
414 public Builder operationTimeoutInSeconds(final int operationTimeoutInSeconds) {
415 datastoreContext.operationTimeoutInMillis = TimeUnit.SECONDS.toMillis(operationTimeoutInSeconds);
419 public Builder operationTimeoutInMillis(final long operationTimeoutInMillis) {
420 datastoreContext.operationTimeoutInMillis = operationTimeoutInMillis;
424 public Builder dataStoreMXBeanType(final String dataStoreMXBeanType) {
425 datastoreContext.dataStoreMXBeanType = dataStoreMXBeanType;
429 public Builder shardTransactionCommitTimeoutInSeconds(final int shardTransactionCommitTimeoutInSeconds) {
430 datastoreContext.shardTransactionCommitTimeoutInSeconds = shardTransactionCommitTimeoutInSeconds;
434 public Builder shardJournalRecoveryLogBatchSize(final int shardJournalRecoveryLogBatchSize) {
435 datastoreContext.setShardJournalRecoveryLogBatchSize(shardJournalRecoveryLogBatchSize);
439 public Builder shardSnapshotBatchCount(final int shardSnapshotBatchCount) {
440 datastoreContext.setSnapshotBatchCount(shardSnapshotBatchCount);
444 public Builder shardSnapshotDataThresholdPercentage(final int shardSnapshotDataThresholdPercentage) {
445 datastoreContext.setSnapshotDataThresholdPercentage(shardSnapshotDataThresholdPercentage);
449 public Builder shardHeartbeatIntervalInMillis(final int shardHeartbeatIntervalInMillis) {
450 datastoreContext.setHeartbeatInterval(shardHeartbeatIntervalInMillis);
454 public Builder shardTransactionCommitQueueCapacity(final int shardTransactionCommitQueueCapacity) {
455 datastoreContext.shardTransactionCommitQueueCapacity = shardTransactionCommitQueueCapacity;
459 public Builder shardInitializationTimeout(final long timeout, final TimeUnit unit) {
460 datastoreContext.shardInitializationTimeout = new Timeout(timeout, unit);
464 public Builder shardInitializationTimeoutInSeconds(final long timeout) {
465 return shardInitializationTimeout(timeout, TimeUnit.SECONDS);
468 public Builder shardLeaderElectionTimeout(final long timeout, final TimeUnit unit) {
469 datastoreContext.shardLeaderElectionTimeout = new Timeout(timeout, unit);
473 public Builder initialSettleTimeoutMultiplier(final int multiplier) {
474 checkArgument(multiplier >= 0);
475 datastoreContext.initialSettleTimeoutMultiplier = multiplier;
479 public Builder shardLeaderElectionTimeoutInSeconds(final long timeout) {
480 return shardLeaderElectionTimeout(timeout, TimeUnit.SECONDS);
483 public Builder configurationReader(final AkkaConfigurationReader configurationReader) {
484 datastoreContext.configurationReader = configurationReader;
488 public Builder persistent(final boolean persistent) {
489 datastoreContext.persistent = persistent;
493 public Builder shardIsolatedLeaderCheckIntervalInMillis(final int shardIsolatedLeaderCheckIntervalInMillis) {
494 datastoreContext.setIsolatedLeaderCheckInterval(shardIsolatedLeaderCheckIntervalInMillis);
498 public Builder shardElectionTimeoutFactor(final long shardElectionTimeoutFactor) {
499 datastoreContext.setElectionTimeoutFactor(shardElectionTimeoutFactor);
503 public Builder shardCandidateElectionTimeoutDivisor(final long candidateElectionTimeoutDivisor) {
504 datastoreContext.setCandidateElectionTimeoutDivisor(candidateElectionTimeoutDivisor);
508 public Builder transactionCreationInitialRateLimit(final long initialRateLimit) {
509 datastoreContext.transactionCreationInitialRateLimit = initialRateLimit;
513 public Builder logicalStoreType(final LogicalDatastoreType logicalStoreType) {
514 datastoreContext.logicalStoreType = requireNonNull(logicalStoreType);
516 // Retain compatible naming
517 switch (logicalStoreType) {
519 dataStoreName("config");
522 dataStoreName("operational");
525 dataStoreName(logicalStoreType.name());
531 public Builder storeRoot(final YangInstanceIdentifier storeRoot) {
532 datastoreContext.storeRoot = storeRoot;
536 public Builder dataStoreName(final String dataStoreName) {
537 datastoreContext.dataStoreName = requireNonNull(dataStoreName);
538 datastoreContext.dataStoreMXBeanType = "Distributed" + WordUtils.capitalize(dataStoreName) + "Datastore";
542 public Builder shardBatchedModificationCount(final int shardBatchedModificationCount) {
543 datastoreContext.shardBatchedModificationCount = shardBatchedModificationCount;
547 public Builder writeOnlyTransactionOptimizationsEnabled(final boolean value) {
548 datastoreContext.writeOnlyTransactionOptimizationsEnabled = value;
552 public Builder shardCommitQueueExpiryTimeoutInMillis(final long value) {
553 datastoreContext.shardCommitQueueExpiryTimeoutInMillis = value;
557 public Builder shardCommitQueueExpiryTimeoutInSeconds(final long value) {
558 datastoreContext.shardCommitQueueExpiryTimeoutInMillis = TimeUnit.MILLISECONDS.convert(
559 value, TimeUnit.SECONDS);
563 public Builder transactionDebugContextEnabled(final boolean value) {
564 datastoreContext.transactionDebugContextEnabled = value;
568 public Builder maxShardDataChangeExecutorPoolSize(final int newMaxShardDataChangeExecutorPoolSize) {
569 this.maxShardDataChangeExecutorPoolSize = newMaxShardDataChangeExecutorPoolSize;
573 public Builder maxShardDataChangeExecutorQueueSize(final int newMaxShardDataChangeExecutorQueueSize) {
574 this.maxShardDataChangeExecutorQueueSize = newMaxShardDataChangeExecutorQueueSize;
578 public Builder maxShardDataChangeListenerQueueSize(final int newMaxShardDataChangeListenerQueueSize) {
579 this.maxShardDataChangeListenerQueueSize = newMaxShardDataChangeListenerQueueSize;
583 public Builder maxShardDataStoreExecutorQueueSize(final int newMaxShardDataStoreExecutorQueueSize) {
584 this.maxShardDataStoreExecutorQueueSize = newMaxShardDataStoreExecutorQueueSize;
588 public Builder useTellBasedProtocol(final boolean value) {
589 datastoreContext.useTellBasedProtocol = value;
594 * For unit tests only.
597 public Builder shardManagerPersistenceId(final String id) {
598 datastoreContext.shardManagerPersistenceId = id;
602 public Builder customRaftPolicyImplementation(final String customRaftPolicyImplementation) {
603 datastoreContext.setCustomRaftPolicyImplementation(customRaftPolicyImplementation);
608 public Builder shardSnapshotChunkSize(final int shardSnapshotChunkSize) {
609 LOG.warn("The shard-snapshot-chunk-size configuration parameter is deprecated - "
610 + "use maximum-message-slice-size instead");
611 datastoreContext.setShardSnapshotChunkSize(shardSnapshotChunkSize);
615 public Builder maximumMessageSliceSize(final int maximumMessageSliceSize) {
616 datastoreContext.setMaximumMessageSliceSize(maximumMessageSliceSize);
620 public Builder shardPeerAddressResolver(final PeerAddressResolver resolver) {
621 datastoreContext.setPeerAddressResolver(resolver);
625 public Builder tempFileDirectory(final String tempFileDirectory) {
626 datastoreContext.setTempFileDirectory(tempFileDirectory);
630 public Builder fileBackedStreamingThresholdInMegabytes(final int fileBackedStreamingThreshold) {
631 datastoreContext.setFileBackedStreamingThreshold(fileBackedStreamingThreshold * ConfigParams.MEGABYTE);
635 public Builder syncIndexThreshold(final long syncIndexThreshold) {
636 datastoreContext.setSyncIndexThreshold(syncIndexThreshold);
640 public Builder backendAlivenessTimerIntervalInSeconds(final long interval) {
641 datastoreContext.backendAlivenessTimerInterval = TimeUnit.SECONDS.toNanos(interval);
645 public Builder frontendRequestTimeoutInSeconds(final long timeout) {
646 datastoreContext.requestTimeout = TimeUnit.SECONDS.toNanos(timeout);
650 public Builder frontendNoProgressTimeoutInSeconds(final long timeout) {
651 datastoreContext.noProgressTimeout = TimeUnit.SECONDS.toNanos(timeout);
655 public Builder initialPayloadSerializedBufferCapacity(final int capacity) {
656 datastoreContext.initialPayloadSerializedBufferCapacity = capacity;
661 public DatastoreContext build() {
662 datastoreContext.dataStoreProperties = InMemoryDOMDataStoreConfigProperties.builder()
663 .maxDataChangeExecutorPoolSize(maxShardDataChangeExecutorPoolSize)
664 .maxDataChangeExecutorQueueSize(maxShardDataChangeExecutorQueueSize)
665 .maxDataChangeListenerQueueSize(maxShardDataChangeListenerQueueSize)
666 .maxDataStoreExecutorQueueSize(maxShardDataStoreExecutorQueueSize)
669 if (datastoreContext.dataStoreName != null) {
670 GLOBAL_DATASTORE_NAMES.add(datastoreContext.dataStoreName);
673 return datastoreContext;