public CompletableFuture<Void> join(Collection<MemberId> otherMembers) { log.info("Joining partition {} ({})", partition.id(), partition.name()); server = buildServer(); return server.join(otherMembers).whenComplete((r, e) -> { if (e == null) { log.debug("Successfully joined partition {} ({})", partition.id(), partition.name()); } else { log.warn("Failed to join partition {} ({})", partition.id(), partition.name(), e); } }).thenApply(v -> null); }
private RaftClient newRaftClient(RaftClientProtocol protocol) { return RaftClient.builder() .withClientId(partition.name()) .withPartitionId(partition.id()) .withMemberId(localMemberId) .withProtocol(protocol) .withThreadContextFactory(threadContextFactory) .build(); } }
/** * Creates a Raft client. */ private RaftPartitionClient createClient(PartitionManagementService managementService) { return new RaftPartitionClient( this, managementService.getMembershipService().getLocalMember().id(), new RaftClientCommunicator( name(), Serializer.using(RaftNamespaces.RAFT_PROTOCOL), managementService.getMessagingService()), threadContextFactory); }
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(); }