-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
raft: don't panic when looking for term conflicts #36
Conversation
b3d210c
to
d0a5d0d
Compare
@tbg PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks! I left some suggestions to a have fewer "unexpected" return values and no case in which the term is not populated. The goal would be to remove all edge cases and make it more transparent what happens in the truncation scenarios, etc.
It might also be good to add some targeted unit testing for findConflictByTerm
. I saw that you added a test case in TestFastLogRejection
, but a few more wouldn't hurt. I should have added that right when we introduced findConflictByTerm
, sorry about that.
Approving preemptively because the current code is "good enough" and I'm fairly certain it's correct (mod comments). The improvements would make it easier to be convinced that it's correct in a month or two but I'll rely on your judgment of which further improvements are worth it.
685e800
to
bdae85a
Compare
Signed-off-by: Pavel Kalinnikov <pavel@cockroachlabs.com>
Signed-off-by: Pavel Kalinnikov <pavel@cockroachlabs.com>
Signed-off-by: Pavel Kalinnikov <pavel@cockroachlabs.com>
Signed-off-by: Pavel Kalinnikov <pavel@cockroachlabs.com>
Signed-off-by: Pavel Kalinnikov <pavel@cockroachlabs.com>
This commit fixes a hypothetical panic that may occur when a stale MsgApp message arrives to a follower. The conflict searching algorithm in findConflictByTerm may return a log index which is not present in the log, and thus the raftLog.term() method may return an error. It is safe to ignore this error and send MsgAppResp with the found index and a zero LogTerm. This commit also restores the behaviour that existed before commit d0fb0cd. Back then, the term() function would silently return 0 instead of an error, and a zero LogTerm would be sent with the rejecting MsgAppResp. After that commit, there is a new possible panic. We remove the possibility of this panic here. Signed-off-by: Pavel Kalinnikov <pavel@cockroachlabs.com>
bdae85a
to
0c22de0
Compare
@tbg Addressed comments, and added unit tests for |
This commit fixes a hypothetical panic that may occur when a stale
MsgApp
message arrives to a follower. The conflict searching algorithm in
findConflictByTerm
may return a log index which is not present in the log, andthus the
raftLog.term()
method may return an error. It is safe to ignore thiserror and send
MsgAppResp
with the found index and a zeroLogTerm
.This commit also restores the behaviour that existed before commit d0fb0cd.
Back then, the
term()
function would silently return 0 instead of an error, anda zero
LogTerm
would be sent with the rejectingMsgAppResp
. After that commit,there is a new possible panic. We remove the possibility of this panic here.