This directory contains a basic test setup for the Raft cluster with 4 nodes.
node add.LogCompactionEnabled = false). The binary log will grow indefinitely../data/node{1..4}Open 4 separate terminals and run the following commands:
Terminal 1 (Node 1):
cd example/basic/node1
go run main.go
Terminal 2 (Node 2):
cd example/basic/node2
go run main.go
Terminal 3 (Node 3):
cd example/basic/node3
go run main.go
Terminal 4 (Node 4):
cd example/basic/node4
go run main.go
Each node provides an interactive CLI with the following commands:
| Command | Description | Example |
|---|---|---|
set <key> <val> |
Set a key-value pair. Requests are forwarded to Leader. | set user:1 bob |
get <key> |
Get a value by key (Linearizable Read). | get user:1 |
del <key> |
Delete a key. | del user:1 |
search <query> [limit] [offset] |
Search keys using SQL-like syntax. | search key like "user:*" 10 0 |
demodata <count> <pattern> |
Generate demo data. Pattern supports * replacement. |
demodata 100 user.name.u* |
stats |
Show current node status, term, and indices. | stats |
binlog |
Show the last CommitIndex in the Raft log. | binlog |
db |
Show the last CommitIndex applied to the DB. | db |
join <nodeID> <addr> |
(Leader Only) Add a new node to the cluster. | join node3 127.0.0.1:9003 |
leave <nodeID> |
(Leader Only) Remove a node from the cluster. | leave node3 |
help |
Show this help message. | help |
stats on Node 1 and Node 2. One should be Leader, the other Follower.demodata 100 user.*.get user.1 or search key like "user.*".join node3 127.0.0.1:9003.join node4 127.0.0.1:9004.search or get.del user.1. Verify it's gone on all nodes.binlog and db to see the commit indices matching across the cluster.