private static Collection<LogPartition> buildPartitions(LogPartitionGroupConfig config) { List<LogPartition> partitions = new ArrayList<>(config.getPartitions()); for (int i = 0; i < config.getPartitions(); i++) { partitions.add(new LogPartition(PartitionId.from(config.getName(), i + 1), config)); } return partitions; }
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 static Collection<PrimaryBackupPartition> buildPartitions(PrimaryBackupPartitionGroupConfig config) { List<PrimaryBackupPartition> partitions = new ArrayList<>(config.getPartitions()); for (int i = 0; i < config.getPartitions(); i++) { partitions.add(new PrimaryBackupPartition(PartitionId.from(config.getName(), i + 1), config.getMemberGroupProvider())); } return partitions; }
@Override public void run() { LOGGER.info("RaftClientThread run() >>>"); int raftClientPort = 0; try { raftClientPort = RemoteInterpreterUtils.findRandomAvailablePortOnAllLocalInterfaces(); } catch (IOException e) { LOGGER.error(e.getMessage()); } MemberId memberId = MemberId.from(ZEPL_CLIENT_ID + zeplServerHost + ":" + raftClientPort); Address address = Address.from(zeplServerHost, raftClientPort); raftAddressMap.put(memberId, address); MessagingService messagingManager = NettyMessagingService.builder().withAddress(address).build().start().join(); RaftClientProtocol protocol = new RaftClientMessagingProtocol( messagingManager, protocolSerializer, raftAddressMap::get); raftClient = RaftClient.builder() .withMemberId(memberId) .withPartitionId(PartitionId.from("partition", 1)) .withProtocol(protocol) .build(); raftClient.connect(clusterMemberIds).join(); raftSessionClient = createProxy(raftClient); LOGGER.info("RaftClientThread run() <<<"); } }).start();
/** * Creates a Raft client. */ private RaftClient createClient() throws Exception { Member member = nextNode(); RaftClientProtocol protocol; if (USE_NETTY) { MessagingService messagingService = new NettyMessagingService("test", member.address(), new MessagingConfig()).start().join(); protocol = new RaftClientMessagingProtocol(messagingService, PROTOCOL_SERIALIZER, addressMap::get); } else { protocol = protocolFactory.newClientProtocol(member.id()); } RaftClient client = RaftClient.builder() .withMemberId(member.id()) .withPartitionId(PartitionId.from("test", 1)) .withProtocol(protocol) .withThreadModel(ThreadModel.SHARED_THREAD_POOL) .build(); client.connect(members.stream().map(Member::id).collect(Collectors.toList())).join(); clients.add(client); return client; }
private static Collection<LogPartition> buildPartitions(LogPartitionGroupConfig config) { List<LogPartition> partitions = new ArrayList<>(config.getPartitions()); for (int i = 0; i < config.getPartitions(); i++) { partitions.add(new LogPartition(PartitionId.from(config.getName(), i + 1), config)); } return partitions; }