public static byte[] messageToBytes(RaftResponseMessage response){ ByteBuffer buffer = ByteBuffer.allocate(RAFT_RESPONSE_HEADER_SIZE); buffer.put(response.getMessageType().toByte()); buffer.put(intToBytes(response.getSource())); buffer.put(intToBytes(response.getDestination())); buffer.put(longToBytes(response.getTerm())); buffer.put(longToBytes(response.getNextIndex())); buffer.put(booleanToByte(response.isAccepted())); return buffer.array(); }
public static byte[] messageToBytes(RaftResponseMessage response){ ByteBuffer buffer = ByteBuffer.allocate(RAFT_RESPONSE_HEADER_SIZE); buffer.put(response.getMessageType().toByte()); buffer.put(intToBytes(response.getSource())); buffer.put(intToBytes(response.getDestination())); buffer.put(longToBytes(response.getTerm())); buffer.put(longToBytes(response.getNextIndex())); buffer.put(booleanToByte(response.isAccepted())); return buffer.array(); }
if(response.isAccepted()){ synchronized(peer){ peer.setNextLogIndex(response.getNextIndex()); peer.setMatchedIndex(response.getNextIndex() - 1); needToCatchup = peer.clearPendingCommit() || response.getNextIndex() < this.logStore.getFirstAvailableIndex(); }else{ synchronized(peer){ if(response.getNextIndex() > 0 && peer.getNextLogIndex() > response.getNextIndex()){ peer.setNextLogIndex(response.getNextIndex()); }else{ peer.setNextLogIndex(peer.getNextLogIndex() - 1);
if(response.isAccepted()){ synchronized(peer){ peer.setNextLogIndex(response.getNextIndex()); peer.setMatchedIndex(response.getNextIndex() - 1); needToCatchup = peer.clearPendingCommit() || response.getNextIndex() < this.logStore.getFirstAvailableIndex(); }else{ synchronized(peer){ if(response.getNextIndex() > 0 && peer.getNextLogIndex() > response.getNextIndex()){ peer.setNextLogIndex(response.getNextIndex()); }else{ peer.setNextLogIndex(peer.getNextLogIndex() - 1);
if(response.isAccepted()){ synchronized(peer){ peer.setNextLogIndex(response.getNextIndex()); peer.setMatchedIndex(response.getNextIndex() - 1); needToCatchup = peer.clearPendingCommit() || response.getNextIndex() < this.logStore.getFirstAvailableIndex(); }else{ synchronized(peer){ if(response.getNextIndex() > 0 && peer.getNextLogIndex() > response.getNextIndex()){ peer.setNextLogIndex(response.getNextIndex()); }else{ peer.setNextLogIndex(peer.getNextLogIndex() - 1);
response.getDestination(), response.getMessageType(), response.getNextIndex(), response.getTerm()));
response.getDestination(), response.getMessageType(), response.getNextIndex(), response.getTerm()));
needToCatchup = false; }else{ if(response.getNextIndex() >= context.getSnapshot().getSize()){ this.logger.debug("snapshot sync is done"); peer.setNextLogIndex(context.getSnapshot().getLastLogIndex() + 1); peer.setMatchedIndex(context.getSnapshot().getLastLogIndex()); peer.setSnapshotInSync(null); needToCatchup = peer.clearPendingCommit() || response.getNextIndex() < this.logStore.getFirstAvailableIndex(); }else{ this.logger.debug("continue to sync snapshot at offset %d", response.getNextIndex()); context.setOffset(response.getNextIndex());
needToCatchup = false; }else{ if(response.getNextIndex() >= context.getSnapshot().getSize()){ this.logger.debug("snapshot sync is done"); peer.setNextLogIndex(context.getSnapshot().getLastLogIndex() + 1); peer.setMatchedIndex(context.getSnapshot().getLastLogIndex()); peer.setSnapshotInSync(null); needToCatchup = peer.clearPendingCommit() || response.getNextIndex() < this.logStore.getFirstAvailableIndex(); }else{ this.logger.debug("continue to sync snapshot at offset %d", response.getNextIndex()); context.setOffset(response.getNextIndex());
needToCatchup = false; }else{ if(response.getNextIndex() >= context.getSnapshot().getSize()){ this.logger.debug("snapshot sync is done"); peer.setNextLogIndex(context.getSnapshot().getLastLogIndex() + 1); peer.setMatchedIndex(context.getSnapshot().getLastLogIndex()); peer.setSnapshotInSync(null); needToCatchup = peer.clearPendingCommit() || response.getNextIndex() < this.logStore.getFirstAvailableIndex(); }else{ this.logger.debug("continue to sync snapshot at offset %d", response.getNextIndex()); context.setOffset(response.getNextIndex());
String.valueOf(response.isAccepted()), response.getTerm(), response.getNextIndex()); if(response.getMessageType() == RaftMessageType.SyncLogResponse){ if(this.serverToJoin != null){ this.serverToJoin.setNextLogIndex(response.getNextIndex()); this.serverToJoin.setMatchedIndex(response.getNextIndex() - 1); this.syncLogsToNewComingServer(response.getNextIndex()); if(response.getNextIndex() >= context.getSnapshot().getSize()){ this.serverToJoin.setMatchedIndex(context.getSnapshot().getLastLogIndex()); }else{ context.setOffset(response.getNextIndex()); this.logger.debug("continue to send snapshot to new server at offset %d", response.getNextIndex());
String.valueOf(response.isAccepted()), response.getTerm(), response.getNextIndex()); if(response.getMessageType() == RaftMessageType.SyncLogResponse){ if(this.serverToJoin != null){ this.serverToJoin.setNextLogIndex(response.getNextIndex()); this.serverToJoin.setMatchedIndex(response.getNextIndex() - 1); this.syncLogsToNewComingServer(response.getNextIndex()); if(response.getNextIndex() >= context.getSnapshot().getSize()){ this.serverToJoin.setMatchedIndex(context.getSnapshot().getLastLogIndex()); }else{ context.setOffset(response.getNextIndex()); this.logger.debug("continue to send snapshot to new server at offset %d", response.getNextIndex());
String.valueOf(response.isAccepted()), response.getTerm(), response.getNextIndex()); if(response.getMessageType() == RaftMessageType.SyncLogResponse){ if(this.serverToJoin != null){ this.serverToJoin.setNextLogIndex(response.getNextIndex()); this.serverToJoin.setMatchedIndex(response.getNextIndex() - 1); this.syncLogsToNewComingServer(response.getNextIndex()); if(response.getNextIndex() >= context.getSnapshot().getSize()){ this.serverToJoin.setMatchedIndex(context.getSnapshot().getLastLogIndex()); }else{ context.setOffset(response.getNextIndex()); this.logger.debug("continue to send snapshot to new server at offset %d", response.getNextIndex());
String.valueOf(response.isAccepted()), response.getTerm(), response.getNextIndex());
String.valueOf(response.isAccepted()), response.getTerm(), response.getNextIndex());
String.valueOf(response.isAccepted()), response.getTerm(), response.getNextIndex());
String.valueOf(response.isAccepted()), response.getTerm(), response.getNextIndex());
String.valueOf(response.isAccepted()), response.getTerm(), response.getNextIndex());
String.valueOf(response.isAccepted()), response.getTerm(), response.getNextIndex());