@Override public synchronized ServerState readState() { try{ if(this.serverStateFile.length() == 0){ return null; } byte[] stateData = new byte[Long.BYTES * 2 + Integer.BYTES]; this.read(stateData); this.serverStateFile.seek(0); ByteBuffer buffer = ByteBuffer.wrap(stateData); ServerState state = new ServerState(); state.setTerm(buffer.getLong()); state.setCommitIndex(buffer.getLong()); state.setVotedFor(buffer.getInt()); return state; }catch(IOException ioError){ this.logger.error("failed to read from the server state file", ioError); throw new RuntimeException("fatal I/O error while reading from state file", ioError); } }
@Override public synchronized ServerState readState() { try{ if(this.serverStateFile.length() == 0){ return null; } byte[] stateData = new byte[Long.BYTES * 2 + Integer.BYTES]; this.read(stateData); this.serverStateFile.seek(0); ByteBuffer buffer = ByteBuffer.wrap(stateData); ServerState state = new ServerState(); state.setTerm(buffer.getLong()); state.setCommitIndex(buffer.getLong()); state.setVotedFor(buffer.getInt()); return state; }catch(IOException ioError){ this.logger.error("failed to read from the server state file", ioError); throw new RuntimeException("fatal I/O error while reading from state file", ioError); } }
this.state.setTerm(0); this.state.setVotedFor(-1); this.state.setCommitIndex(0);
this.state.setTerm(0); this.state.setVotedFor(-1); this.state.setCommitIndex(0);
this.state.setTerm(0); this.state.setVotedFor(-1); this.state.setCommitIndex(0);
server.state.setCommitIndex(currentCommitIndex); server.snapshotAndCompact(currentCommitIndex);
this.state.setCommitIndex(snapshotSyncRequest.getSnapshot().getLastLogIndex()); this.quickCommitIndex = snapshotSyncRequest.getSnapshot().getLastLogIndex(); this.context.getServerStateManager().persistState(this.state);
server.state.setCommitIndex(currentCommitIndex); server.snapshotAndCompact(currentCommitIndex);
server.state.setCommitIndex(currentCommitIndex); server.snapshotAndCompact(currentCommitIndex);
this.state.setCommitIndex(snapshotSyncRequest.getSnapshot().getLastLogIndex()); this.quickCommitIndex = snapshotSyncRequest.getSnapshot().getLastLogIndex(); this.context.getServerStateManager().persistState(this.state);
this.state.setCommitIndex(snapshotSyncRequest.getSnapshot().getLastLogIndex()); this.quickCommitIndex = snapshotSyncRequest.getSnapshot().getLastLogIndex(); this.context.getServerStateManager().persistState(this.state);
this.leader = request.getSource(); this.state.setTerm(request.getTerm()); this.state.setCommitIndex(0); this.quickCommitIndex = 0; this.state.setVotedFor(-1);
this.leader = request.getSource(); this.state.setTerm(request.getTerm()); this.state.setCommitIndex(0); this.quickCommitIndex = 0; this.state.setVotedFor(-1);
this.leader = request.getSource(); this.state.setTerm(request.getTerm()); this.state.setCommitIndex(0); this.quickCommitIndex = 0; this.state.setVotedFor(-1);