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

©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.