public ClusterServer getServer(int id){ for(ClusterServer server : this.servers){ if(server.getId() == id){ return server; } } return null; }
/** * Try to get a cluster server configuration from cluster configuration * @param id the server id * @return a cluster server configuration or null if id is not found */ public ClusterServer getServer(int id){ for(ClusterServer server : this.servers){ if(server.getId() == id){ return server; } } return null; }
/** * Try to get a cluster server configuration from cluster configuration * @param id the server id * @return a cluster server configuration or null if id is not found */ public ClusterServer getServer(int id){ for(ClusterServer server : this.servers){ if(server.getId() == id){ return server; } } return null; }
public int getId(){ return this.clusterConfig.getId(); }
public int getId(){ return this.clusterConfig.getId(); }
public int getId(){ return this.clusterConfig.getId(); }
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(); } }
this.leaderId = this.configuration.getServers().get(this.random.nextInt(this.configuration.getServers().size())).getId(); this.randomLeader = true; refreshRpcClient();
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(); }