Skip to main content

krabka_raft/
reconfig.rs

1//! KIP-853 requests submitted to the single-owner Raft engine.
2
3use {crate::NodeId, krabka_metadata::Voter};
4
5/// A request to add one voter. The candidate must already be a caught-up observer.
6#[derive(Debug, Clone)]
7pub struct AddVoter {
8    pub voter: Voter,
9    /// `AddRaftVoter` v1 may acknowledge after the local append so an
10    /// auto-joining observer can keep fetching while the record commits.
11    pub ack_when_committed: bool,
12}
13
14/// A request to remove one voter.
15#[derive(Debug, Clone)]
16pub struct RemoveVoter {
17    pub id: NodeId,
18    pub directory_id: uuid::Uuid,
19}
20
21/// A request to update one voter's endpoints / supported version range.
22#[derive(Debug, Clone)]
23pub struct UpdateVoter {
24    pub voter: Voter,
25}
26
27/// A single KIP-853 control operation owned by the Raft engine.
28#[derive(Debug, Clone)]
29pub enum VoterChange {
30    Add(AddVoter),
31    /// Run only the checks `AddVoterHandler.handleAddVoterRequest` makes from
32    /// the leader's own state, before it contacts the candidate: a pending
33    /// change, an unset high watermark, `kraft.version`, an uncommitted voters
34    /// record and a duplicate voter id. Nothing is appended, and an admitted
35    /// request is answered [`ReconfigOutcome::Committed`]. The candidate's
36    /// `ApiVersions` range and catch-up are the later, second half of the
37    /// admission that [`VoterChange::Add`] still makes.
38    CheckAdd(AddVoter),
39    Remove(RemoveVoter),
40    Update(UpdateVoter),
41    FinalizeKraftVersion(u16),
42    /// Run every check [`VoterChange::FinalizeKraftVersion`] runs, and write
43    /// nothing. Kafka's `LeaderState.maybeAppendUpgradedKRaftVersion` runs its
44    /// checks whatever `validateOnly` says, and skips only the append.
45    ValidateKraftVersion(u16),
46}
47
48/// Outcome shared by all three operations.
49#[derive(Debug, Clone, PartialEq, Eq)]
50pub enum ReconfigOutcome {
51    Committed,
52    NotLeader { leader: Option<NodeId> },
53}