-
Notifications
You must be signed in to change notification settings - Fork 243
Ensure that pre-vote messages are binary compatible with pre-pre-vote messages #7445
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
Conversation
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.
Pull Request Overview
This PR refactors the Raft consensus protocol implementation to separate pre-vote and regular vote message types, moving from a field-based differentiation to distinct message types. This improves type safety and clarifies the distinction between pre-vote and regular vote operations.
- Introduced separate
RequestPreVoteandRequestPreVoteResponsemessage types alongside existingRequestVoteandRequestVoteResponse - Added corresponding enum values
raft_request_pre_voteandraft_request_pre_vote_responsetoRaftMsgType - Removed the
election_typefield fromRequestVoteandRequestVoteResponsestructs, as the message type itself now determines whether it's a pre-vote or regular vote
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/consensus/aft/raft_types.h | Adds new RequestPreVote and RequestPreVoteResponse types, removes election_type field from vote request/response structs, and adds formatter for RaftMsgType enum |
| src/consensus/aft/raft.h | Updates message handling logic to use separate functions for pre-vote vs regular vote, adds recv/send handlers for new pre-vote message types |
| src/consensus/aft/test/driver.h | Adds logging support for new pre-vote message types and updates log messages to include message type |
| tla/consensus/Traceccfraft.tla | Updates trace validation to distinguish pre-vote from regular vote based on message type rather than election_type field |
| doc/architecture/raft_tla.rst | Minor grammar correction (validate → validating) |
Comments suppressed due to low confidence (1)
src/consensus/aft/test/driver.h:533
- Incorrect type casting for
raft_request_pre_vote_response. When the message type israft_request_pre_vote_response, the code casts toRequestVoteResponse*, but it should cast toRequestPreVoteResponse*instead. These are different types with different RaftHeader base classes.
The case should be split into two separate cases:
- One for
raft_request_vote_responsethat casts toRequestVoteResponse* - One for
raft_request_pre_vote_responsethat casts toRequestPreVoteResponse*and calls the appropriate overload oflog_msg_details
case (aft::RaftMsgType::raft_request_vote_response):
case (aft::RaftMsgType::raft_request_pre_vote_response):
{
auto rvr = *(aft::RequestVoteResponse*)data;
packet = rvr;
log_msg_details(node_id, tgt_node_id, rvr, dropped);
break;
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Eddy Ashton <[email protected]>
The idea is that rather than using a field in the message to denote whether a message is for pre-vote or not, use the RaftMsgType to denote this.
To minimise the diff relative to the original code, this PR just adds new pre-vote versions of the raft_request_vote and raft_request_vote_response messages.
This means that the pre-vote variants can reuse the existing code, while there are not 'official' RequestPreVote struct, we just update the type in the RequestVote's header for pre-votes messages.
(I'll open a separate PR to address the snagging of docs etc for raft.h)