Skip to content

refactor(raft): migrate from openraft to raft-rs#104

Merged
slow2342 merged 1 commit into
mainfrom
refactor/migrate-to-raft-rs
Jun 10, 2026
Merged

refactor(raft): migrate from openraft to raft-rs#104
slow2342 merged 1 commit into
mainfrom
refactor/migrate-to-raft-rs

Conversation

@slow2342

@slow2342 slow2342 commented Jun 9, 2026

Copy link
Copy Markdown
Owner

Summary

Replace openraft with raft-rs (TiKV fork) for Raft consensus. The new architecture uses a dedicated thread event loop with crossbeam channels, a RocksDB-backed log store, and a RaftHandle trait that abstracts the raft implementation from the API layer.

Use git dependency pinned to ad13f3d9 to fix RUSTSEC-2024-0437 (protobuf v2 stack overflow vulnerability).

Changes

  • src/raft/node.rs — Raft event loop on dedicated thread with tick-based progression. Bootstrap saves initial ConfState before creating RawNode to fix single-node cluster startup.
  • src/raft/raftrs_store.rs — RocksDB-backed raft log and state storage implementing raft-rs Storage trait.
  • src/raft/raftrs_handle.rsRaftHandle impl communicating with event loop via channels.
  • src/raft/handle.rs — Trait abstraction (RaftHandle) for KvService/ClusterService.
  • src/raft/mod.rs — Updated RaftRequest/RaftResponse types, simplified proto to opaque byte payloads.
  • src/raft/network.rs — Updated network sender for raft-rs message types.
  • src/raft/rpc.rs — Updated RPC server for raft-rs.
  • src/raft/state_machine.rs — Apply log entries to storage engine.
  • src/api/cluster.rs — Updated cluster service for raft-rs handle.
  • src/api/kv.rs — Updated KV service for raft-rs handle.
  • src/main.rs — Bootstrap and initialization changes.
  • Cargo.toml — Switch raft from crates.io to git dependency (fixes RUSTSEC-2024-0437).
  • proto/raft.proto — Simplified to opaque byte payloads.

Testing

  • cargo build succeeds
  • cargo test passes (10 tests)
  • cargo run boots single-node cluster successfully
  • ConfState bootstrap fix verified — no more panic on empty store

How to verify

cargo build
cargo test
cargo run  # should start without panic

@slow2342
slow2342 force-pushed the refactor/migrate-to-raft-rs branch from 26b956e to 79953b8 Compare June 9, 2026 18:02
@slow2342 slow2342 changed the title refactor(raft): migrate from openraft to raft-rs 0.7 refactor(raft): migrate from openraft to raft-rs Jun 9, 2026
Replace openraft with raft-rs (TiKV fork) for Raft consensus. The new
architecture uses a dedicated thread event loop with crossbeam channels,
a RocksDB-backed log store, and a RaftHandle trait that abstracts the
raft implementation from the API layer.

Use git dependency pinned to ad13f3d9 to fix RUSTSEC-2024-0437
(protobuf v2 stack overflow vulnerability).
@slow2342
slow2342 force-pushed the refactor/migrate-to-raft-rs branch from 79953b8 to 8db5b37 Compare June 9, 2026 18:04
@slow2342
slow2342 merged commit dfd1f5d into main Jun 10, 2026
7 of 9 checks passed
@slow2342
slow2342 deleted the refactor/migrate-to-raft-rs branch June 10, 2026 02:03
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.

1 participant