Skip to content

raft-runtime: expose per-peer match_index and follower-observed leader commit (replica lag) - #70

Open
chrischeng-c4 wants to merge 2 commits into
mainfrom
issue/45
Open

chrischeng-c4 wants to merge 2 commits into
mainfrom
issue/45

Conversation

@chrischeng-c4

Copy link
Copy Markdown
Contributor

Closes #45

Changes

  • crates/raft-core/src/domain/raft_node/accessors.rs:
    • Added pub fn peer_match_index(&self) -> Option<Vec<(NodeId, Index)>> on RaftNode. Returns None when node is not leader; otherwise returns sorted (NodeId, Index) for all voters (incoming/outgoing) and learners excluding self, with Index::new(0) for peers without recorded match index.
  • crates/raft-core/tests/it/consensus.rs:
    • Added integration test peer_match_index_reports_leader_peers_and_advances covering None on follower, peer list on leader, and advancement after append.
  • crates/raft-runtime/src/application/host/status.rs:
    • Defined PeerMatch { pub id: NodeId, pub match_index: u64 }.
    • Added #[serde(default)] pub peer_match_index: Vec<PeerMatch> to RaftStatus.
    • Added isolated unit test raft_status_deserializes_without_peer_match_index.
  • crates/raft-runtime/src/application/host.rs, application.rs, lib.rs:
    • Re-exported PeerMatch next to RaftStatus.
  • crates/raft-runtime/src/interfaces/peer_http/status.rs:
    • Populated peer_match_index from n.peer_match_index() in host_status.
  • crates/raft-runtime/tests/it/membership_changes.rs:
    • Added test row raftz_peer_match_index_reported_on_leader_and_empty_on_follower on a 3-voter + 1-learner cluster.
  • crates/raft-runtime/tests/it/wire_golden.rs:
    • Updated raft_status_json_is_pinned struct literal and expected JSON to include peer_match_index: [].

Tests Passed Locally

  • cargo check --locked -p raft-core -p raft-runtime: PASSED
  • cargo test --locked -p raft-core -p raft-runtime --no-run: PASSED
  • cargo test --locked -p raft-runtime --lib raft_status_deserializes_without_peer_match_index: PASSED (1 passed; 0 failed)
  • cargo fmt --check -p raft-core -p raft-runtime: PASSED

Tests Not Run Locally (Deferred to Cloud CI)

Per local testing policy, cluster/network tests belong in authorized cloud CI:

  • crates/raft-core/tests/it/consensus.rs::peer_match_index_reports_leader_peers_and_advances (runs multi-node Raft simulation and leader election).
  • crates/raft-runtime/tests/it/membership_changes.rs::raftz_peer_match_index_reported_on_leader_and_empty_on_follower (starts multi-node TCP/h2c cluster).
  • Full crate test suites cargo test -p raft-core and cargo test -p raft-runtime.

@chrischeng-c4

Copy link
Copy Markdown
Contributor Author

Summary of Changes

  • raft-core: Exposed peer_match_index(&self) -> Option<Vec<(NodeId, Index)>> in crates/raft-core/src/domain/raft_node/accessors.rs returning None on non-leaders, and on leaders returning every voter (incoming and outgoing) and learner other than self, sorted by NodeId. Added verification in crates/raft-core/tests/it/consensus.rs.
  • raft-runtime: Added PeerMatch { id: NodeId, match_index: u64 } and #[serde(default)] pub peer_match_index: Vec<PeerMatch> to RaftStatus in crates/raft-runtime/src/application/host/status.rs, and exported PeerMatch from application::host and crate root. Updated /raftz handler in crates/raft-runtime/src/interfaces/peer_http/status.rs. Added tests in crates/raft-runtime/tests/it/membership_changes.rs asserting sorted peer reporting on leader and empty list on follower.
  • CI Retry / Test Refinement: Updated test assertions in membership_changes.rs to explicitly verify sorted order by NodeId across /raftz responses, and follower search in consensus.rs.

Local Tests Passed

  • application::host::status::tests::raft_status_deserializes_without_peer_match_index (isolated unit test)
  • Compilation and formatting verification: cargo check --locked -p raft-core -p raft-runtime, rustfmt --edition 2021 --check

Cloud Validation Required (Tests Not Run Locally)

  • MR CI Gates:
    • cargo test --locked -p raft-core (in-process consensus simulation / elections)
    • cargo test --locked -p raft-runtime (h2c multi-node clusters, /raftz endpoints, network transport, shutdown handoff)
    • cargo test --locked -p service-k8s
    • cargo test --locked -p storage-durable
    • cargo test --locked -p service-backup --features http-client
  • Release Acceptance: Full declared acceptance matrix and cluster performance verification in cloud environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

raft-runtime: expose per-peer match_index and follower-observed leader commit (replica lag)

1 participant