/** * 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; }
/** * Returns a new Raft partition group builder. * * @param name the partition group name * @return a new partition group builder */ public static Builder builder(String name) { return new Builder(new RaftPartitionGroupConfig().setName(name)); }
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; }
/** * 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 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 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; }
/** * Sets the number of partitions. * * @param numPartitions the number of partitions * @return the Raft partition group builder * @throws IllegalArgumentException if the number of partitions is not positive */ public Builder withNumPartitions(int numPartitions) { config.setPartitions(numPartitions); return this; }
/** * Sets the partition size. * * @param partitionSize the partition size * @return the Raft partition group builder * @throws IllegalArgumentException if the partition size is not positive */ public Builder withPartitionSize(int partitionSize) { config.setPartitionSize(partitionSize); return this; }
@Override public RaftPartitionGroupConfig newConfig() { return new RaftPartitionGroupConfig(); }
/** * Closes the partition. */ CompletableFuture<Void> close() { return closeClient() .exceptionally(v -> null) .thenCompose(v -> closeServer()) .exceptionally(v -> null); }
/** * Sets the Raft partition group members. * * @param members the Raft partition group members * @return the Raft partition group builder * @throws NullPointerException if the members are null */ public Builder withMembers(Collection<String> members) { config.setMembers(Sets.newHashSet(checkNotNull(members, "members cannot be null"))); return this; }
@Override public ManagedPartitionGroup newPartitionGroup(RaftPartitionGroupConfig config) { return new RaftPartitionGroup(config); } }
/** * Enables flush on commit. * * @return the Raft partition group builder */ public Builder withFlushOnCommit() { return withFlushOnCommit(true); }
@Override public CompletableFuture<ManagedPartitionGroup> connect(PartitionManagementService managementService) { return join(managementService); }
/** * Sets the Raft partition group members. * * @param members the Raft partition group members * @return the Raft partition group builder * @throws NullPointerException if the members are null */ public Builder withMembers(String... members) { return withMembers(Arrays.asList(members)); }
@Override public String toString() { return toStringHelper(this) .add("partitionId", id()) .toString(); } }
/** * Sets the maximum Raft log entry size. * * @param maxEntrySize the maximum Raft log entry size * @return the Raft partition group builder */ public Builder withMaxEntrySize(int maxEntrySize) { return withMaxEntrySize(new MemorySize(maxEntrySize)); }
/** * Sets the segment size. * * @param segmentSizeBytes the segment size in bytes * @return the Raft partition group builder */ public Builder withSegmentSize(long segmentSizeBytes) { return withSegmentSize(new MemorySize(segmentSizeBytes)); }
@Override public RaftPartitionGroup build() { return new RaftPartitionGroup(config); } }