mirror of
https://github.com/logos-blockchain/logos-blockchain-testing.git
synced 2026-04-13 06:33:35 +00:00
OpenRaft KV Example
This example runs a small key-value service built on top of OpenRaft.
The main scenario does four things:
- bootstraps node 0 as a one-node cluster
- adds nodes 1 and 2 as learners and promotes them to voters
- writes one batch of keys through the current leader
- restarts that leader, waits for a new leader, writes again, and then checks that all three nodes expose the same replicated state
How TF runs this
- TF starts three OpenRaft nodes
- the workload bootstraps the cluster through the admin API
- the workload writes a first batch, restarts the current leader, waits for failover, and writes again
- the expectation checks that all three nodes converge on the same key/value state and membership
Scenario
basic_failoverruns the leader-restart flow locallycompose_failoverruns the same flow in Docker Composek8s_failoverruns the same flow against a manual Kubernetes cluster deployment
API
Each node exposes:
GET /healthzfor readinessGET /statefor current Raft role, leader, membership, log progress, and replicated key/value dataPOST /kv/writeto submit a write through the local Raft nodePOST /kv/readto read a key from the local state machinePOST /admin/initto initialize a single-node clusterPOST /admin/add-learnerto add a new Raft learnerPOST /admin/change-membershipto promote learners into the voting set
The node also exposes internal Raft RPC endpoints used only for replication:
POST /raft/votePOST /raft/appendPOST /raft/snapshot
Run locally
OPENRAFT_KV_NODE_BIN="$(pwd)/target/debug/openraft-kv-node" \
cargo run -p openraft-kv-examples --bin basic_failover
Build the node first if you have not done that yet:
cargo build -p openraft-kv-node
Run with Docker Compose
Build the image first:
docker build -t openraft-kv-node:local -f examples/openraft_kv/Dockerfile .
Then run:
cargo run -p openraft-kv-examples --bin compose_failover
Set OPENRAFT_KV_IMAGE to override the default compose image tag.
Run on Kubernetes
Build the same image first:
docker build -t openraft-kv-node:local -f examples/openraft_kv/Dockerfile .
Then run:
cargo run -p openraft-kv-examples --bin k8s_failover
If no cluster is available, the example exits early and prints a skip message.