public CompletableFuture<RaftResponseMessage> SendRequest(RaftRequestMessage request){ boolean isAppendRequest = request.getMessageType() == RaftMessageType.AppendEntriesRequest || request.getMessageType() == RaftMessageType.InstallSnapshotRequest; return this.rpcClient.send(request) .thenComposeAsync((RaftResponseMessage response) -> { if(isAppendRequest){ this.setFree(); } this.resumeHeartbeatingSpeed(); return CompletableFuture.completedFuture(response); }, this.executor) .exceptionally((Throwable error) -> { if(isAppendRequest){ this.setFree(); } this.slowDownHeartbeating(); throw new RpcException(error, request); }); }
public CompletableFuture<RaftResponseMessage> SendRequest(RaftRequestMessage request){ boolean isAppendRequest = request.getMessageType() == RaftMessageType.AppendEntriesRequest || request.getMessageType() == RaftMessageType.InstallSnapshotRequest; return this.rpcClient.send(request) .thenComposeAsync((RaftResponseMessage response) -> { if(isAppendRequest){ this.setFree(); } this.resumeHeartbeatingSpeed(); return CompletableFuture.completedFuture(response); }, this.executor) .exceptionally((Throwable error) -> { if(isAppendRequest){ this.setFree(); } this.slowDownHeartbeating(); throw new RpcException(error, request); }); }
public CompletableFuture<RaftResponseMessage> SendRequest(RaftRequestMessage request){ boolean isAppendRequest = request.getMessageType() == RaftMessageType.AppendEntriesRequest || request.getMessageType() == RaftMessageType.InstallSnapshotRequest; return this.rpcClient.send(request) .thenComposeAsync((RaftResponseMessage response) -> { if(isAppendRequest){ this.setFree(); } this.resumeHeartbeatingSpeed(); return CompletableFuture.completedFuture(response); }, this.executor) .exceptionally((Throwable error) -> { if(isAppendRequest){ this.setFree(); } this.slowDownHeartbeating(); throw new RpcException(error, request); }); }
private void becomeLeader(){ this.stopElectionTimer(); this.role = ServerRole.Leader; this.leader = this.id; this.serverToJoin = null; for(PeerServer server : this.peers.values()){ server.setNextLogIndex(this.logStore.getFirstAvailableIndex()); server.setSnapshotInSync(null); server.setFree(); this.enableHeartbeatForPeer(server); } // if current config is not committed, try to commit it if(this.config.getLogIndex() == 0){ this.config.setLogIndex(this.logStore.getFirstAvailableIndex()); this.logStore.append(new LogEntry(this.state.getTerm(), this.config.toBytes(), LogValueType.Configuration)); this.logger.info("add initial configuration to log store"); this.configChanging = true; } this.requestAppendEntries(); }
private void becomeLeader(){ this.stopElectionTimer(); this.role = ServerRole.Leader; this.leader = this.id; this.serverToJoin = null; for(PeerServer server : this.peers.values()){ server.setNextLogIndex(this.logStore.getFirstAvailableIndex()); server.setSnapshotInSync(null); server.setFree(); this.enableHeartbeatForPeer(server); } // if current config is not committed, try to commit it if(this.config.getLogIndex() == 0){ this.config.setLogIndex(this.logStore.getFirstAvailableIndex()); this.logStore.append(new LogEntry(this.state.getTerm(), this.config.toBytes(), LogValueType.Configuration)); this.logger.info("add initial configuration to log store"); this.configChanging = true; } this.requestAppendEntries(); }
private void becomeLeader(){ this.stopElectionTimer(); this.role = ServerRole.Leader; this.leader = this.id; this.serverToJoin = null; for(PeerServer server : this.peers.values()){ server.setNextLogIndex(this.logStore.getFirstAvailableIndex()); server.setSnapshotInSync(null); server.setFree(); this.enableHeartbeatForPeer(server); } // if current config is not committed, try to commit it if(this.config.getLogIndex() == 0){ this.config.setLogIndex(this.logStore.getFirstAvailableIndex()); this.logStore.append(new LogEntry(this.state.getTerm(), this.config.toBytes(), LogValueType.Configuration)); this.logger.info("add initial configuration to log store"); this.configChanging = true; } this.requestAppendEntries(); }