Expand description
§tsoracle-driver-openraft
ConsensusDriver implementation for tsoracle backed by openraft via tsoracle-openraft-toolkit.
§What it provides
OpenraftDriver— thetsoracle_consensus::ConsensusDriverimpl. Wraps anopenraft::Rafthandle and the bundledHighWaterStateMachine; bridges them to tsoracle’sleadership_events,load_high_water, andpersist_high_watercontract.OpenraftHighWaterHost— the single trait a host service implements to expose its openraft cluster to the driver. Lets a service share one raft log between its own state and the tsoracleHighWaterCommand.StandaloneHost— turnkeyOpenraftHighWaterHostfor services that don’t already run openraft. Bring yourRaftLogStorageandRaftNetworkFactory; this crate provides the state machine and the trait bridge.HighWaterStateMachine— theRaftStateMachineimpl over an in-memoryu64high-water counter. Snapshots use postcard via a pluggableSnapshotStore(in-memory default, plus an optionalRocksdbSnapshotStorebehind therocksdb-snapshot-storefeature).HighWaterCommand— the typed log entry the driver injects into the host’s raft log.- The
RaftTypeConfig(viatsoracle_openraft_toolkit::declare_raft_types_ext!) —TypeConfigand friends.
§Patterns
§Standalone services
Greenfield path — wire StandaloneHost::new(raft, state_machine) with an openraft::Raft handle you constructed against tsoracle_openraft_toolkit::RocksdbLogStore plus your own RaftNetworkFactory, then hand the resulting OpenraftDriver to Server::builder().consensus_driver(driver). See examples/openraft-standalone for the full wiring with a tonic peer transport.
§Piggyback on an existing openraft
If your service already runs an openraft for its own state, implement OpenraftHighWaterHost directly against that handle. HighWaterCommand becomes a tagged variant of your application command type, decided on the same log alongside your own commands; one snapshot covers both halves. See examples/openraft-piggyback for the worked envelope pattern.
§Feature flags
rocksdb-snapshot-store(default) — enablesRocksdbSnapshotStore, keyed in a caller-managed RocksDB column family. Pairs naturally withtsoracle_openraft_toolkit::RocksdbLogStoreso oneArc<DB>covers both the raft log and the persisted snapshot. Disable withdefault-features = falseif you want a custom snapshot backend.
§Documentation
docs/consensus-integration.md— theConsensusDrivertrait reference, the “Choosing a driver” comparison (file vs openraft vs paxos), and the canonical worked example for the openraft side.tsoracle-openraft-toolkit— the reusable openraft glue this crate is built on (RocksDB log store,declare_raft_types_ext!macro, lifecycle helpers).
Re-exports§
pub use capabilities::CapabilitySource;pub use capabilities::FormatActivationError;pub use capabilities::NodeCapabilities;pub use capabilities::all_members_can_read;pub use capabilities::gather_with;pub use capabilities::report_with;pub use driver::OpenraftDriver;pub use host::OpenraftHighWaterHost;pub use log_codec::OpenraftLogCodec;pub use log_entry::DenseAdvance;pub use log_entry::HighWaterCommand;pub use log_entry::SetFormatVersionPayload;pub use snapshot_store::RocksdbSnapshotStore;pub use snapshot_store::InMemorySnapshotStore;pub use snapshot_store::SnapshotStore;pub use standalone::StandaloneHost;pub use state_machine::HighWaterStateMachine;pub use state_machine::HighWaterStateMachineSnapshot;pub use type_config::ApplyOutcome;pub use type_config::HighWaterApplied;pub use type_config::OpenraftPeer;pub use type_config::ServiceEndpoint;pub use type_config::TypeConfig;
Modules§
- capabilities
- Format-migration capability reporting and the leader-side all-members activation gate’s pure logic.
- driver
ConsensusDriverimpl on top of anyOpenraftHighWaterHost.- host
- Host abstraction the openraft-backed
ConsensusDriverbuilds on. - log_
codec - Concrete
LogStoreCodecprovider for this driver’sTypeConfig. - log_
entry - Log entries replicated by the openraft cluster.
- observability
- Format-migration observability: the metric-name constants and the emit
helpers the activation path and the state-machine apply arm call. Every
emission is gated behind the crate’s
metricsfeature so themetricsdependency stays opt-in (matchingtsoracle-server). The helpers are deliberately the single place eachtsoracle.schema.*name is written, so the apply arm, the gate, the boot path, and the metrics test cannot drift apart on a name. When the feature is off, every helper compiles to a no-op with an identical signature. - snapshot_
store - Persistence backend for
HighWaterStateMachinesnapshots. - standalone
- Bundled host: owns its own raft cluster and the
HighWaterStateMachine. - state_
machine RaftStateMachinefor the high-water counter with pluggable snapshot persistence.- type_
config RaftTypeConfigfor the openraft-backed driver.
Structs§
- Advance
Payload - Re-export of the cross-backend advance payload that
HighWaterCommand::Advancewraps, so consumers can build commands without depending ontsoracle-consensus. The payload of an “advance the high-water to at leastat_least” command, shared by every consensus backend’s replicated log entry. - TsoPeer
- A known peer node and the network endpoint where its TSO service can be reached for follower-redirect hints.
Constants§
- DEFAULT_
DENSE_ CARDINALITY_ CAP - The default immutable genesis cardinality cap for dense sequence keys. Every cluster member must be constructed with the same value; the cap is stored in replicated snapshots so replay/restore reproduces the same accept/reject decisions (spec §6.2). Operators that need a larger or smaller key namespace configure this at SM construction time.