X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2FDatastoreContext.java;h=0536e4b15a382c4913fa29ee292dcfc6c9b4b12f;hp=01e42dbb8e92400b7f4af73d55257d6f9ebbe4a2;hb=925cb4a228d0fda99c7bfeb432eb25285a223887;hpb=7fcaf37fb411e26859ad761b329af1df9dd46c13 diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContext.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContext.java index 01e42dbb8e..0536e4b15a 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContext.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/DatastoreContext.java @@ -9,11 +9,18 @@ package org.opendaylight.controller.cluster.datastore; import akka.util.Timeout; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import com.google.common.collect.Sets; +import java.util.Set; import java.util.concurrent.TimeUnit; -import org.opendaylight.controller.cluster.datastore.config.ConfigurationReader; -import org.opendaylight.controller.cluster.datastore.config.FileConfigurationReader; +import org.apache.commons.lang3.text.WordUtils; +import org.opendaylight.controller.cluster.common.actor.AkkaConfigurationReader; +import org.opendaylight.controller.cluster.common.actor.FileAkkaConfigurationReader; import org.opendaylight.controller.cluster.raft.ConfigParams; import org.opendaylight.controller.cluster.raft.DefaultConfigParamsImpl; +import org.opendaylight.controller.cluster.raft.PeerAddressResolver; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStoreConfigProperties; import scala.concurrent.duration.Duration; import scala.concurrent.duration.FiniteDuration; @@ -24,42 +31,103 @@ import scala.concurrent.duration.FiniteDuration; * @author Thomas Pantelis */ public class DatastoreContext { + public static final String METRICS_DOMAIN = "org.opendaylight.controller.cluster.datastore"; + + public static final Duration DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT = Duration.create(10, TimeUnit.MINUTES); + public static final int DEFAULT_OPERATION_TIMEOUT_IN_MS = 5000; + public static final int DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS = 30; + public static final int DEFAULT_JOURNAL_RECOVERY_BATCH_SIZE = 1; + public static final int DEFAULT_SNAPSHOT_BATCH_COUNT = 20000; + public static final int DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS = 500; + public static final int DEFAULT_ISOLATED_LEADER_CHECK_INTERVAL_IN_MILLIS = + DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS * 10; + public static final int DEFAULT_SHARD_TX_COMMIT_QUEUE_CAPACITY = 50000; + public static final Timeout DEFAULT_SHARD_INITIALIZATION_TIMEOUT = new Timeout(5, TimeUnit.MINUTES); + public static final Timeout DEFAULT_SHARD_LEADER_ELECTION_TIMEOUT = new Timeout(30, TimeUnit.SECONDS); + public static final boolean DEFAULT_PERSISTENT = true; + public static final FileAkkaConfigurationReader DEFAULT_CONFIGURATION_READER = new FileAkkaConfigurationReader(); + public static final int DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE = 12; + public static final int DEFAULT_SHARD_ELECTION_TIMEOUT_FACTOR = 2; + public static final int DEFAULT_TX_CREATION_INITIAL_RATE_LIMIT = 100; + public static final String UNKNOWN_DATA_STORE_TYPE = "unknown"; + public static final int DEFAULT_SHARD_BATCHED_MODIFICATION_COUNT = 1000; + public static final long DEFAULT_SHARD_COMMIT_QUEUE_EXPIRY_TIMEOUT_IN_MS = + TimeUnit.MILLISECONDS.convert(2, TimeUnit.MINUTES); + public static final int DEFAULT_SHARD_SNAPSHOT_CHUNK_SIZE = 2048000; + + private static final Set GLOBAL_DATASTORE_NAMES = Sets.newConcurrentHashSet(); + + private InMemoryDOMDataStoreConfigProperties dataStoreProperties; + private Duration shardTransactionIdleTimeout = DatastoreContext.DEFAULT_SHARD_TRANSACTION_IDLE_TIMEOUT; + private long operationTimeoutInMillis = DEFAULT_OPERATION_TIMEOUT_IN_MS; + private String dataStoreMXBeanType; + private int shardTransactionCommitTimeoutInSeconds = DEFAULT_SHARD_TX_COMMIT_TIMEOUT_IN_SECONDS; + private int shardTransactionCommitQueueCapacity = DEFAULT_SHARD_TX_COMMIT_QUEUE_CAPACITY; + private Timeout shardInitializationTimeout = DEFAULT_SHARD_INITIALIZATION_TIMEOUT; + private Timeout shardLeaderElectionTimeout = DEFAULT_SHARD_LEADER_ELECTION_TIMEOUT; + private boolean persistent = DEFAULT_PERSISTENT; + private AkkaConfigurationReader configurationReader = DEFAULT_CONFIGURATION_READER; + private long transactionCreationInitialRateLimit = DEFAULT_TX_CREATION_INITIAL_RATE_LIMIT; + private final DefaultConfigParamsImpl raftConfig = new DefaultConfigParamsImpl(); + private String dataStoreName = UNKNOWN_DATA_STORE_TYPE; + private LogicalDatastoreType logicalStoreType = LogicalDatastoreType.OPERATIONAL; + private int shardBatchedModificationCount = DEFAULT_SHARD_BATCHED_MODIFICATION_COUNT; + private boolean writeOnlyTransactionOptimizationsEnabled = true; + private long shardCommitQueueExpiryTimeoutInMillis = DEFAULT_SHARD_COMMIT_QUEUE_EXPIRY_TIMEOUT_IN_MS; + private boolean transactionDebugContextEnabled = false; + private String shardManagerPersistenceId; + + public static Set getGlobalDatastoreNames() { + return GLOBAL_DATASTORE_NAMES; + } + + private DatastoreContext() { + setShardJournalRecoveryLogBatchSize(DEFAULT_JOURNAL_RECOVERY_BATCH_SIZE); + setSnapshotBatchCount(DEFAULT_SNAPSHOT_BATCH_COUNT); + setHeartbeatInterval(DEFAULT_HEARTBEAT_INTERVAL_IN_MILLIS); + setIsolatedLeaderCheckInterval(DEFAULT_ISOLATED_LEADER_CHECK_INTERVAL_IN_MILLIS); + setSnapshotDataThresholdPercentage(DEFAULT_SHARD_SNAPSHOT_DATA_THRESHOLD_PERCENTAGE); + setElectionTimeoutFactor(DEFAULT_SHARD_ELECTION_TIMEOUT_FACTOR); + setShardSnapshotChunkSize(DEFAULT_SHARD_SNAPSHOT_CHUNK_SIZE); + } - private final InMemoryDOMDataStoreConfigProperties dataStoreProperties; - private final Duration shardTransactionIdleTimeout; - private final int operationTimeoutInSeconds; - private final String dataStoreMXBeanType; - private final ConfigParams shardRaftConfig; - private final int shardTransactionCommitTimeoutInSeconds; - private final int shardTransactionCommitQueueCapacity; - private final Timeout shardInitializationTimeout; - private final Timeout shardLeaderElectionTimeout; - private final boolean persistent; - private final ConfigurationReader configurationReader; - private final long shardElectionTimeoutFactor; - - private DatastoreContext(InMemoryDOMDataStoreConfigProperties dataStoreProperties, - ConfigParams shardRaftConfig, String dataStoreMXBeanType, int operationTimeoutInSeconds, - Duration shardTransactionIdleTimeout, int shardTransactionCommitTimeoutInSeconds, - int shardTransactionCommitQueueCapacity, Timeout shardInitializationTimeout, - Timeout shardLeaderElectionTimeout, - boolean persistent, ConfigurationReader configurationReader, long shardElectionTimeoutFactor) { - this.dataStoreProperties = dataStoreProperties; - this.shardRaftConfig = shardRaftConfig; - this.dataStoreMXBeanType = dataStoreMXBeanType; - this.operationTimeoutInSeconds = operationTimeoutInSeconds; - this.shardTransactionIdleTimeout = shardTransactionIdleTimeout; - this.shardTransactionCommitTimeoutInSeconds = shardTransactionCommitTimeoutInSeconds; - this.shardTransactionCommitQueueCapacity = shardTransactionCommitQueueCapacity; - this.shardInitializationTimeout = shardInitializationTimeout; - this.shardLeaderElectionTimeout = shardLeaderElectionTimeout; - this.persistent = persistent; - this.configurationReader = configurationReader; - this.shardElectionTimeoutFactor = shardElectionTimeoutFactor; + private DatastoreContext(DatastoreContext other) { + this.dataStoreProperties = other.dataStoreProperties; + this.shardTransactionIdleTimeout = other.shardTransactionIdleTimeout; + this.operationTimeoutInMillis = other.operationTimeoutInMillis; + this.dataStoreMXBeanType = other.dataStoreMXBeanType; + this.shardTransactionCommitTimeoutInSeconds = other.shardTransactionCommitTimeoutInSeconds; + this.shardTransactionCommitQueueCapacity = other.shardTransactionCommitQueueCapacity; + this.shardInitializationTimeout = other.shardInitializationTimeout; + this.shardLeaderElectionTimeout = other.shardLeaderElectionTimeout; + this.persistent = other.persistent; + this.configurationReader = other.configurationReader; + this.transactionCreationInitialRateLimit = other.transactionCreationInitialRateLimit; + this.dataStoreName = other.dataStoreName; + this.logicalStoreType = other.logicalStoreType; + this.shardBatchedModificationCount = other.shardBatchedModificationCount; + this.writeOnlyTransactionOptimizationsEnabled = other.writeOnlyTransactionOptimizationsEnabled; + this.shardCommitQueueExpiryTimeoutInMillis = other.shardCommitQueueExpiryTimeoutInMillis; + this.transactionDebugContextEnabled = other.transactionDebugContextEnabled; + this.shardManagerPersistenceId = other.shardManagerPersistenceId; + + setShardJournalRecoveryLogBatchSize(other.raftConfig.getJournalRecoveryLogBatchSize()); + setSnapshotBatchCount(other.raftConfig.getSnapshotBatchCount()); + setHeartbeatInterval(other.raftConfig.getHeartBeatInterval().toMillis()); + setIsolatedLeaderCheckInterval(other.raftConfig.getIsolatedCheckIntervalInMillis()); + setSnapshotDataThresholdPercentage(other.raftConfig.getSnapshotDataThresholdPercentage()); + setElectionTimeoutFactor(other.raftConfig.getElectionTimeoutFactor()); + setCustomRaftPolicyImplementation(other.raftConfig.getCustomRaftPolicyImplementationClass()); + setShardSnapshotChunkSize(other.raftConfig.getSnapshotChunkSize()); + setPeerAddressResolver(other.raftConfig.getPeerAddressResolver()); } public static Builder newBuilder() { - return new Builder(); + return new Builder(new DatastoreContext()); + } + + public static Builder newBuilderFrom(DatastoreContext context) { + return new Builder(new DatastoreContext(context)); } public InMemoryDOMDataStoreConfigProperties getDataStoreProperties() { @@ -74,12 +142,12 @@ public class DatastoreContext { return dataStoreMXBeanType; } - public int getOperationTimeoutInSeconds() { - return operationTimeoutInSeconds; + public long getOperationTimeoutInMillis() { + return operationTimeoutInMillis; } public ConfigParams getShardRaftConfig() { - return shardRaftConfig; + return raftConfig; } public int getShardTransactionCommitTimeoutInSeconds() { @@ -102,130 +170,329 @@ public class DatastoreContext { return persistent; } - public ConfigurationReader getConfigurationReader() { + public AkkaConfigurationReader getConfigurationReader() { return configurationReader; } - public long getShardElectionTimeoutFactor(){ - return this.shardElectionTimeoutFactor; + public long getShardElectionTimeoutFactor() { + return raftConfig.getElectionTimeoutFactor(); + } + + public String getDataStoreName() { + return dataStoreName; + } + + public LogicalDatastoreType getLogicalStoreType() { + return logicalStoreType; + } + + public long getTransactionCreationInitialRateLimit() { + return transactionCreationInitialRateLimit; + } + + public String getShardManagerPersistenceId() { + return shardManagerPersistenceId; + } + + private void setPeerAddressResolver(PeerAddressResolver resolver) { + raftConfig.setPeerAddressResolver(resolver); + } + + private void setHeartbeatInterval(long shardHeartbeatIntervalInMillis) { + raftConfig.setHeartBeatInterval(new FiniteDuration(shardHeartbeatIntervalInMillis, + TimeUnit.MILLISECONDS)); + } + + private void setShardJournalRecoveryLogBatchSize(int shardJournalRecoveryLogBatchSize) { + raftConfig.setJournalRecoveryLogBatchSize(shardJournalRecoveryLogBatchSize); + } + + + private void setIsolatedLeaderCheckInterval(long shardIsolatedLeaderCheckIntervalInMillis) { + raftConfig.setIsolatedLeaderCheckInterval( + new FiniteDuration(shardIsolatedLeaderCheckIntervalInMillis, TimeUnit.MILLISECONDS)); + } + + private void setElectionTimeoutFactor(long shardElectionTimeoutFactor) { + raftConfig.setElectionTimeoutFactor(shardElectionTimeoutFactor); + } + + private void setCustomRaftPolicyImplementation(String customRaftPolicyImplementation) { + raftConfig.setCustomRaftPolicyImplementationClass(customRaftPolicyImplementation); + } + + private void setSnapshotDataThresholdPercentage(int shardSnapshotDataThresholdPercentage) { + Preconditions.checkArgument(shardSnapshotDataThresholdPercentage >= 0 + && shardSnapshotDataThresholdPercentage <= 100); + raftConfig.setSnapshotDataThresholdPercentage(shardSnapshotDataThresholdPercentage); + } + + private void setSnapshotBatchCount(long shardSnapshotBatchCount) { + raftConfig.setSnapshotBatchCount(shardSnapshotBatchCount); + } + + private void setShardSnapshotChunkSize(int shardSnapshotChunkSize) { + raftConfig.setSnapshotChunkSize(shardSnapshotChunkSize); + } + + public int getShardBatchedModificationCount() { + return shardBatchedModificationCount; + } + + public boolean isWriteOnlyTransactionOptimizationsEnabled() { + return writeOnlyTransactionOptimizationsEnabled; + } + + public long getShardCommitQueueExpiryTimeoutInMillis() { + return shardCommitQueueExpiryTimeoutInMillis; + } + + public boolean isTransactionDebugContextEnabled() { + return transactionDebugContextEnabled; + } + + public int getShardSnapshotChunkSize() { + return raftConfig.getSnapshotChunkSize(); } public static class Builder { - private InMemoryDOMDataStoreConfigProperties dataStoreProperties; - private Duration shardTransactionIdleTimeout = Duration.create(10, TimeUnit.MINUTES); - private int operationTimeoutInSeconds = 5; - private String dataStoreMXBeanType; - private int shardTransactionCommitTimeoutInSeconds = 30; - private int shardJournalRecoveryLogBatchSize = 1000; - private int shardSnapshotBatchCount = 20000; - private int shardHeartbeatIntervalInMillis = 500; - private int shardTransactionCommitQueueCapacity = 20000; - private Timeout shardInitializationTimeout = new Timeout(5, TimeUnit.MINUTES); - private Timeout shardLeaderElectionTimeout = new Timeout(30, TimeUnit.SECONDS); - private boolean persistent = true; - private ConfigurationReader configurationReader = new FileConfigurationReader(); - private int shardIsolatedLeaderCheckIntervalInMillis = shardHeartbeatIntervalInMillis * 10; - private int shardSnapshotDataThresholdPercentage = 12; - private long shardElectionTimeoutFactor = 2; - - public Builder shardTransactionIdleTimeout(Duration shardTransactionIdleTimeout) { - this.shardTransactionIdleTimeout = shardTransactionIdleTimeout; + private final DatastoreContext datastoreContext; + private int maxShardDataChangeExecutorPoolSize = + InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_EXECUTOR_POOL_SIZE; + private int maxShardDataChangeExecutorQueueSize = + InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_EXECUTOR_QUEUE_SIZE; + private int maxShardDataChangeListenerQueueSize = + InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_CHANGE_LISTENER_QUEUE_SIZE; + private int maxShardDataStoreExecutorQueueSize = + InMemoryDOMDataStoreConfigProperties.DEFAULT_MAX_DATA_STORE_EXECUTOR_QUEUE_SIZE; + + private Builder(DatastoreContext datastoreContext) { + this.datastoreContext = datastoreContext; + + if (datastoreContext.getDataStoreProperties() != null) { + maxShardDataChangeExecutorPoolSize = + datastoreContext.getDataStoreProperties().getMaxDataChangeExecutorPoolSize(); + maxShardDataChangeExecutorQueueSize = + datastoreContext.getDataStoreProperties().getMaxDataChangeExecutorQueueSize(); + maxShardDataChangeListenerQueueSize = + datastoreContext.getDataStoreProperties().getMaxDataChangeListenerQueueSize(); + maxShardDataStoreExecutorQueueSize = + datastoreContext.getDataStoreProperties().getMaxDataStoreExecutorQueueSize(); + } + } + + public Builder boundedMailboxCapacity(int boundedMailboxCapacity) { + // TODO - this is defined in the yang DataStoreProperties but not currently used. + return this; + } + + public Builder enableMetricCapture(boolean enableMetricCapture) { + // TODO - this is defined in the yang DataStoreProperties but not currently used. + return this; + } + + + public Builder shardTransactionIdleTimeout(long timeout, TimeUnit unit) { + datastoreContext.shardTransactionIdleTimeout = Duration.create(timeout, unit); return this; } + public Builder shardTransactionIdleTimeoutInMinutes(long timeout) { + return shardTransactionIdleTimeout(timeout, TimeUnit.MINUTES); + } + public Builder operationTimeoutInSeconds(int operationTimeoutInSeconds) { - this.operationTimeoutInSeconds = operationTimeoutInSeconds; + datastoreContext.operationTimeoutInMillis = TimeUnit.SECONDS.toMillis(operationTimeoutInSeconds); return this; } - public Builder dataStoreMXBeanType(String dataStoreMXBeanType) { - this.dataStoreMXBeanType = dataStoreMXBeanType; + public Builder operationTimeoutInMillis(long operationTimeoutInMillis) { + datastoreContext.operationTimeoutInMillis = operationTimeoutInMillis; return this; } - public Builder dataStoreProperties(InMemoryDOMDataStoreConfigProperties dataStoreProperties) { - this.dataStoreProperties = dataStoreProperties; + public Builder dataStoreMXBeanType(String dataStoreMXBeanType) { + datastoreContext.dataStoreMXBeanType = dataStoreMXBeanType; return this; } public Builder shardTransactionCommitTimeoutInSeconds(int shardTransactionCommitTimeoutInSeconds) { - this.shardTransactionCommitTimeoutInSeconds = shardTransactionCommitTimeoutInSeconds; + datastoreContext.shardTransactionCommitTimeoutInSeconds = shardTransactionCommitTimeoutInSeconds; return this; } public Builder shardJournalRecoveryLogBatchSize(int shardJournalRecoveryLogBatchSize) { - this.shardJournalRecoveryLogBatchSize = shardJournalRecoveryLogBatchSize; + datastoreContext.setShardJournalRecoveryLogBatchSize(shardJournalRecoveryLogBatchSize); return this; } public Builder shardSnapshotBatchCount(int shardSnapshotBatchCount) { - this.shardSnapshotBatchCount = shardSnapshotBatchCount; + datastoreContext.setSnapshotBatchCount(shardSnapshotBatchCount); return this; } public Builder shardSnapshotDataThresholdPercentage(int shardSnapshotDataThresholdPercentage) { - this.shardSnapshotDataThresholdPercentage = shardSnapshotDataThresholdPercentage; + datastoreContext.setSnapshotDataThresholdPercentage(shardSnapshotDataThresholdPercentage); return this; } - public Builder shardHeartbeatIntervalInMillis(int shardHeartbeatIntervalInMillis) { - this.shardHeartbeatIntervalInMillis = shardHeartbeatIntervalInMillis; + datastoreContext.setHeartbeatInterval(shardHeartbeatIntervalInMillis); return this; } public Builder shardTransactionCommitQueueCapacity(int shardTransactionCommitQueueCapacity) { - this.shardTransactionCommitQueueCapacity = shardTransactionCommitQueueCapacity; + datastoreContext.shardTransactionCommitQueueCapacity = shardTransactionCommitQueueCapacity; return this; } public Builder shardInitializationTimeout(long timeout, TimeUnit unit) { - this.shardInitializationTimeout = new Timeout(timeout, unit); + datastoreContext.shardInitializationTimeout = new Timeout(timeout, unit); return this; } + public Builder shardInitializationTimeoutInSeconds(long timeout) { + return shardInitializationTimeout(timeout, TimeUnit.SECONDS); + } + public Builder shardLeaderElectionTimeout(long timeout, TimeUnit unit) { - this.shardLeaderElectionTimeout = new Timeout(timeout, unit); + datastoreContext.shardLeaderElectionTimeout = new Timeout(timeout, unit); return this; } - public Builder configurationReader(ConfigurationReader configurationReader){ - this.configurationReader = configurationReader; + public Builder shardLeaderElectionTimeoutInSeconds(long timeout) { + return shardLeaderElectionTimeout(timeout, TimeUnit.SECONDS); + } + + public Builder configurationReader(AkkaConfigurationReader configurationReader) { + datastoreContext.configurationReader = configurationReader; return this; } - public Builder persistent(boolean persistent){ - this.persistent = persistent; + public Builder persistent(boolean persistent) { + datastoreContext.persistent = persistent; return this; } public Builder shardIsolatedLeaderCheckIntervalInMillis(int shardIsolatedLeaderCheckIntervalInMillis) { - this.shardIsolatedLeaderCheckIntervalInMillis = shardIsolatedLeaderCheckIntervalInMillis; + datastoreContext.setIsolatedLeaderCheckInterval(shardIsolatedLeaderCheckIntervalInMillis); + return this; + } + + public Builder shardElectionTimeoutFactor(long shardElectionTimeoutFactor) { + datastoreContext.setElectionTimeoutFactor(shardElectionTimeoutFactor); + return this; + } + + public Builder transactionCreationInitialRateLimit(long initialRateLimit) { + datastoreContext.transactionCreationInitialRateLimit = initialRateLimit; + return this; + } + + public Builder logicalStoreType(LogicalDatastoreType logicalStoreType) { + datastoreContext.logicalStoreType = Preconditions.checkNotNull(logicalStoreType); + + // Retain compatible naming + switch (logicalStoreType) { + case CONFIGURATION: + dataStoreName("config"); + break; + case OPERATIONAL: + dataStoreName("operational"); + break; + default: + dataStoreName(logicalStoreType.name()); + } + + return this; + } + + public Builder dataStoreName(String dataStoreName) { + datastoreContext.dataStoreName = Preconditions.checkNotNull(dataStoreName); + datastoreContext.dataStoreMXBeanType = "Distributed" + WordUtils.capitalize(dataStoreName) + "Datastore"; + return this; + } + + public Builder shardBatchedModificationCount(int shardBatchedModificationCount) { + datastoreContext.shardBatchedModificationCount = shardBatchedModificationCount; return this; } - public Builder shardElectionTimeoutFactor(long shardElectionTimeoutFactor){ - this.shardElectionTimeoutFactor = shardElectionTimeoutFactor; + public Builder writeOnlyTransactionOptimizationsEnabled(boolean value) { + datastoreContext.writeOnlyTransactionOptimizationsEnabled = value; return this; } + public Builder shardCommitQueueExpiryTimeoutInMillis(long value) { + datastoreContext.shardCommitQueueExpiryTimeoutInMillis = value; + return this; + } + + public Builder shardCommitQueueExpiryTimeoutInSeconds(long value) { + datastoreContext.shardCommitQueueExpiryTimeoutInMillis = TimeUnit.MILLISECONDS.convert( + value, TimeUnit.SECONDS); + return this; + } + + public Builder transactionDebugContextEnabled(boolean value) { + datastoreContext.transactionDebugContextEnabled = value; + return this; + } + + public Builder maxShardDataChangeExecutorPoolSize(int maxShardDataChangeExecutorPoolSize) { + this.maxShardDataChangeExecutorPoolSize = maxShardDataChangeExecutorPoolSize; + return this; + } + + public Builder maxShardDataChangeExecutorQueueSize(int maxShardDataChangeExecutorQueueSize) { + this.maxShardDataChangeExecutorQueueSize = maxShardDataChangeExecutorQueueSize; + return this; + } + + public Builder maxShardDataChangeListenerQueueSize(int maxShardDataChangeListenerQueueSize) { + this.maxShardDataChangeListenerQueueSize = maxShardDataChangeListenerQueueSize; + return this; + } + + public Builder maxShardDataStoreExecutorQueueSize(int maxShardDataStoreExecutorQueueSize) { + this.maxShardDataStoreExecutorQueueSize = maxShardDataStoreExecutorQueueSize; + return this; + } + + /** + * For unit tests only. + */ + @VisibleForTesting + public Builder shardManagerPersistenceId(String id) { + datastoreContext.shardManagerPersistenceId = id; + return this; + } public DatastoreContext build() { - DefaultConfigParamsImpl raftConfig = new DefaultConfigParamsImpl(); - raftConfig.setHeartBeatInterval(new FiniteDuration(shardHeartbeatIntervalInMillis, - TimeUnit.MILLISECONDS)); - raftConfig.setJournalRecoveryLogBatchSize(shardJournalRecoveryLogBatchSize); - raftConfig.setSnapshotBatchCount(shardSnapshotBatchCount); - raftConfig.setSnapshotDataThresholdPercentage(shardSnapshotDataThresholdPercentage); - raftConfig.setElectionTimeoutFactor(shardElectionTimeoutFactor); - raftConfig.setIsolatedLeaderCheckInterval( - new FiniteDuration(shardIsolatedLeaderCheckIntervalInMillis, TimeUnit.MILLISECONDS)); + datastoreContext.dataStoreProperties = InMemoryDOMDataStoreConfigProperties.create( + maxShardDataChangeExecutorPoolSize, maxShardDataChangeExecutorQueueSize, + maxShardDataChangeListenerQueueSize, maxShardDataStoreExecutorQueueSize); + + if (datastoreContext.dataStoreName != null) { + GLOBAL_DATASTORE_NAMES.add(datastoreContext.dataStoreName); + } - return new DatastoreContext(dataStoreProperties, raftConfig, dataStoreMXBeanType, - operationTimeoutInSeconds, shardTransactionIdleTimeout, - shardTransactionCommitTimeoutInSeconds, shardTransactionCommitQueueCapacity, - shardInitializationTimeout, shardLeaderElectionTimeout, - persistent, configurationReader, shardElectionTimeoutFactor); + return datastoreContext; + } + + public Builder customRaftPolicyImplementation(String customRaftPolicyImplementation) { + datastoreContext.setCustomRaftPolicyImplementation(customRaftPolicyImplementation); + return this; + } + + public Builder shardSnapshotChunkSize(int shardSnapshotChunkSize) { + datastoreContext.setShardSnapshotChunkSize(shardSnapshotChunkSize); + return this; + } + + public Builder shardPeerAddressResolver(PeerAddressResolver resolver) { + datastoreContext.setPeerAddressResolver(resolver); + return this; } } }