Skip to content

Conversation

@cjen1-msft
Copy link
Contributor

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)

@cjen1-msft cjen1-msft added run-long-test Run Long Test job run-long-verification Run Long Verification jobs labels Nov 10, 2025
@cjen1-msft cjen1-msft marked this pull request as ready for review November 10, 2025 13:08
Copilot AI review requested due to automatic review settings November 10, 2025 13:08
@cjen1-msft cjen1-msft requested a review from a team as a code owner November 10, 2025 13:08
Copy link
Contributor

Copilot AI left a 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 RequestPreVote and RequestPreVoteResponse message types alongside existing RequestVote and RequestVoteResponse
  • Added corresponding enum values raft_request_pre_vote and raft_request_pre_vote_response to RaftMsgType
  • Removed the election_type field from RequestVote and RequestVoteResponse structs, 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 is raft_request_pre_vote_response, the code casts to RequestVoteResponse*, but it should cast to RequestPreVoteResponse* instead. These are different types with different RaftHeader base classes.

The case should be split into two separate cases:

  • One for raft_request_vote_response that casts to RequestVoteResponse*
  • One for raft_request_pre_vote_response that casts to RequestPreVoteResponse* and calls the appropriate overload of log_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;

@achamayou achamayou merged commit 28c8006 into microsoft:main Nov 12, 2025
23 checks passed
@cjen1-msft cjen1-msft deleted the fix-raft-binary-format branch November 12, 2025 15:21
cjen1-msft added a commit to cjen1-msft/CCF that referenced this pull request Nov 12, 2025
@cjen1-msft cjen1-msft added the 6.x-todo PRs which should be backported to 6.x label Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.x-todo PRs which should be backported to 6.x run-long-test Run Long Test job run-long-verification Run Long Verification jobs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants