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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.distributed.datastore.provider.rev140612.DataStoreProperties.ExportOnRecovery;
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_RECOVERY_SNAPSHOT_INTERVAL_SECONDS = 0;
49 public static final int DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS = 500;
50 public static final int DEFAULT_ISOLATED_LEADER_CHECK_INTERVAL_IN_MILLIS =
51 DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS * 10;
52 public static final int DEFAULT_SHARD_TX_COMMIT_QUEUE_CAPACITY = 50000;
53 public static final Timeout DEFAULT_SHARD_INITIALIZATION_TIMEOUT = new Timeout(5, TimeUnit.MINUTES);
54 public static final Timeout DEFAULT_SHARD_LEADER_ELECTION_TIMEOUT = new Timeout(30, TimeUnit.SECONDS);
55 public static final int DEFAULT_INITIAL_SETTLE_TIMEOUT_MULTIPLIER = 3;
56 public static final boolean DEFAULT_PERSISTENT = true;
57 public static final boolean DEFAULT_SNAPSHOT_ON_ROOT_OVERWRITE = false;
58 public static final FileAkkaConfigurationReader DEFAULT_CONFIGURATION_READER = new FileAkkaConfigurationReader();
59 public static final int DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE = 12;
60 public static final int DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD = 0;
61 public static final int DEFAULT_SHARD_ELECTION_TIMEOUT_FACTOR = 2;
62 public static final int DEFAULT_SHARD_CANDIDATE_ELECTION_TIMEOUT_DIVISOR = 1;
63 public static final int DEFAULT_TX_CREATION_INITIAL_RATE_LIMIT = 100;
64 public static final String UNKNOWN_DATA_STORE_TYPE = "unknown";
65 public static final int DEFAULT_SHARD_BATCHED_MODIFICATION_COUNT = 1000;
66 public static final long DEFAULT_SHARD_COMMIT_QUEUE_EXPIRY_TIMEOUT_IN_MS =
67 TimeUnit.MILLISECONDS.convert(2, TimeUnit.MINUTES);
68 public static final int DEFAULT_MAX_MESSAGE_SLICE_SIZE = 480 * 1024; // 480KiB
69 public static final int DEFAULT_INITIAL_PAYLOAD_SERIALIZED_BUFFER_CAPACITY = 512;
70 public static final ExportOnRecovery DEFAULT_EXPORT_ON_RECOVERY = ExportOnRecovery.Off;
71 public static final String DEFAULT_RECOVERY_EXPORT_BASE_DIR = "persistence-export";
73 public static final long DEFAULT_SYNC_INDEX_THRESHOLD = 10;
75 private static final Logger LOG = LoggerFactory.getLogger(DatastoreContext.class);
77 private static final Set<String> GLOBAL_DATASTORE_NAMES = ConcurrentHashMap.newKeySet();
79 private final DefaultConfigParamsImpl raftConfig = new DefaultConfigParamsImpl();
81 private FiniteDuration shardTransactionIdleTimeout = DatastoreContext.DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT;
82 private long operationTimeoutInMillis = DEFAULT_OPERATION_TIMEOUT_IN_MS;
83 private String dataStoreMXBeanType;
84 private int shardTransactionCommitTimeoutInSeconds = DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS;
85 private int shardTransactionCommitQueueCapacity = DEFAULT_SHARD_TX_COMMIT_QUEUE_CAPACITY;
86 private Timeout shardInitializationTimeout = DEFAULT_SHARD_INITIALIZATION_TIMEOUT;
87 private Timeout shardLeaderElectionTimeout = DEFAULT_SHARD_LEADER_ELECTION_TIMEOUT;
88 private int initialSettleTimeoutMultiplier = DEFAULT_INITIAL_SETTLE_TIMEOUT_MULTIPLIER;
89 private boolean persistent = DEFAULT_PERSISTENT;
90 private boolean snapshotOnRootOverwrite = DEFAULT_SNAPSHOT_ON_ROOT_OVERWRITE;
91 private AkkaConfigurationReader configurationReader = DEFAULT_CONFIGURATION_READER;
92 private long transactionCreationInitialRateLimit = DEFAULT_TX_CREATION_INITIAL_RATE_LIMIT;
93 private String dataStoreName = UNKNOWN_DATA_STORE_TYPE;
94 private LogicalDatastoreType logicalStoreType = LogicalDatastoreType.OPERATIONAL;
95 private YangInstanceIdentifier storeRoot = YangInstanceIdentifier.empty();
96 private int shardBatchedModificationCount = DEFAULT_SHARD_BATCHED_MODIFICATION_COUNT;
97 private boolean writeOnlyTransactionOptimizationsEnabled = true;
98 private long shardCommitQueueExpiryTimeoutInMillis = DEFAULT_SHARD_COMMIT_QUEUE_EXPIRY_TIMEOUT_IN_MS;
99 private boolean useTellBasedProtocol = true;
100 private boolean transactionDebugContextEnabled = false;
101 private String shardManagerPersistenceId;
102 private int maximumMessageSliceSize = DEFAULT_MAX_MESSAGE_SLICE_SIZE;
103 private long backendAlivenessTimerInterval = AbstractClientConnection.DEFAULT_BACKEND_ALIVE_TIMEOUT_NANOS;
104 private long requestTimeout = AbstractClientConnection.DEFAULT_REQUEST_TIMEOUT_NANOS;
105 private long noProgressTimeout = AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS;
106 private int initialPayloadSerializedBufferCapacity = DEFAULT_INITIAL_PAYLOAD_SERIALIZED_BUFFER_CAPACITY;
107 private boolean useLz4Compression = false;
108 private ExportOnRecovery exportOnRecovery = DEFAULT_EXPORT_ON_RECOVERY;
109 private String recoveryExportBaseDir = DEFAULT_RECOVERY_EXPORT_BASE_DIR;
111 public static Set<String> getGlobalDatastoreNames() {
112 return GLOBAL_DATASTORE_NAMES;
116 setShardJournalRecoveryLogBatchSize(DEFAULT_JOURNAL_RECOVERY_BATCH_SIZE);
117 setSnapshotBatchCount(DEFAULT_SNAPSHOT_BATCH_COUNT);
118 setRecoverySnapshotIntervalSeconds(DEFAULT_RECOVERY_SNAPSHOT_INTERVAL_SECONDS);
119 setHeartbeatInterval(DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS);
120 setIsolatedLeaderCheckInterval(DEFAULT_ISOLATED_LEADER_CHECK_INTERVAL_IN_MILLIS);
121 setSnapshotDataThresholdPercentage(DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE);
122 setSnapshotDataThreshold(DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD);
123 setElectionTimeoutFactor(DEFAULT_SHARD_ELECTION_TIMEOUT_FACTOR);
124 setCandidateElectionTimeoutDivisor(DEFAULT_SHARD_CANDIDATE_ELECTION_TIMEOUT_DIVISOR);
125 setSyncIndexThreshold(DEFAULT_SYNC_INDEX_THRESHOLD);
126 setMaximumMessageSliceSize(DEFAULT_MAX_MESSAGE_SLICE_SIZE);
129 private DatastoreContext(final DatastoreContext other) {
130 shardTransactionIdleTimeout = other.shardTransactionIdleTimeout;
131 operationTimeoutInMillis = other.operationTimeoutInMillis;
132 dataStoreMXBeanType = other.dataStoreMXBeanType;
133 shardTransactionCommitTimeoutInSeconds = other.shardTransactionCommitTimeoutInSeconds;
134 shardTransactionCommitQueueCapacity = other.shardTransactionCommitQueueCapacity;
135 shardInitializationTimeout = other.shardInitializationTimeout;
136 shardLeaderElectionTimeout = other.shardLeaderElectionTimeout;
137 initialSettleTimeoutMultiplier = other.initialSettleTimeoutMultiplier;
138 persistent = other.persistent;
139 snapshotOnRootOverwrite = other.snapshotOnRootOverwrite;
140 configurationReader = other.configurationReader;
141 transactionCreationInitialRateLimit = other.transactionCreationInitialRateLimit;
142 dataStoreName = other.dataStoreName;
143 logicalStoreType = other.logicalStoreType;
144 storeRoot = other.storeRoot;
145 shardBatchedModificationCount = other.shardBatchedModificationCount;
146 writeOnlyTransactionOptimizationsEnabled = other.writeOnlyTransactionOptimizationsEnabled;
147 shardCommitQueueExpiryTimeoutInMillis = other.shardCommitQueueExpiryTimeoutInMillis;
148 transactionDebugContextEnabled = other.transactionDebugContextEnabled;
149 shardManagerPersistenceId = other.shardManagerPersistenceId;
150 useTellBasedProtocol = other.useTellBasedProtocol;
151 backendAlivenessTimerInterval = other.backendAlivenessTimerInterval;
152 requestTimeout = other.requestTimeout;
153 noProgressTimeout = other.noProgressTimeout;
154 initialPayloadSerializedBufferCapacity = other.initialPayloadSerializedBufferCapacity;
155 useLz4Compression = other.useLz4Compression;
156 exportOnRecovery = other.exportOnRecovery;
157 recoveryExportBaseDir = other.recoveryExportBaseDir;
159 setShardJournalRecoveryLogBatchSize(other.raftConfig.getJournalRecoveryLogBatchSize());
160 setSnapshotBatchCount(other.raftConfig.getSnapshotBatchCount());
161 setRecoverySnapshotIntervalSeconds(other.raftConfig.getRecoverySnapshotIntervalSeconds());
162 setHeartbeatInterval(other.raftConfig.getHeartBeatInterval().toMillis());
163 setIsolatedLeaderCheckInterval(other.raftConfig.getIsolatedCheckIntervalInMillis());
164 setSnapshotDataThresholdPercentage(other.raftConfig.getSnapshotDataThresholdPercentage());
165 setSnapshotDataThreshold(other.raftConfig.getSnapshotDataThreshold());
166 setElectionTimeoutFactor(other.raftConfig.getElectionTimeoutFactor());
167 setCandidateElectionTimeoutDivisor(other.raftConfig.getCandidateElectionTimeoutDivisor());
168 setCustomRaftPolicyImplementation(other.raftConfig.getCustomRaftPolicyImplementationClass());
169 setMaximumMessageSliceSize(other.getMaximumMessageSliceSize());
170 setShardSnapshotChunkSize(other.raftConfig.getSnapshotChunkSize());
171 setPeerAddressResolver(other.raftConfig.getPeerAddressResolver());
172 setTempFileDirectory(other.getTempFileDirectory());
173 setFileBackedStreamingThreshold(other.getFileBackedStreamingThreshold());
174 setSyncIndexThreshold(other.raftConfig.getSyncIndexThreshold());
177 public static Builder newBuilder() {
178 return new Builder(new DatastoreContext());
181 public static Builder newBuilderFrom(final DatastoreContext context) {
182 return new Builder(new DatastoreContext(context));
185 public FiniteDuration getShardTransactionIdleTimeout() {
186 return shardTransactionIdleTimeout;
189 public String getDataStoreMXBeanType() {
190 return dataStoreMXBeanType;
193 public long getOperationTimeoutInMillis() {
194 return operationTimeoutInMillis;
197 public ConfigParams getShardRaftConfig() {
201 public int getShardTransactionCommitTimeoutInSeconds() {
202 return shardTransactionCommitTimeoutInSeconds;
205 public int getShardTransactionCommitQueueCapacity() {
206 return shardTransactionCommitQueueCapacity;
209 public Timeout getShardInitializationTimeout() {
210 return shardInitializationTimeout;
213 public Timeout getShardLeaderElectionTimeout() {
214 return shardLeaderElectionTimeout;
218 * Return the multiplier of {@link #getShardLeaderElectionTimeout()} which the frontend will wait for all shards
219 * on the local node to settle.
221 * @return Non-negative multiplier. Value of {@code 0} indicates to wait indefinitely.
223 public int getInitialSettleTimeoutMultiplier() {
224 return initialSettleTimeoutMultiplier;
227 public boolean isPersistent() {
231 public boolean isSnapshotOnRootOverwrite() {
232 return snapshotOnRootOverwrite;
235 public AkkaConfigurationReader getConfigurationReader() {
236 return configurationReader;
239 public long getShardElectionTimeoutFactor() {
240 return raftConfig.getElectionTimeoutFactor();
243 public String getDataStoreName() {
244 return dataStoreName;
247 public LogicalDatastoreType getLogicalStoreType() {
248 return logicalStoreType;
251 public YangInstanceIdentifier getStoreRoot() {
255 public long getTransactionCreationInitialRateLimit() {
256 return transactionCreationInitialRateLimit;
259 public String getShardManagerPersistenceId() {
260 return shardManagerPersistenceId;
264 public String getTempFileDirectory() {
265 return raftConfig.getTempFileDirectory();
268 private void setTempFileDirectory(final String tempFileDirectory) {
269 raftConfig.setTempFileDirectory(tempFileDirectory);
273 public int getFileBackedStreamingThreshold() {
274 return raftConfig.getFileBackedStreamingThreshold();
277 private void setFileBackedStreamingThreshold(final int fileBackedStreamingThreshold) {
278 raftConfig.setFileBackedStreamingThreshold(fileBackedStreamingThreshold);
281 private void setPeerAddressResolver(final PeerAddressResolver resolver) {
282 raftConfig.setPeerAddressResolver(resolver);
285 private void setHeartbeatInterval(final long shardHeartbeatIntervalInMillis) {
286 raftConfig.setHeartBeatInterval(new FiniteDuration(shardHeartbeatIntervalInMillis,
287 TimeUnit.MILLISECONDS));
290 private void setShardJournalRecoveryLogBatchSize(final int shardJournalRecoveryLogBatchSize) {
291 raftConfig.setJournalRecoveryLogBatchSize(shardJournalRecoveryLogBatchSize);
295 private void setIsolatedLeaderCheckInterval(final long shardIsolatedLeaderCheckIntervalInMillis) {
296 raftConfig.setIsolatedLeaderCheckInterval(
297 new FiniteDuration(shardIsolatedLeaderCheckIntervalInMillis, TimeUnit.MILLISECONDS));
300 private void setElectionTimeoutFactor(final long shardElectionTimeoutFactor) {
301 raftConfig.setElectionTimeoutFactor(shardElectionTimeoutFactor);
304 private void setCandidateElectionTimeoutDivisor(final long candidateElectionTimeoutDivisor) {
305 raftConfig.setCandidateElectionTimeoutDivisor(candidateElectionTimeoutDivisor);
308 private void setCustomRaftPolicyImplementation(final String customRaftPolicyImplementation) {
309 raftConfig.setCustomRaftPolicyImplementationClass(customRaftPolicyImplementation);
312 private void setSnapshotDataThresholdPercentage(final int shardSnapshotDataThresholdPercentage) {
313 checkArgument(shardSnapshotDataThresholdPercentage >= 0 && shardSnapshotDataThresholdPercentage <= 100);
314 raftConfig.setSnapshotDataThresholdPercentage(shardSnapshotDataThresholdPercentage);
317 private void setSnapshotDataThreshold(final int shardSnapshotDataThreshold) {
318 checkArgument(shardSnapshotDataThreshold >= 0);
319 raftConfig.setSnapshotDataThreshold(shardSnapshotDataThreshold);
322 private void setSnapshotBatchCount(final long shardSnapshotBatchCount) {
323 raftConfig.setSnapshotBatchCount(shardSnapshotBatchCount);
327 * Set the interval in seconds after which a snapshot should be taken during the recovery process.
328 * 0 means don't take snapshots
330 private void setRecoverySnapshotIntervalSeconds(final int recoverySnapshotInterval) {
331 raftConfig.setRecoverySnapshotIntervalSeconds(recoverySnapshotInterval);
335 private void setShardSnapshotChunkSize(final int shardSnapshotChunkSize) {
336 // We'll honor the shardSnapshotChunkSize setting for backwards compatibility but only if it doesn't exceed
337 // maximumMessageSliceSize.
338 if (shardSnapshotChunkSize < maximumMessageSliceSize) {
339 raftConfig.setSnapshotChunkSize(shardSnapshotChunkSize);
343 private void setMaximumMessageSliceSize(final int maximumMessageSliceSize) {
344 raftConfig.setSnapshotChunkSize(maximumMessageSliceSize);
345 this.maximumMessageSliceSize = maximumMessageSliceSize;
348 private void setSyncIndexThreshold(final long syncIndexThreshold) {
349 raftConfig.setSyncIndexThreshold(syncIndexThreshold);
352 public int getShardBatchedModificationCount() {
353 return shardBatchedModificationCount;
356 public boolean isWriteOnlyTransactionOptimizationsEnabled() {
357 return writeOnlyTransactionOptimizationsEnabled;
360 public long getShardCommitQueueExpiryTimeoutInMillis() {
361 return shardCommitQueueExpiryTimeoutInMillis;
364 public boolean isTransactionDebugContextEnabled() {
365 return transactionDebugContextEnabled;
368 public boolean isUseTellBasedProtocol() {
369 return useTellBasedProtocol;
372 public boolean isUseLz4Compression() {
373 return useLz4Compression;
376 public ExportOnRecovery getExportOnRecovery() {
377 return exportOnRecovery;
380 public String getRecoveryExportBaseDir() {
381 return recoveryExportBaseDir;
385 public int getMaximumMessageSliceSize() {
386 return maximumMessageSliceSize;
390 public long getBackendAlivenessTimerInterval() {
391 return backendAlivenessTimerInterval;
395 public long getRequestTimeout() {
396 return requestTimeout;
400 public long getNoProgressTimeout() {
401 return noProgressTimeout;
404 public int getInitialPayloadSerializedBufferCapacity() {
405 return initialPayloadSerializedBufferCapacity;
408 public static class Builder {
409 private final DatastoreContext datastoreContext;
411 Builder(final DatastoreContext datastoreContext) {
412 this.datastoreContext = datastoreContext;
415 public Builder boundedMailboxCapacity(final int boundedMailboxCapacity) {
416 // TODO - this is defined in the yang DataStoreProperties but not currently used.
420 public Builder enableMetricCapture(final boolean enableMetricCapture) {
421 // TODO - this is defined in the yang DataStoreProperties but not currently used.
426 public Builder shardTransactionIdleTimeout(final long timeout, final TimeUnit unit) {
427 datastoreContext.shardTransactionIdleTimeout = FiniteDuration.create(timeout, unit);
431 public Builder shardTransactionIdleTimeoutInMinutes(final long timeout) {
432 return shardTransactionIdleTimeout(timeout, TimeUnit.MINUTES);
435 public Builder operationTimeoutInSeconds(final int operationTimeoutInSeconds) {
436 datastoreContext.operationTimeoutInMillis = TimeUnit.SECONDS.toMillis(operationTimeoutInSeconds);
440 public Builder operationTimeoutInMillis(final long operationTimeoutInMillis) {
441 datastoreContext.operationTimeoutInMillis = operationTimeoutInMillis;
445 public Builder dataStoreMXBeanType(final String dataStoreMXBeanType) {
446 datastoreContext.dataStoreMXBeanType = dataStoreMXBeanType;
450 public Builder shardTransactionCommitTimeoutInSeconds(final int shardTransactionCommitTimeoutInSeconds) {
451 datastoreContext.shardTransactionCommitTimeoutInSeconds = shardTransactionCommitTimeoutInSeconds;
455 public Builder shardJournalRecoveryLogBatchSize(final int shardJournalRecoveryLogBatchSize) {
456 datastoreContext.setShardJournalRecoveryLogBatchSize(shardJournalRecoveryLogBatchSize);
460 public Builder shardSnapshotBatchCount(final int shardSnapshotBatchCount) {
461 datastoreContext.setSnapshotBatchCount(shardSnapshotBatchCount);
465 public Builder recoverySnapshotIntervalSeconds(final int recoverySnapshotIntervalSeconds) {
466 checkArgument(recoverySnapshotIntervalSeconds >= 0);
467 datastoreContext.setRecoverySnapshotIntervalSeconds(recoverySnapshotIntervalSeconds);
471 public Builder shardSnapshotDataThresholdPercentage(final int shardSnapshotDataThresholdPercentage) {
472 datastoreContext.setSnapshotDataThresholdPercentage(shardSnapshotDataThresholdPercentage);
476 public Builder shardSnapshotDataThreshold(final int shardSnapshotDataThreshold) {
477 datastoreContext.setSnapshotDataThreshold(shardSnapshotDataThreshold);
481 public Builder shardHeartbeatIntervalInMillis(final int shardHeartbeatIntervalInMillis) {
482 datastoreContext.setHeartbeatInterval(shardHeartbeatIntervalInMillis);
486 public Builder shardTransactionCommitQueueCapacity(final int shardTransactionCommitQueueCapacity) {
487 datastoreContext.shardTransactionCommitQueueCapacity = shardTransactionCommitQueueCapacity;
491 public Builder shardInitializationTimeout(final long timeout, final TimeUnit unit) {
492 datastoreContext.shardInitializationTimeout = new Timeout(timeout, unit);
496 public Builder shardInitializationTimeoutInSeconds(final long timeout) {
497 return shardInitializationTimeout(timeout, TimeUnit.SECONDS);
500 public Builder shardLeaderElectionTimeout(final long timeout, final TimeUnit unit) {
501 datastoreContext.shardLeaderElectionTimeout = new Timeout(timeout, unit);
505 public Builder initialSettleTimeoutMultiplier(final int multiplier) {
506 checkArgument(multiplier >= 0);
507 datastoreContext.initialSettleTimeoutMultiplier = multiplier;
511 public Builder shardLeaderElectionTimeoutInSeconds(final long timeout) {
512 return shardLeaderElectionTimeout(timeout, TimeUnit.SECONDS);
515 public Builder configurationReader(final AkkaConfigurationReader configurationReader) {
516 datastoreContext.configurationReader = configurationReader;
520 public Builder persistent(final boolean persistent) {
521 datastoreContext.persistent = persistent;
525 public Builder snapshotOnRootOverwrite(final boolean snapshotOnRootOverwrite) {
526 datastoreContext.snapshotOnRootOverwrite = snapshotOnRootOverwrite;
530 public Builder shardIsolatedLeaderCheckIntervalInMillis(final int shardIsolatedLeaderCheckIntervalInMillis) {
531 datastoreContext.setIsolatedLeaderCheckInterval(shardIsolatedLeaderCheckIntervalInMillis);
535 public Builder shardElectionTimeoutFactor(final long shardElectionTimeoutFactor) {
536 datastoreContext.setElectionTimeoutFactor(shardElectionTimeoutFactor);
540 public Builder shardCandidateElectionTimeoutDivisor(final long candidateElectionTimeoutDivisor) {
541 datastoreContext.setCandidateElectionTimeoutDivisor(candidateElectionTimeoutDivisor);
545 public Builder transactionCreationInitialRateLimit(final long initialRateLimit) {
546 datastoreContext.transactionCreationInitialRateLimit = initialRateLimit;
550 public Builder logicalStoreType(final LogicalDatastoreType logicalStoreType) {
551 datastoreContext.logicalStoreType = requireNonNull(logicalStoreType);
553 // Retain compatible naming
554 switch (logicalStoreType) {
556 dataStoreName("config");
559 dataStoreName("operational");
562 dataStoreName(logicalStoreType.name());
568 public Builder storeRoot(final YangInstanceIdentifier storeRoot) {
569 datastoreContext.storeRoot = storeRoot;
573 public Builder dataStoreName(final String dataStoreName) {
574 datastoreContext.dataStoreName = requireNonNull(dataStoreName);
575 datastoreContext.dataStoreMXBeanType = "Distributed" + WordUtils.capitalize(dataStoreName) + "Datastore";
579 public Builder shardBatchedModificationCount(final int shardBatchedModificationCount) {
580 datastoreContext.shardBatchedModificationCount = shardBatchedModificationCount;
584 public Builder writeOnlyTransactionOptimizationsEnabled(final boolean value) {
585 datastoreContext.writeOnlyTransactionOptimizationsEnabled = value;
589 public Builder shardCommitQueueExpiryTimeoutInMillis(final long value) {
590 datastoreContext.shardCommitQueueExpiryTimeoutInMillis = value;
594 public Builder shardCommitQueueExpiryTimeoutInSeconds(final long value) {
595 datastoreContext.shardCommitQueueExpiryTimeoutInMillis = TimeUnit.MILLISECONDS.convert(
596 value, TimeUnit.SECONDS);
600 public Builder transactionDebugContextEnabled(final boolean value) {
601 datastoreContext.transactionDebugContextEnabled = value;
605 public Builder useTellBasedProtocol(final boolean value) {
606 datastoreContext.useTellBasedProtocol = value;
610 public Builder useLz4Compression(final boolean value) {
611 datastoreContext.useLz4Compression = value;
615 public Builder exportOnRecovery(final ExportOnRecovery value) {
616 datastoreContext.exportOnRecovery = value;
620 public Builder recoveryExportBaseDir(final String value) {
621 datastoreContext.recoveryExportBaseDir = value;
626 * For unit tests only.
629 public Builder shardManagerPersistenceId(final String id) {
630 datastoreContext.shardManagerPersistenceId = id;
634 public Builder customRaftPolicyImplementation(final String customRaftPolicyImplementation) {
635 datastoreContext.setCustomRaftPolicyImplementation(customRaftPolicyImplementation);
640 public Builder shardSnapshotChunkSize(final int shardSnapshotChunkSize) {
641 LOG.warn("The shard-snapshot-chunk-size configuration parameter is deprecated - "
642 + "use maximum-message-slice-size instead");
643 datastoreContext.setShardSnapshotChunkSize(shardSnapshotChunkSize);
647 public Builder maximumMessageSliceSize(final int maximumMessageSliceSize) {
648 datastoreContext.setMaximumMessageSliceSize(maximumMessageSliceSize);
652 public Builder shardPeerAddressResolver(final PeerAddressResolver resolver) {
653 datastoreContext.setPeerAddressResolver(resolver);
657 public Builder tempFileDirectory(final String tempFileDirectory) {
658 datastoreContext.setTempFileDirectory(tempFileDirectory);
662 public Builder fileBackedStreamingThresholdInMegabytes(final int fileBackedStreamingThreshold) {
663 datastoreContext.setFileBackedStreamingThreshold(fileBackedStreamingThreshold * ConfigParams.MEGABYTE);
667 public Builder syncIndexThreshold(final long syncIndexThreshold) {
668 datastoreContext.setSyncIndexThreshold(syncIndexThreshold);
672 public Builder backendAlivenessTimerIntervalInSeconds(final long interval) {
673 datastoreContext.backendAlivenessTimerInterval = TimeUnit.SECONDS.toNanos(interval);
677 public Builder frontendRequestTimeoutInSeconds(final long timeout) {
678 datastoreContext.requestTimeout = TimeUnit.SECONDS.toNanos(timeout);
682 public Builder frontendNoProgressTimeoutInSeconds(final long timeout) {
683 datastoreContext.noProgressTimeout = TimeUnit.SECONDS.toNanos(timeout);
687 public Builder initialPayloadSerializedBufferCapacity(final int capacity) {
688 datastoreContext.initialPayloadSerializedBufferCapacity = capacity;
692 public DatastoreContext build() {
693 if (datastoreContext.dataStoreName != null) {
694 GLOBAL_DATASTORE_NAMES.add(datastoreContext.dataStoreName);
697 return datastoreContext;