Allow incremental recovery
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / DatastoreContext.java
1 /*
2  * Copyright (c) 2014 Brocade Communications Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.datastore;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
12
13 import akka.util.Timeout;
14 import com.google.common.annotations.VisibleForTesting;
15 import java.util.Set;
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.yangtools.yang.data.api.YangInstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import scala.concurrent.duration.FiniteDuration;
31
32 /**
33  * Contains contextual data for a data store.
34  *
35  * @author Thomas Pantelis
36  */
37 // Non-final for mocking
38 public class DatastoreContext implements ClientActorConfig {
39     public static final String METRICS_DOMAIN = "org.opendaylight.controller.cluster.datastore";
40
41     public static final FiniteDuration DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT = FiniteDuration.create(10,
42         TimeUnit.MINUTES);
43     public static final int DEFAULT_OPERATION_TIMEOUT_IN_MS = 5000;
44     public static final int DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS = 30;
45     public static final int DEFAULT_JOURNAL_RECOVERY_BATCH_SIZE = 1;
46     public static final int DEFAULT_SNAPSHOT_BATCH_COUNT = 20000;
47     public static final int DEFAULT_RECOVERY_SNAPSHOT_INTERVAL_SECONDS = 0;
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;
67
68     public static final long DEFAULT_SYNC_INDEX_THRESHOLD = 10;
69
70     private static final Logger LOG = LoggerFactory.getLogger(DatastoreContext.class);
71
72     private static final Set<String> GLOBAL_DATASTORE_NAMES = ConcurrentHashMap.newKeySet();
73
74     private final DefaultConfigParamsImpl raftConfig = new DefaultConfigParamsImpl();
75
76     private FiniteDuration shardTransactionIdleTimeout = DatastoreContext.DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT;
77     private long operationTimeoutInMillis = DEFAULT_OPERATION_TIMEOUT_IN_MS;
78     private String dataStoreMXBeanType;
79     private int shardTransactionCommitTimeoutInSeconds = DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS;
80     private int shardTransactionCommitQueueCapacity = DEFAULT_SHARD_TX_COMMIT_QUEUE_CAPACITY;
81     private Timeout shardInitializationTimeout = DEFAULT_SHARD_INITIALIZATION_TIMEOUT;
82     private Timeout shardLeaderElectionTimeout = DEFAULT_SHARD_LEADER_ELECTION_TIMEOUT;
83     private int initialSettleTimeoutMultiplier = DEFAULT_INITIAL_SETTLE_TIMEOUT_MULTIPLIER;
84     private boolean persistent = DEFAULT_PERSISTENT;
85     private AkkaConfigurationReader configurationReader = DEFAULT_CONFIGURATION_READER;
86     private long transactionCreationInitialRateLimit = DEFAULT_TX_CREATION_INITIAL_RATE_LIMIT;
87     private String dataStoreName = UNKNOWN_DATA_STORE_TYPE;
88     private LogicalDatastoreType logicalStoreType = LogicalDatastoreType.OPERATIONAL;
89     private YangInstanceIdentifier storeRoot = YangInstanceIdentifier.empty();
90     private int shardBatchedModificationCount = DEFAULT_SHARD_BATCHED_MODIFICATION_COUNT;
91     private boolean writeOnlyTransactionOptimizationsEnabled = true;
92     private long shardCommitQueueExpiryTimeoutInMillis = DEFAULT_SHARD_COMMIT_QUEUE_EXPIRY_TIMEOUT_IN_MS;
93     private boolean useTellBasedProtocol = false;
94     private boolean transactionDebugContextEnabled = false;
95     private String shardManagerPersistenceId;
96     private int maximumMessageSliceSize = DEFAULT_MAX_MESSAGE_SLICE_SIZE;
97     private long backendAlivenessTimerInterval = AbstractClientConnection.DEFAULT_BACKEND_ALIVE_TIMEOUT_NANOS;
98     private long requestTimeout = AbstractClientConnection.DEFAULT_REQUEST_TIMEOUT_NANOS;
99     private long noProgressTimeout = AbstractClientConnection.DEFAULT_NO_PROGRESS_TIMEOUT_NANOS;
100     private int initialPayloadSerializedBufferCapacity = DEFAULT_INITIAL_PAYLOAD_SERIALIZED_BUFFER_CAPACITY;
101
102     public static Set<String> getGlobalDatastoreNames() {
103         return GLOBAL_DATASTORE_NAMES;
104     }
105
106     DatastoreContext() {
107         setShardJournalRecoveryLogBatchSize(DEFAULT_JOURNAL_RECOVERY_BATCH_SIZE);
108         setSnapshotBatchCount(DEFAULT_SNAPSHOT_BATCH_COUNT);
109         setRecoverySnapshotIntervalSeconds(DEFAULT_RECOVERY_SNAPSHOT_INTERVAL_SECONDS);
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);
117     }
118
119     private DatastoreContext(final DatastoreContext other) {
120         this.shardTransactionIdleTimeout = other.shardTransactionIdleTimeout;
121         this.operationTimeoutInMillis = other.operationTimeoutInMillis;
122         this.dataStoreMXBeanType = other.dataStoreMXBeanType;
123         this.shardTransactionCommitTimeoutInSeconds = other.shardTransactionCommitTimeoutInSeconds;
124         this.shardTransactionCommitQueueCapacity = other.shardTransactionCommitQueueCapacity;
125         this.shardInitializationTimeout = other.shardInitializationTimeout;
126         this.shardLeaderElectionTimeout = other.shardLeaderElectionTimeout;
127         this.initialSettleTimeoutMultiplier = other.initialSettleTimeoutMultiplier;
128         this.persistent = other.persistent;
129         this.configurationReader = other.configurationReader;
130         this.transactionCreationInitialRateLimit = other.transactionCreationInitialRateLimit;
131         this.dataStoreName = other.dataStoreName;
132         this.logicalStoreType = other.logicalStoreType;
133         this.storeRoot = other.storeRoot;
134         this.shardBatchedModificationCount = other.shardBatchedModificationCount;
135         this.writeOnlyTransactionOptimizationsEnabled = other.writeOnlyTransactionOptimizationsEnabled;
136         this.shardCommitQueueExpiryTimeoutInMillis = other.shardCommitQueueExpiryTimeoutInMillis;
137         this.transactionDebugContextEnabled = other.transactionDebugContextEnabled;
138         this.shardManagerPersistenceId = other.shardManagerPersistenceId;
139         this.useTellBasedProtocol = other.useTellBasedProtocol;
140         this.backendAlivenessTimerInterval = other.backendAlivenessTimerInterval;
141         this.requestTimeout = other.requestTimeout;
142         this.noProgressTimeout = other.noProgressTimeout;
143         this.initialPayloadSerializedBufferCapacity = other.initialPayloadSerializedBufferCapacity;
144
145         setShardJournalRecoveryLogBatchSize(other.raftConfig.getJournalRecoveryLogBatchSize());
146         setSnapshotBatchCount(other.raftConfig.getSnapshotBatchCount());
147         setRecoverySnapshotIntervalSeconds(other.raftConfig.getRecoverySnapshotIntervalSeconds());
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());
160     }
161
162     public static Builder newBuilder() {
163         return new Builder(new DatastoreContext());
164     }
165
166     public static Builder newBuilderFrom(final DatastoreContext context) {
167         return new Builder(new DatastoreContext(context));
168     }
169
170     public FiniteDuration getShardTransactionIdleTimeout() {
171         return shardTransactionIdleTimeout;
172     }
173
174     public String getDataStoreMXBeanType() {
175         return dataStoreMXBeanType;
176     }
177
178     public long getOperationTimeoutInMillis() {
179         return operationTimeoutInMillis;
180     }
181
182     public ConfigParams getShardRaftConfig() {
183         return raftConfig;
184     }
185
186     public int getShardTransactionCommitTimeoutInSeconds() {
187         return shardTransactionCommitTimeoutInSeconds;
188     }
189
190     public int getShardTransactionCommitQueueCapacity() {
191         return shardTransactionCommitQueueCapacity;
192     }
193
194     public Timeout getShardInitializationTimeout() {
195         return shardInitializationTimeout;
196     }
197
198     public Timeout getShardLeaderElectionTimeout() {
199         return shardLeaderElectionTimeout;
200     }
201
202     /**
203      * Return the multiplier of {@link #getShardLeaderElectionTimeout()} which the frontend will wait for all shards
204      * on the local node to settle.
205      *
206      * @return Non-negative multiplier. Value of {@code 0} indicates to wait indefinitely.
207      */
208     public int getInitialSettleTimeoutMultiplier() {
209         return initialSettleTimeoutMultiplier;
210     }
211
212     public boolean isPersistent() {
213         return persistent;
214     }
215
216     public AkkaConfigurationReader getConfigurationReader() {
217         return configurationReader;
218     }
219
220     public long getShardElectionTimeoutFactor() {
221         return raftConfig.getElectionTimeoutFactor();
222     }
223
224     public String getDataStoreName() {
225         return dataStoreName;
226     }
227
228     public LogicalDatastoreType getLogicalStoreType() {
229         return logicalStoreType;
230     }
231
232     public YangInstanceIdentifier getStoreRoot() {
233         return storeRoot;
234     }
235
236     public long getTransactionCreationInitialRateLimit() {
237         return transactionCreationInitialRateLimit;
238     }
239
240     public String getShardManagerPersistenceId() {
241         return shardManagerPersistenceId;
242     }
243
244     @Override
245     public String getTempFileDirectory() {
246         return raftConfig.getTempFileDirectory();
247     }
248
249     private void setTempFileDirectory(final String tempFileDirectory) {
250         raftConfig.setTempFileDirectory(tempFileDirectory);
251     }
252
253     @Override
254     public int getFileBackedStreamingThreshold() {
255         return raftConfig.getFileBackedStreamingThreshold();
256     }
257
258     private void setFileBackedStreamingThreshold(final int fileBackedStreamingThreshold) {
259         raftConfig.setFileBackedStreamingThreshold(fileBackedStreamingThreshold);
260     }
261
262     private void setPeerAddressResolver(final PeerAddressResolver resolver) {
263         raftConfig.setPeerAddressResolver(resolver);
264     }
265
266     private void setHeartbeatInterval(final long shardHeartbeatIntervalInMillis) {
267         raftConfig.setHeartBeatInterval(new FiniteDuration(shardHeartbeatIntervalInMillis,
268                 TimeUnit.MILLISECONDS));
269     }
270
271     private void setShardJournalRecoveryLogBatchSize(final int shardJournalRecoveryLogBatchSize) {
272         raftConfig.setJournalRecoveryLogBatchSize(shardJournalRecoveryLogBatchSize);
273     }
274
275
276     private void setIsolatedLeaderCheckInterval(final long shardIsolatedLeaderCheckIntervalInMillis) {
277         raftConfig.setIsolatedLeaderCheckInterval(
278                 new FiniteDuration(shardIsolatedLeaderCheckIntervalInMillis, TimeUnit.MILLISECONDS));
279     }
280
281     private void setElectionTimeoutFactor(final long shardElectionTimeoutFactor) {
282         raftConfig.setElectionTimeoutFactor(shardElectionTimeoutFactor);
283     }
284
285     private void setCandidateElectionTimeoutDivisor(final long candidateElectionTimeoutDivisor) {
286         raftConfig.setCandidateElectionTimeoutDivisor(candidateElectionTimeoutDivisor);
287     }
288
289     private void setCustomRaftPolicyImplementation(final String customRaftPolicyImplementation) {
290         raftConfig.setCustomRaftPolicyImplementationClass(customRaftPolicyImplementation);
291     }
292
293     private void setSnapshotDataThresholdPercentage(final int shardSnapshotDataThresholdPercentage) {
294         checkArgument(shardSnapshotDataThresholdPercentage >= 0 && shardSnapshotDataThresholdPercentage <= 100);
295         raftConfig.setSnapshotDataThresholdPercentage(shardSnapshotDataThresholdPercentage);
296     }
297
298     private void setSnapshotBatchCount(final long shardSnapshotBatchCount) {
299         raftConfig.setSnapshotBatchCount(shardSnapshotBatchCount);
300     }
301
302     /**
303      * Set the interval in seconds after which a snapshot should be taken during the recovery process.
304      * 0 means don't take snapshots
305      */
306     private void setRecoverySnapshotIntervalSeconds(final int recoverySnapshotInterval) {
307         raftConfig.setRecoverySnapshotIntervalSeconds(recoverySnapshotInterval);
308     }
309
310     @Deprecated
311     private void setShardSnapshotChunkSize(final int shardSnapshotChunkSize) {
312         // We'll honor the shardSnapshotChunkSize setting for backwards compatibility but only if it doesn't exceed
313         // maximumMessageSliceSize.
314         if (shardSnapshotChunkSize < maximumMessageSliceSize) {
315             raftConfig.setSnapshotChunkSize(shardSnapshotChunkSize);
316         }
317     }
318
319     private void setMaximumMessageSliceSize(final int maximumMessageSliceSize) {
320         raftConfig.setSnapshotChunkSize(maximumMessageSliceSize);
321         this.maximumMessageSliceSize = maximumMessageSliceSize;
322     }
323
324     private void setSyncIndexThreshold(final long syncIndexThreshold) {
325         raftConfig.setSyncIndexThreshold(syncIndexThreshold);
326     }
327
328     public int getShardBatchedModificationCount() {
329         return shardBatchedModificationCount;
330     }
331
332     public boolean isWriteOnlyTransactionOptimizationsEnabled() {
333         return writeOnlyTransactionOptimizationsEnabled;
334     }
335
336     public long getShardCommitQueueExpiryTimeoutInMillis() {
337         return shardCommitQueueExpiryTimeoutInMillis;
338     }
339
340     public boolean isTransactionDebugContextEnabled() {
341         return transactionDebugContextEnabled;
342     }
343
344     public boolean isUseTellBasedProtocol() {
345         return useTellBasedProtocol;
346     }
347
348     @Override
349     public int getMaximumMessageSliceSize() {
350         return maximumMessageSliceSize;
351     }
352
353     @Override
354     public long getBackendAlivenessTimerInterval() {
355         return backendAlivenessTimerInterval;
356     }
357
358     @Override
359     public long getRequestTimeout() {
360         return requestTimeout;
361     }
362
363     @Override
364     public long getNoProgressTimeout() {
365         return noProgressTimeout;
366     }
367
368     public int getInitialPayloadSerializedBufferCapacity() {
369         return initialPayloadSerializedBufferCapacity;
370     }
371
372     public static class Builder implements org.opendaylight.yangtools.concepts.Builder<DatastoreContext> {
373         private final DatastoreContext datastoreContext;
374
375         Builder(final DatastoreContext datastoreContext) {
376             this.datastoreContext = datastoreContext;
377         }
378
379         public Builder boundedMailboxCapacity(final int boundedMailboxCapacity) {
380             // TODO - this is defined in the yang DataStoreProperties but not currently used.
381             return this;
382         }
383
384         public Builder enableMetricCapture(final boolean enableMetricCapture) {
385             // TODO - this is defined in the yang DataStoreProperties but not currently used.
386             return this;
387         }
388
389
390         public Builder shardTransactionIdleTimeout(final long timeout, final TimeUnit unit) {
391             datastoreContext.shardTransactionIdleTimeout = FiniteDuration.create(timeout, unit);
392             return this;
393         }
394
395         public Builder shardTransactionIdleTimeoutInMinutes(final long timeout) {
396             return shardTransactionIdleTimeout(timeout, TimeUnit.MINUTES);
397         }
398
399         public Builder operationTimeoutInSeconds(final int operationTimeoutInSeconds) {
400             datastoreContext.operationTimeoutInMillis = TimeUnit.SECONDS.toMillis(operationTimeoutInSeconds);
401             return this;
402         }
403
404         public Builder operationTimeoutInMillis(final long operationTimeoutInMillis) {
405             datastoreContext.operationTimeoutInMillis = operationTimeoutInMillis;
406             return this;
407         }
408
409         public Builder dataStoreMXBeanType(final String dataStoreMXBeanType) {
410             datastoreContext.dataStoreMXBeanType = dataStoreMXBeanType;
411             return this;
412         }
413
414         public Builder shardTransactionCommitTimeoutInSeconds(final int shardTransactionCommitTimeoutInSeconds) {
415             datastoreContext.shardTransactionCommitTimeoutInSeconds = shardTransactionCommitTimeoutInSeconds;
416             return this;
417         }
418
419         public Builder shardJournalRecoveryLogBatchSize(final int shardJournalRecoveryLogBatchSize) {
420             datastoreContext.setShardJournalRecoveryLogBatchSize(shardJournalRecoveryLogBatchSize);
421             return this;
422         }
423
424         public Builder shardSnapshotBatchCount(final int shardSnapshotBatchCount) {
425             datastoreContext.setSnapshotBatchCount(shardSnapshotBatchCount);
426             return this;
427         }
428
429         public Builder recoverySnapshotIntervalSeconds(final int recoverySnapshotIntervalSeconds) {
430             checkArgument(recoverySnapshotIntervalSeconds >= 0);
431             datastoreContext.setRecoverySnapshotIntervalSeconds(recoverySnapshotIntervalSeconds);
432             return this;
433         }
434
435         public Builder shardSnapshotDataThresholdPercentage(final int shardSnapshotDataThresholdPercentage) {
436             datastoreContext.setSnapshotDataThresholdPercentage(shardSnapshotDataThresholdPercentage);
437             return this;
438         }
439
440         public Builder shardHeartbeatIntervalInMillis(final int shardHeartbeatIntervalInMillis) {
441             datastoreContext.setHeartbeatInterval(shardHeartbeatIntervalInMillis);
442             return this;
443         }
444
445         public Builder shardTransactionCommitQueueCapacity(final int shardTransactionCommitQueueCapacity) {
446             datastoreContext.shardTransactionCommitQueueCapacity = shardTransactionCommitQueueCapacity;
447             return this;
448         }
449
450         public Builder shardInitializationTimeout(final long timeout, final TimeUnit unit) {
451             datastoreContext.shardInitializationTimeout = new Timeout(timeout, unit);
452             return this;
453         }
454
455         public Builder shardInitializationTimeoutInSeconds(final long timeout) {
456             return shardInitializationTimeout(timeout, TimeUnit.SECONDS);
457         }
458
459         public Builder shardLeaderElectionTimeout(final long timeout, final TimeUnit unit) {
460             datastoreContext.shardLeaderElectionTimeout = new Timeout(timeout, unit);
461             return this;
462         }
463
464         public Builder initialSettleTimeoutMultiplier(final int multiplier) {
465             checkArgument(multiplier >= 0);
466             datastoreContext.initialSettleTimeoutMultiplier = multiplier;
467             return this;
468         }
469
470         public Builder shardLeaderElectionTimeoutInSeconds(final long timeout) {
471             return shardLeaderElectionTimeout(timeout, TimeUnit.SECONDS);
472         }
473
474         public Builder configurationReader(final AkkaConfigurationReader configurationReader) {
475             datastoreContext.configurationReader = configurationReader;
476             return this;
477         }
478
479         public Builder persistent(final boolean persistent) {
480             datastoreContext.persistent = persistent;
481             return this;
482         }
483
484         public Builder shardIsolatedLeaderCheckIntervalInMillis(final int shardIsolatedLeaderCheckIntervalInMillis) {
485             datastoreContext.setIsolatedLeaderCheckInterval(shardIsolatedLeaderCheckIntervalInMillis);
486             return this;
487         }
488
489         public Builder shardElectionTimeoutFactor(final long shardElectionTimeoutFactor) {
490             datastoreContext.setElectionTimeoutFactor(shardElectionTimeoutFactor);
491             return this;
492         }
493
494         public Builder shardCandidateElectionTimeoutDivisor(final long candidateElectionTimeoutDivisor) {
495             datastoreContext.setCandidateElectionTimeoutDivisor(candidateElectionTimeoutDivisor);
496             return this;
497         }
498
499         public Builder transactionCreationInitialRateLimit(final long initialRateLimit) {
500             datastoreContext.transactionCreationInitialRateLimit = initialRateLimit;
501             return this;
502         }
503
504         public Builder logicalStoreType(final LogicalDatastoreType logicalStoreType) {
505             datastoreContext.logicalStoreType = requireNonNull(logicalStoreType);
506
507             // Retain compatible naming
508             switch (logicalStoreType) {
509                 case CONFIGURATION:
510                     dataStoreName("config");
511                     break;
512                 case OPERATIONAL:
513                     dataStoreName("operational");
514                     break;
515                 default:
516                     dataStoreName(logicalStoreType.name());
517             }
518
519             return this;
520         }
521
522         public Builder storeRoot(final YangInstanceIdentifier storeRoot) {
523             datastoreContext.storeRoot = storeRoot;
524             return this;
525         }
526
527         public Builder dataStoreName(final String dataStoreName) {
528             datastoreContext.dataStoreName = requireNonNull(dataStoreName);
529             datastoreContext.dataStoreMXBeanType = "Distributed" + WordUtils.capitalize(dataStoreName) + "Datastore";
530             return this;
531         }
532
533         public Builder shardBatchedModificationCount(final int shardBatchedModificationCount) {
534             datastoreContext.shardBatchedModificationCount = shardBatchedModificationCount;
535             return this;
536         }
537
538         public Builder writeOnlyTransactionOptimizationsEnabled(final boolean value) {
539             datastoreContext.writeOnlyTransactionOptimizationsEnabled = value;
540             return this;
541         }
542
543         public Builder shardCommitQueueExpiryTimeoutInMillis(final long value) {
544             datastoreContext.shardCommitQueueExpiryTimeoutInMillis = value;
545             return this;
546         }
547
548         public Builder shardCommitQueueExpiryTimeoutInSeconds(final long value) {
549             datastoreContext.shardCommitQueueExpiryTimeoutInMillis = TimeUnit.MILLISECONDS.convert(
550                     value, TimeUnit.SECONDS);
551             return this;
552         }
553
554         public Builder transactionDebugContextEnabled(final boolean value) {
555             datastoreContext.transactionDebugContextEnabled = value;
556             return this;
557         }
558
559         @Deprecated(forRemoval = true)
560         public Builder maxShardDataChangeExecutorPoolSize(final int newMaxShardDataChangeExecutorPoolSize) {
561             return this;
562         }
563
564         @Deprecated(forRemoval = true)
565         public Builder maxShardDataChangeExecutorQueueSize(final int newMaxShardDataChangeExecutorQueueSize) {
566             return this;
567         }
568
569         @Deprecated(forRemoval = true)
570         public Builder maxShardDataChangeListenerQueueSize(final int newMaxShardDataChangeListenerQueueSize) {
571             return this;
572         }
573
574         @Deprecated(forRemoval = true)
575         public Builder maxShardDataStoreExecutorQueueSize(final int newMaxShardDataStoreExecutorQueueSize) {
576             return this;
577         }
578
579         public Builder useTellBasedProtocol(final boolean value) {
580             datastoreContext.useTellBasedProtocol = value;
581             return this;
582         }
583
584         /**
585          * For unit tests only.
586          */
587         @VisibleForTesting
588         public Builder shardManagerPersistenceId(final String id) {
589             datastoreContext.shardManagerPersistenceId = id;
590             return this;
591         }
592
593         public Builder customRaftPolicyImplementation(final String customRaftPolicyImplementation) {
594             datastoreContext.setCustomRaftPolicyImplementation(customRaftPolicyImplementation);
595             return this;
596         }
597
598         @Deprecated
599         public Builder shardSnapshotChunkSize(final int shardSnapshotChunkSize) {
600             LOG.warn("The shard-snapshot-chunk-size configuration parameter is deprecated - "
601                     + "use maximum-message-slice-size instead");
602             datastoreContext.setShardSnapshotChunkSize(shardSnapshotChunkSize);
603             return this;
604         }
605
606         public Builder maximumMessageSliceSize(final int maximumMessageSliceSize) {
607             datastoreContext.setMaximumMessageSliceSize(maximumMessageSliceSize);
608             return this;
609         }
610
611         public Builder shardPeerAddressResolver(final PeerAddressResolver resolver) {
612             datastoreContext.setPeerAddressResolver(resolver);
613             return this;
614         }
615
616         public Builder tempFileDirectory(final String tempFileDirectory) {
617             datastoreContext.setTempFileDirectory(tempFileDirectory);
618             return this;
619         }
620
621         public Builder fileBackedStreamingThresholdInMegabytes(final int fileBackedStreamingThreshold) {
622             datastoreContext.setFileBackedStreamingThreshold(fileBackedStreamingThreshold * ConfigParams.MEGABYTE);
623             return this;
624         }
625
626         public Builder syncIndexThreshold(final long syncIndexThreshold) {
627             datastoreContext.setSyncIndexThreshold(syncIndexThreshold);
628             return this;
629         }
630
631         public Builder backendAlivenessTimerIntervalInSeconds(final long interval) {
632             datastoreContext.backendAlivenessTimerInterval = TimeUnit.SECONDS.toNanos(interval);
633             return this;
634         }
635
636         public Builder frontendRequestTimeoutInSeconds(final long timeout) {
637             datastoreContext.requestTimeout = TimeUnit.SECONDS.toNanos(timeout);
638             return this;
639         }
640
641         public Builder frontendNoProgressTimeoutInSeconds(final long timeout) {
642             datastoreContext.noProgressTimeout = TimeUnit.SECONDS.toNanos(timeout);
643             return this;
644         }
645
646         public Builder initialPayloadSerializedBufferCapacity(final int capacity) {
647             datastoreContext.initialPayloadSerializedBufferCapacity = capacity;
648             return this;
649         }
650
651         @Override
652         public DatastoreContext build() {
653             if (datastoreContext.dataStoreName != null) {
654                 GLOBAL_DATASTORE_NAMES.add(datastoreContext.dataStoreName);
655             }
656
657             return datastoreContext;
658         }
659     }
660 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.