• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

databendlabs / openraft / 15236981492

25 May 2025 05:51AM UTC coverage: 90.34% (-0.09%) from 90.427%
15236981492

push

github

drmingdrmer
feat: add `Raft::get_read_linearizer()`

Add new API `Raft::get_read_linearizer()` to implement linearizable
reads. It provides a clearer API and gives users intuitive guidance
on how to perform local linearizable reads or follower reads, i.e.,
get `read_log_id` from a remote leader but read the local state machine.

`Raft::get_read_linearizer()` ensures leadership and returns a
`Linearizer` instance containing `read_log_id` and the last `applied`
log ID in the state machine. The caller, either on the local node or on
a remote follower, calls `Linearizer::await_applied()` to block until
the state machine applies up to `read_log_id` to assert linearizability.

A typical usage of follower read:

```rust,ignore
// Application defined RPC to get the `read_log_id` from the remote leader
let leader_id = my_raft.current_leader().await?.unwrap();
let linearizer = my_app_rpc.get_read_linearizer(leader_id, ReadPolicy::ReadIndex).await?;

// Block waiting local state machine to apply up to the `read_log_id`
let _ = linearizer.await_applied(&my_raft, None).await?.unwrap();

// Following read from state machine is linearized across the cluster
let val = my_raft.with_state_machine(|sm| { sm.read("foo") }).await?;
```

63 of 79 new or added lines in 7 files covered. (79.75%)

3 existing lines in 2 files now uncovered.

9838 of 10890 relevant lines covered (90.34%)

98008.38 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.15
/openraft/src/engine/handler/leader_handler/mod.rs


Source Not Available

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc