Package io.atomix.raft.partition
Class RaftPartitionGroup.Builder
java.lang.Object
io.atomix.primitive.partition.PartitionGroup.Builder<RaftPartitionGroupConfig>
io.atomix.raft.partition.RaftPartitionGroup.Builder
- All Implemented Interfaces:
Builder<ManagedPartitionGroup>
- Enclosing class:
- RaftPartitionGroup
public static class RaftPartitionGroup.Builder
extends PartitionGroup.Builder<RaftPartitionGroupConfig>
Raft partition group builder.
-
Field Summary
Fields inherited from class io.atomix.primitive.partition.PartitionGroup.Builder
config -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()withDataDirectory(File dataDir) Sets the path to the data directory.withElectionTimeout(Duration electionTimeout) Sets the election timeout.withEntryValidator(EntryValidator entryValidator) Sets the entry validator to be called when an entry is appended.withFlusherFactory(RaftLogFlusher.Factory flusherFactory) Sets theRaftLogFlusher.Factoryto create a new flushing strategy for theRaftLogwhenio.atomix.raft.storage.RaftStorage#openLog(ThreadContext)} is called.withFreeDiskSpace(long freeDiskSpace) Set the minimum free disk space (in bytes) to leave when allocating a new segmentwithHeartbeatInterval(Duration heartbeatInterval) Sets the heartbeatInterval.withJournalIndexDensity(int journalIndexDensity) withMaxAppendBatchSize(int maxAppendBatchSize) Sets the maximum batch size, which is sent per append request.withMaxAppendsPerFollower(int maxAppendsPerFollower) Sets the maximum append requests which are sent per follower at once.withMaxQuorumResponseTimeout(Duration maxQuorumResponseTimeout) If the leader is not able to reach the quorum, the leader may step down.withMembers(Member... members) Sets the Raft partition group members.withMembers(Collection<String> members) Sets the Raft partition group members.withMinStepDownFailureCount(int minStepDownFailureCount) If the leader is not able to reach the quorum, the leader may step down.withNumPartitions(int numPartitions) Sets the number of partitions.withPartitionDistributor(PartitionDistributor partitionDistributor) Sets the partition distributor to use.withPartitionSize(int partitionSize) Sets the partition size.withPreallocateSegmentFiles(boolean preallocateSegmentFiles) Sets whether segment files are pre-allocated at creation.withPreferSnapshotReplicationThreshold(int preferSnapshotReplicationThreshold) Sets the threshold for preferring snapshot replication.withPriorityElection(boolean enable) withRequestTimeout(Duration requestTimeout) Sets the timeout for all messages sent between raft replicas.withSegmentSize(long segmentSizeBytes) Sets the segment size.withSnapshotStoreFactory(ReceivableSnapshotStoreFactory persistedSnapshotStoreFactory) Sets the Raft snapshot store factory to use.
-
Constructor Details
-
Builder
-
-
Method Details
-
withMembers
Sets the Raft partition group members.- Parameters:
members- the Raft partition group members- Returns:
- the Raft partition group builder
- Throws:
NullPointerException- if the members are null
-
withMembers
Sets the Raft partition group members.- Parameters:
members- the Raft partition group members- Returns:
- the Raft partition group builder
- Throws:
NullPointerException- if the members are null
-
withNumPartitions
Sets the number of partitions.- Parameters:
numPartitions- the number of partitions- Returns:
- the Raft partition group builder
- Throws:
IllegalArgumentException- if the number of partitions is not positive
-
withPartitionSize
Sets the partition size.- Parameters:
partitionSize- the partition size- Returns:
- the Raft partition group builder
- Throws:
IllegalArgumentException- if the partition size is not positive
-
withMaxAppendsPerFollower
Sets the maximum append requests which are sent per follower at once. Default is 2.- Parameters:
maxAppendsPerFollower- the maximum appends send per follower- Returns:
- the Raft partition group builder
-
withMaxAppendBatchSize
Sets the maximum batch size, which is sent per append request. Default size is 32 KB.- Parameters:
maxAppendBatchSize- the maximum batch size per append- Returns:
- the Raft partition group builder
-
withHeartbeatInterval
Sets the heartbeatInterval. The leader will send heartbeats to a follower at this interval.- Parameters:
heartbeatInterval- the delay between two heartbeats- Returns:
- the Raft partition group builder
-
withElectionTimeout
Sets the election timeout. If a follower does not receive a heartbeat from the leader within election timeout, it can start a new leader election.- Parameters:
electionTimeout- the election timeout- Returns:
- the Raft partition group builder
-
withDataDirectory
Sets the path to the data directory.- Parameters:
dataDir- the path to the replica's data directory- Returns:
- the replica builder
-
withSegmentSize
Sets the segment size.- Parameters:
segmentSizeBytes- the segment size- Returns:
- the Raft partition group builder
-
withFreeDiskSpace
Set the minimum free disk space (in bytes) to leave when allocating a new segment- Parameters:
freeDiskSpace- free disk space in bytes- Returns:
- the Raft partition group builder
-
withFlusherFactory
Sets theRaftLogFlusher.Factoryto create a new flushing strategy for theRaftLogwhenio.atomix.raft.storage.RaftStorage#openLog(ThreadContext)} is called.- Parameters:
flusherFactory- factory to create the flushing strategy for theRaftLog- Returns:
- the Raft partition group builder
-
withSnapshotStoreFactory
public RaftPartitionGroup.Builder withSnapshotStoreFactory(ReceivableSnapshotStoreFactory persistedSnapshotStoreFactory) Sets the Raft snapshot store factory to use.- Parameters:
persistedSnapshotStoreFactory- the new snapshot store factory to use- Returns:
- the Raft partition group builder
-
withEntryValidator
Sets the entry validator to be called when an entry is appended.- Parameters:
entryValidator- the entry validator- Returns:
- the Raft Partition group builder
-
withJournalIndexDensity
-
withPriorityElection
-
withRequestTimeout
Sets the timeout for all messages sent between raft replicas.- Parameters:
requestTimeout- the timeout- Returns:
- the Raft Partition group builder
-
withMinStepDownFailureCount
If the leader is not able to reach the quorum, the leader may step down. This is triggered after minStepDownFailureCount number of requests fails to get a response from the quorum of followers as well as if the last response was received before maxQuorumResponseTime.- Parameters:
minStepDownFailureCount- The number of failures after which a leader considers stepping down.- Returns:
- the Raft Partition group builder
-
withMaxQuorumResponseTimeout
If the leader is not able to reach the quorum, the leader may step down. This is triggered * after minStepDownFailureCount number of requests fails to get a response from the quorum of * followers as well as if the last response was received before maxQuorumResponseTime.When this value is 0, it will use a default value of electionTimeout * 2.
- Parameters:
maxQuorumResponseTimeout- the quorum response timeout- Returns:
- the Raft Partition group builder
-
withPartitionDistributor
public RaftPartitionGroup.Builder withPartitionDistributor(PartitionDistributor partitionDistributor) Sets the partition distributor to use. The partition distributor determines which members will own which partitions, and ensures they are correctly replicated.- Parameters:
partitionDistributor- the partition distributor to use- Returns:
- this builder for chaining
-
withPreferSnapshotReplicationThreshold
public RaftPartitionGroup.Builder withPreferSnapshotReplicationThreshold(int preferSnapshotReplicationThreshold) Sets the threshold for preferring snapshot replication. The unit is number of records by which a follower may lag behind before the leader starts to prefer replicating snapshots instead of records.- Parameters:
preferSnapshotReplicationThreshold- the threshold to use- Returns:
- this builder for chaining
-
withPreallocateSegmentFiles
Sets whether segment files are pre-allocated at creation. If true, segment files are pre-allocated to the maximum segment size (seewithSegmentSize(long)) at creation before any writes happen.- Parameters:
preallocateSegmentFiles- true to preallocate files, false otherwise- Returns:
- this builder for chaining
-
build
-