/** * Sets the storage level. * * @param storageLevel the storage level * @return the Raft partition group builder */ public Builder withStorageLevel(StorageLevel storageLevel) { config.getStorageConfig().setLevel(storageLevel); return this; }
/** * Sets the maximum Raft log entry size. * * @param maxEntrySize the maximum Raft log entry size * @return the Raft partition group builder */ public Builder withMaxEntrySize(MemorySize maxEntrySize) { config.getStorageConfig().setMaxEntrySize(maxEntrySize); return this; }
/** * Sets the segment size. * * @param segmentSize the segment size * @return the Raft partition group builder */ public Builder withSegmentSize(MemorySize segmentSize) { config.getStorageConfig().setSegmentSize(segmentSize); return this; }
/** * Sets the path to the data directory. * * @param dataDir the path to the replica's data directory * @return the replica builder */ public Builder withDataDirectory(File dataDir) { config.getStorageConfig().setDirectory(new File("user.dir").toURI().relativize(dataDir.toURI()).getPath()); return this; }
/** * Sets whether to flush logs to disk on commit. * * @param flushOnCommit whether to flush logs to disk on commit * @return the Raft partition group builder */ public Builder withFlushOnCommit(boolean flushOnCommit) { config.getStorageConfig().setFlushOnCommit(flushOnCommit); return this; }
private static Collection<RaftPartition> buildPartitions( RaftPartitionGroupConfig config, ThreadContextFactory threadContextFactory) { File partitionsDir = new File(config.getStorageConfig().getDirectory(config.getName()), "partitions"); List<RaftPartition> partitions = new ArrayList<>(config.getPartitions()); for (int i = 0; i < config.getPartitions(); i++) { partitions.add(new RaftPartition( PartitionId.from(config.getName(), i + 1), config, new File(partitionsDir, String.valueOf(i + 1)), threadContextFactory)); } return partitions; }
private RaftServer buildServer() { return RaftServer.builder(localMemberId) .withName(partition.name()) .withMembershipService(membershipService) .withProtocol(new RaftServerCommunicator( partition.name(), Serializer.using(RaftNamespaces.RAFT_PROTOCOL), clusterCommunicator)) .withPrimitiveTypes(primitiveTypes) .withElectionTimeout(Duration.ofMillis(ELECTION_TIMEOUT_MILLIS)) .withHeartbeatInterval(Duration.ofMillis(HEARTBEAT_INTERVAL_MILLIS)) .withStorage(RaftStorage.builder() .withPrefix(partition.name()) .withDirectory(partition.dataDirectory()) .withStorageLevel(config.getStorageConfig().getLevel()) .withMaxSegmentSize((int) config.getStorageConfig().getSegmentSize().bytes()) .withMaxEntrySize((int) config.getStorageConfig().getMaxEntrySize().bytes()) .withFlushOnCommit(config.getStorageConfig().isFlushOnCommit()) .withDynamicCompaction(config.getCompactionConfig().isDynamic()) .withFreeDiskBuffer(config.getCompactionConfig().getFreeDiskBuffer()) .withFreeMemoryBuffer(config.getCompactionConfig().getFreeMemoryBuffer()) .withNamespace(RaftNamespaces.RAFT_STORAGE) .build()) .withThreadContextFactory(threadContextFactory) .build(); }