public RaftClient(RpcClientFactory rpcClientFactory, ClusterConfiguration configuration, LoggerFactory loggerFactory){ this.random = new Random(Calendar.getInstance().getTimeInMillis()); this.rpcClientFactory = rpcClientFactory; this.configuration = configuration; this.leaderId = configuration.getServers().get(this.random.nextInt(configuration.getServers().size())).getId(); this.randomLeader = true; this.logger = loggerFactory.getLogger(getClass()); this.timer = new Timer(); }
public RaftClient(RpcClientFactory rpcClientFactory, ClusterConfiguration configuration, LoggerFactory loggerFactory){ this.random = new Random(Calendar.getInstance().getTimeInMillis()); this.rpcClientFactory = rpcClientFactory; this.configuration = configuration; this.leaderId = configuration.getServers().get(this.random.nextInt(configuration.getServers().size())).getId(); this.randomLeader = true; this.logger = loggerFactory.getLogger(getClass()); this.timer = new Timer(); }
public RaftClient(RpcClientFactory rpcClientFactory, ClusterConfiguration configuration, LoggerFactory loggerFactory){ this.random = new Random(Calendar.getInstance().getTimeInMillis()); this.rpcClientFactory = rpcClientFactory; this.configuration = configuration; this.leaderId = configuration.getServers().get(this.random.nextInt(configuration.getServers().size())).getId(); this.randomLeader = true; this.logger = loggerFactory.getLogger(getClass()); this.timer = new Timer(); }
private String getLeaderEndpoint(){ for(ClusterServer server : this.configuration.getServers()){ if(server.getId() == this.leaderId){ return server.getEndpoint(); } } logger.info("no endpoint could be found for leader %d, that usually means no leader is elected, retry the first one", this.leaderId); this.randomLeader = true; this.leaderId = this.configuration.getServers().get(0).getId(); return this.configuration.getServers().get(0).getEndpoint(); } }
private String getLeaderEndpoint(){ for(ClusterServer server : this.configuration.getServers()){ if(server.getId() == this.leaderId){ return server.getEndpoint(); } } logger.info("no endpoint could be found for leader %d, that usually means no leader is elected, retry the first one", this.leaderId); this.randomLeader = true; this.leaderId = this.configuration.getServers().get(0).getId(); return this.configuration.getServers().get(0).getEndpoint(); } }
private String getLeaderEndpoint(){ for(ClusterServer server : this.configuration.getServers()){ if(server.getId() == this.leaderId){ return server.getEndpoint(); } } logger.info("no endpoint could be found for leader %d, that usually means no leader is elected, retry the first one", this.leaderId); this.randomLeader = true; this.leaderId = this.configuration.getServers().get(0).getId(); return this.configuration.getServers().get(0).getEndpoint(); } }
public static ClusterConfiguration fromBytes(ByteBuffer buffer){ ClusterConfiguration configuration = new ClusterConfiguration(); configuration.setLogIndex(buffer.getLong()); configuration.setLastLogIndex(buffer.getLong()); while(buffer.hasRemaining()){ configuration.getServers().add(new ClusterServer(buffer)); } return configuration; }
/** * De-serialize the data stored in buffer to cluster configuration * this is used for the peers to get the cluster configuration from log entry value * @param buffer the binary data * @return cluster configuration */ public static ClusterConfiguration fromBytes(ByteBuffer buffer){ ClusterConfiguration configuration = new ClusterConfiguration(); configuration.setLogIndex(buffer.getLong()); configuration.setLastLogIndex(buffer.getLong()); while(buffer.hasRemaining()){ configuration.getServers().add(new ClusterServer(buffer)); } return configuration; }
/** * De-serialize the data stored in buffer to cluster configuration * this is used for the peers to get the cluster configuration from log entry value * @param buffer the binary data * @return cluster configuration */ public static ClusterConfiguration fromBytes(ByteBuffer buffer){ ClusterConfiguration configuration = new ClusterConfiguration(); configuration.setLogIndex(buffer.getLong()); configuration.setLastLogIndex(buffer.getLong()); while(buffer.hasRemaining()){ configuration.getServers().add(new ClusterServer(buffer)); } return configuration; }
if(retry > configuration.getServers().size()){ future.complete(false); return; this.leaderId = this.configuration.getServers().get(this.random.nextInt(this.configuration.getServers().size())).getId(); this.randomLeader = true; refreshRpcClient();
if(retry > configuration.getServers().size()){ future.complete(false); return; this.leaderId = this.configuration.getServers().get(this.random.nextInt(this.configuration.getServers().size())).getId(); this.randomLeader = true; refreshRpcClient();
if(retry > configuration.getServers().size()){ future.complete(false); return; this.leaderId = this.configuration.getServers().get(this.random.nextInt(this.configuration.getServers().size())).getId(); this.randomLeader = true; refreshRpcClient();
private void removeServerFromCluster(int serverId){ ClusterConfiguration newConfig = new ClusterConfiguration(); newConfig.setLastLogIndex(this.config.getLogIndex()); newConfig.setLogIndex(this.logStore.getFirstAvailableIndex()); for(ClusterServer server: this.config.getServers()){ if(server.getId() != serverId){ newConfig.getServers().add(server); } } this.logger.info("removed a server from configuration and save the configuration to log store at %d", newConfig.getLogIndex()); this.configChanging = true; this.logStore.append(new LogEntry(this.state.getTerm(), newConfig.toBytes(), LogValueType.Configuration)); this.requestAppendEntries(); }
private void removeServerFromCluster(int serverId){ ClusterConfiguration newConfig = new ClusterConfiguration(); newConfig.setLastLogIndex(this.config.getLogIndex()); newConfig.setLogIndex(this.logStore.getFirstAvailableIndex()); for(ClusterServer server: this.config.getServers()){ if(server.getId() != serverId){ newConfig.getServers().add(server); } } this.logger.info("removed a server from configuration and save the configuration to log store at %d", newConfig.getLogIndex()); this.configChanging = true; this.logStore.append(new LogEntry(this.state.getTerm(), newConfig.toBytes(), LogValueType.Configuration)); this.requestAppendEntries(); }
private void removeServerFromCluster(int serverId){ ClusterConfiguration newConfig = new ClusterConfiguration(); newConfig.setLastLogIndex(this.config.getLogIndex()); newConfig.setLogIndex(this.logStore.getFirstAvailableIndex()); for(ClusterServer server: this.config.getServers()){ if(server.getId() != serverId){ newConfig.getServers().add(server); } } this.logger.info("removed a server from configuration and save the configuration to log store at %d", newConfig.getLogIndex()); this.configChanging = true; this.logStore.append(new LogEntry(this.state.getTerm(), newConfig.toBytes(), LogValueType.Configuration)); this.requestAppendEntries(); }
newConfig.setLastLogIndex(this.config.getLogIndex()); newConfig.setLogIndex(this.logStore.getFirstAvailableIndex()); newConfig.getServers().addAll(this.config.getServers()); newConfig.getServers().add(this.serverToJoin.getClusterConfig()); LogEntry configEntry = new LogEntry(this.state.getTerm(), newConfig.toBytes(), LogValueType.Configuration); this.logStore.append(configEntry);
newConfig.setLastLogIndex(this.config.getLogIndex()); newConfig.setLogIndex(this.logStore.getFirstAvailableIndex()); newConfig.getServers().addAll(this.config.getServers()); newConfig.getServers().add(this.serverToJoin.getClusterConfig()); LogEntry configEntry = new LogEntry(this.state.getTerm(), newConfig.toBytes(), LogValueType.Configuration); this.logStore.append(configEntry);
newConfig.setLastLogIndex(this.config.getLogIndex()); newConfig.setLogIndex(this.logStore.getFirstAvailableIndex()); newConfig.getServers().addAll(this.config.getServers()); newConfig.getServers().add(this.serverToJoin.getClusterConfig()); LogEntry configEntry = new LogEntry(this.state.getTerm(), newConfig.toBytes(), LogValueType.Configuration); this.logStore.append(configEntry);
ClusterServer server = this.config.getServer(this.id); if(server != null){ this.config.getServers().remove(server); this.context.getServerStateManager().saveClusterConfiguration(this.config);
ClusterServer server = this.config.getServer(this.id); if(server != null){ this.config.getServers().remove(server); this.context.getServerStateManager().saveClusterConfiguration(this.config);