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

databendlabs / openraft / 22836653978
88%

Build:
DEFAULT BRANCH: main
Ran 09 Mar 2026 03:11AM UTC
Jobs 1
Files 258
Run time 1min
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

07 Mar 2026 01:24PM UTC coverage: 87.582% (-0.2%) from 87.747%
22836653978

push

github

drmingdrmer
change: add SM type parameter to Raft<C, SM> for compile-time state machine type safety

Previously, Raft::with_state_machine() and external_state_machine_request()
erased the SM type via dyn Any and performed runtime downcasting. If the caller
specified the wrong SM type, it would fail at runtime with
InvalidStateMachineType. This change lifts the SM type into Raft<C, SM>
itself, making type mismatches a compile-time error.

The SM command channel (sm_cmd_tx) is now stored directly on Raft, bypassing
RaftCore message loop for external SM requests. This eliminates the
ExternalCommand::StateMachineCommand variant and reduces latency for
with_state_machine calls.

SM defaults to () so existing code that does not use with_state_machine
continues to compile unchanged.

Changes:
- Add SM = () type parameter to Raft, Leader, Command, Engine,
  EngineOutput, and all handler types throughout the engine layer
- Store sm_cmd_tx on Raft and send external SM commands directly to the
  worker, bypassing RaftCore
- Rename sm::Command::Func to ExternalFunc, using BoxAsyncOnceMut<SM>
  instead of BoxMaybeAsyncOnceMut<dyn Any>
- Simplify with_state_machine return type from
  Result<Result<V, InvalidStateMachineType>, Fatal<C>> to Result<V, Fatal<C>>
- Remove ExternalCommand::StateMachineCommand variant and its routing in RaftCore
- Each example now defines pub type Raft = openraft::Raft<TypeConfig, SM> with
  its concrete SM type; declare_types.rs re-exports from parent module

Upgrade tip:

Raft::new() return type is now Raft<C, SM> where SM is inferred from the
state machine argument. If you use with_state_machine(), the SM type is
checked at compile time - no changes needed beyond ensuring the Raft type
carries the correct SM parameter.

Before:
    let raft: Raft<MyConfig> = Raft::new(id, config, net, log, sm).await?;
    let val = raft.with_state_machine::<_, MySM, _>(|sm| { ... }).await?.unwrap();

After:
    let raft: Raft<MyConfig, MySM> = Raft::new(id, config... (continued)

87 of 118 new or added lines in 18 files covered. (73.73%)

14 existing lines in 5 files now uncovered.

15840 of 18086 relevant lines covered (87.58%)

147144.73 hits per line

New Missed Lines in Diff

Lines Coverage ∆ File
4
91.55
-0.05% openraft/src/raft/mod.rs
6
77.55
-1.02% openraft/src/core/sm/command.rs
6
72.88
-8.25% openraft/src/engine/engine_output.rs
15
31.03
-28.97% openraft/src/raft/leader.rs

Uncovered Existing Lines

Lines Coverage ∆ File
2
92.59
5.09% openraft/src/core/sm/handle.rs
2
93.39
-1.65% openraft/src/replication/stream_state.rs
3
79.69
-1.26% openraft/src/engine/command.rs
3
0.0
-100.0% openraft/src/raft/core_state.rs
4
84.62
-6.15% openraft/src/raft/raft_inner.rs
Jobs
ID Job ID Ran Files Coverage
1 22836653978.1 09 Mar 2026 03:11AM UTC 258
87.58
GitHub Action Run
Source Files on build 22836653978
  • Tree
  • List 258
  • Changed 28
  • Source Changed 27
  • Coverage Changed 16
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Repo
  • Github Actions Build #22836653978
  • 88604cfd on github
  • Prev Build on main (#22723756593)
  • Next Build on main (#22842783777)
  • Delete
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