@Override public String toString() { return toStringHelper(this) .add("partitionId", id()) .toString(); } }
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); }
@Override public CompletableFuture<RaftPartitionClient> start() { synchronized (RaftPartitionClient.this) { client = newRaftClient(protocol); } return client.connect(partition.members()).whenComplete((r, e) -> { if (e == null) { log.debug("Successfully started client for partition {}", partition.id()); } else { log.warn("Failed to start client for partition {}", partition.id(), e); } }).thenApply(v -> null); }
@Override public CompletableFuture<RaftPartitionServer> start() { log.info("Starting server for partition {}", partition.id()); CompletableFuture<RaftServer> serverOpenFuture; if (partition.members().contains(localMemberId)) { if (server != null && server.isRunning()) { return CompletableFuture.completedFuture(null); } synchronized (this) { try { server = buildServer(); } catch (StorageException e) { return Futures.exceptionalFuture(e); } } serverOpenFuture = server.bootstrap(partition.members()); } else { serverOpenFuture = CompletableFuture.completedFuture(null); } return serverOpenFuture.whenComplete((r, e) -> { if (e == null) { log.debug("Successfully started server for partition {}", partition.id()); } else { log.warn("Failed to start server for partition {}", partition.id(), e); } }).thenApply(v -> this); }
public RaftPartitionGroup(RaftPartitionGroupConfig config) { Logger log = ContextualLoggerFactory.getLogger(DefaultRaftClient.class, LoggerContext.builder(RaftClient.class) .addValue(config.getName()) .build()); this.name = config.getName(); this.config = config; this.partitionSize = config.getPartitionSize(); int threadPoolSize = Math.max(Math.min(Runtime.getRuntime().availableProcessors() * 2, 16), 4); this.threadContextFactory = new BlockingAwareThreadPoolContextFactory( "raft-partition-group-" + name + "-%d", threadPoolSize, log); this.snapshotSubject = "raft-partition-group-" + name + "-snapshot"; buildPartitions(config, threadContextFactory).forEach(p -> { this.partitions.put(p.id(), p); this.sortedPartitionIds.add(p.id()); }); Collections.sort(sortedPartitionIds); }
private RaftClient newRaftClient(RaftClientProtocol protocol) { return RaftClient.builder() .withClientId(partition.name()) .withPartitionId(partition.id()) .withMemberId(localMemberId) .withProtocol(protocol) .withThreadContextFactory(threadContextFactory) .build(); } }