/** * Creates a Raft server. */ protected RaftPartitionServer createServer(PartitionManagementService managementService) { return new RaftPartitionServer( this, config, managementService.getMembershipService().getLocalMember().id(), managementService.getMembershipService(), managementService.getMessagingService(), managementService.getPrimitiveTypes(), threadContextFactory); }
/** * Updates the partition with the given metadata. */ CompletableFuture<Void> update(PartitionMetadata metadata, PartitionManagementService managementService) { if (server == null && metadata.members().contains(managementService.getMembershipService().getLocalMember().id())) { server = createServer(managementService); return server.join(metadata.members()); } else if (server != null && !metadata.members().contains(managementService.getMembershipService().getLocalMember().id())) { return server.leave().thenRun(() -> server = null); } return CompletableFuture.completedFuture(null); }
/** * Opens the partition. */ CompletableFuture<Partition> open(PartitionMetadata metadata, PartitionManagementService managementService) { this.partition = metadata; this.client = createClient(managementService); if (partition.members().contains(managementService.getMembershipService().getLocalMember().id())) { server = createServer(managementService); return server.start() .thenCompose(v -> client.start()) .thenApply(v -> null); } return client.start() .thenApply(v -> this); }
/** * 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 PrimaryBackupServer buildServer() { return PrimaryBackupServer.builder() .withServerName(partition.name()) .withMembershipService(managementService.getMembershipService()) .withMemberGroupProvider(memberGroupProvider) .withProtocol(new PrimaryBackupServerCommunicator( partition.name(), Serializer.using(PrimaryBackupNamespaces.PROTOCOL), managementService.getMessagingService())) .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id())) .withPrimitiveTypes(managementService.getPrimitiveTypes()) .withThreadContextFactory(threadFactory) .build(); }
private PrimaryBackupClient newClient() { return PrimaryBackupClient.builder() .withClientName(partition.name()) .withPartitionId(partition.id()) .withMembershipService(managementService.getMembershipService()) .withProtocol(new PrimaryBackupClientCommunicator( partition.name(), Serializer.using(PrimaryBackupNamespaces.PROTOCOL), managementService.getMessagingService())) .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id())) .withSessionIdProvider(managementService.getSessionIdService()) .withThreadContextFactory(threadFactory) .build(); }
private DistributedLogSessionClient newClient() { return DistributedLogSessionClient.builder() .withClientName(partition.name()) .withPartitionId(partition.id()) .withMembershipService(managementService.getMembershipService()) .withProtocol(new LogClientCommunicator( partition.name(), Serializer.using(LogNamespaces.PROTOCOL), managementService.getMessagingService())) .withSessionIdProvider(() -> managementService.getSessionIdService().nextSessionId()) .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id())) .withThreadContextFactory(threadFactory) .build(); }
private DistributedLogServer buildServer() { return DistributedLogServer.builder() .withServerName(partition.name()) .withMembershipService(managementService.getMembershipService()) .withMemberGroupProvider(config.getMemberGroupProvider()) .withProtocol(new LogServerCommunicator( partition.name(), Serializer.using(LogNamespaces.PROTOCOL), managementService.getMessagingService())) .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id())) .withStorageLevel(config.getStorageConfig().getLevel()) .withDirectory(config.getStorageConfig().getDirectory(partition.name())) .withMaxSegmentSize((int) config.getStorageConfig().getSegmentSize().bytes()) .withMaxEntrySize((int) config.getStorageConfig().getMaxEntrySize().bytes()) .withFlushOnCommit(config.getStorageConfig().isFlushOnCommit()) .withMaxLogSize(config.getCompactionConfig().getSize().bytes()) .withMaxLogAge(config.getCompactionConfig().getAge()) .withThreadContextFactory(threadFactory) .build(); }
private DistributedLogSessionClient newClient() { return DistributedLogSessionClient.builder() .withClientName(partition.name()) .withPartitionId(partition.id()) .withMembershipService(managementService.getMembershipService()) .withProtocol(new LogClientCommunicator( partition.name(), Serializer.using(LogNamespaces.PROTOCOL), managementService.getMessagingService())) .withSessionIdProvider(() -> managementService.getSessionIdService().nextSessionId()) .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id())) .withThreadContextFactory(threadFactory) .build(); }
private DistributedLogServer buildServer() { return DistributedLogServer.builder() .withServerName(partition.name()) .withMembershipService(managementService.getMembershipService()) .withMemberGroupProvider(config.getMemberGroupProvider()) .withProtocol(new LogServerCommunicator( partition.name(), Serializer.using(LogNamespaces.PROTOCOL), managementService.getMessagingService())) .withPrimaryElection(managementService.getElectionService().getElectionFor(partition.id())) .withStorageLevel(config.getStorageConfig().getLevel()) .withDirectory(config.getStorageConfig().getDirectory(partition.name())) .withMaxSegmentSize((int) config.getStorageConfig().getSegmentSize().bytes()) .withMaxEntrySize((int) config.getStorageConfig().getMaxEntrySize().bytes()) .withFlushOnCommit(config.getStorageConfig().isFlushOnCommit()) .withMaxLogSize(config.getCompactionConfig().getSize().bytes()) .withMaxLogAge(config.getCompactionConfig().getAge()) .withThreadContextFactory(threadFactory) .build(); }