private long[] computeCommittedIndices(List<FollowerInfo> followers, boolean includeSelf) { final int length = includeSelf ? followers.size() + 1 : followers.size(); if (length == 0) { throw new IllegalArgumentException("followers.size() == " + followers.size() + " and includeSelf == " + includeSelf); } final long[] indices = new long[length]; for (int i = 0; i < followers.size(); i++) { indices[i] = followers.get(i).getMatchIndex(); } if (includeSelf) { // note that we also need to wait for the local disk I/O indices[length - 1] = raftLog.getLatestFlushedIndex(); } Arrays.sort(indices); return indices; }
@Override public String toString() { return name + "(c" + getCommitIndex() + ",m" + getMatchIndex() + ",n" + getNextIndex() + ", attendVote=" + attendVote + ", lastRpcSendTime=" + lastRpcSendTime.get().elapsedTimeMs() + ", lastRpcResponseTime=" + lastRpcResponseTime.get().elapsedTimeMs() + ")"; }
/** * So far we use a simple implementation for catchup checking: * 1. If the latest rpc time of the remote peer is before 3 * max_timeout, * the peer made no progress for that long. We should fail the whole * setConfiguration request. * 2. If the peer's matching index is just behind for a small gap, and the * peer was updated recently (within max_timeout), declare the peer as * caught-up. * 3. Otherwise the peer is making progressing. Keep waiting. */ private BootStrapProgress checkProgress(FollowerInfo follower, long committed) { Preconditions.assertTrue(!follower.isAttendingVote()); final Timestamp progressTime = new Timestamp().addTimeMs(-server.getMaxTimeoutMs()); final Timestamp timeoutTime = new Timestamp().addTimeMs(-3*server.getMaxTimeoutMs()); if (follower.getLastRpcResponseTime().compareTo(timeoutTime) < 0) { LOG.debug("{} detects a follower {} timeout for bootstrapping," + " timeoutTime: {}", server.getId(), follower, timeoutTime); return BootStrapProgress.NOPROGRESS; } else if (follower.getMatchIndex() + stagingCatchupGap > committed && follower.getLastRpcResponseTime().compareTo(progressTime) > 0) { return BootStrapProgress.CAUGHTUP; } else { return BootStrapProgress.PROGRESSING; } }
/** * So far we use a simple implementation for catchup checking: * 1. If the latest rpc time of the remote peer is before 3 * max_timeout, * the peer made no progress for that long. We should fail the whole * setConfiguration request. * 2. If the peer's matching index is just behind for a small gap, and the * peer was updated recently (within max_timeout), declare the peer as * caught-up. * 3. Otherwise the peer is making progressing. Keep waiting. */ private BootStrapProgress checkProgress(FollowerInfo follower, long committed) { Preconditions.assertTrue(!follower.isAttendingVote()); final Timestamp progressTime = Timestamp.currentTime().addTimeMs(-server.getMaxTimeoutMs()); final Timestamp timeoutTime = Timestamp.currentTime().addTimeMs(-3*server.getMaxTimeoutMs()); if (follower.getLastRpcResponseTime().compareTo(timeoutTime) < 0) { LOG.debug("{} detects a follower {} timeout for bootstrapping," + " timeoutTime: {}", server.getId(), follower, timeoutTime); return BootStrapProgress.NOPROGRESS; } else if (follower.getMatchIndex() + stagingCatchupGap > committed && follower.getLastRpcResponseTime().compareTo(progressTime) > 0) { return BootStrapProgress.CAUGHTUP; } else { return BootStrapProgress.PROGRESSING; } }
"reply's next index is %s, request's previous is %s", replyNextIndex, request.getPreviousLog()); updateMatchIndex = request.hasPreviousLog() && follower.getMatchIndex() < lastIndex; } else {
final long leaderNextIndex = leaderLog.getNextIndex(); final long followerMatchIndex = logAppender.getFollower().getMatchIndex(); Assert.assertTrue(followerMatchIndex >= leaderNextIndex - 1); Assert.assertEquals(followerMatchIndex + 1, logAppender.getFollower().getNextIndex());
RaftServerTestUtil.getLogAppenders(cluster.getLeader()).forEach(logAppender -> { Assert.assertEquals(logAppender.getFollower().getMatchIndex(), index - 1); Assert.assertEquals(logAppender.getFollower().getNextIndex(), index); });