feat(raft-library): task 3.2 — raft_start_election with single-node shortcircuit; 4 tests

This commit is contained in:
Rongsong Shen 2026-05-31 05:30:00 +00:00
parent 1aa7db4583
commit 4955fa3805
3 changed files with 318 additions and 3 deletions

View file

@ -31,7 +31,7 @@
- `raft_init` with a NULL required callback returns `-EINVAL`; subsequent `raft_start_election` is not callable
- _Requirements: 1.2, 7.2, 7.3_
- [ ] 3.2 Implement raft_start_election
- [x] 3.2 Implement raft_start_election
- Guard: returns `-EALREADY` if `role` is `RAFT_CANDIDATE` or `RAFT_LEADER` without modifying state
- Increments `term`, sets `role=RAFT_CANDIDATE`, records `voted_for=self_idx`, `voted_for_term=term`, resets `votes_granted=1`, `replies_received=0`, `election_decided=0`
- Fires `on_persist(ctx, new_term, self_idx)` for self-vote durability before sending any RPC