Clustering #
A cluster is a set of nodes that share one Raft log. Every write command is appended to that log and replayed by every node, so all nodes converge on the same state; reads are answered locally by whichever node receives them.
Bootstrapping and joining #
The first node needs no extra flag: an empty -j means “start a new cluster”. Every later node joins
with -j <leader-or-any-node-address>:
./bin/IceFireDB -n 1 -a 127.0.0.1:11001 -d ./data
./bin/IceFireDB -n 2 -a 127.0.0.1:11002 -d ./data -j 127.0.0.1:11001
./bin/IceFireDB -n 3 -a 127.0.0.1:11003 -d ./data -j 127.0.0.1:11001
When joining, the node dials the address with AUTH (if --auth/ICEFIREDB_AUTH is set) and TLS (if
a certificate is configured), asks for the current cluster state, adds itself, and then catches up
from the log. A node restarted on the same data directory does not need -j again — it rejoins from
its persisted Raft state.
Use --advertise whenever the bind address is not the address peers should dial (containers, NAT,
multiple interfaces):
./bin/IceFireDB -n 2 -a 0.0.0.0:11001 --advertise 10.0.0.12:11001 -d /var/lib/icefiredb -j 10.0.0.11:11001
The advertised address is what clients receive in -MOVED redirects and what other nodes add to the
Raft configuration, so it must be reachable by peers and by clients.
Consistency model #
| Operation | Where it runs | Guarantee |
|---|---|---|
Write command (SET, HSET, RPUSH, …) | Leader only, through the Raft log | Applied in the same order on every node; a write is acknowledged after quorum commit |
Read command, no --openreads | Node that receives it; on a follower it is refused | Followers answer -MOVED 0 <leader>; the client retries against the leader |
Read command, --openreads | Any node | May return stale data (whatever the local log has applied) |
RAFT …, CLUSTER …, MACHINE, BARRIER | Receiving node | Administrative, not replicated |
With --try-errors the redirect error becomes -TRY <leader> and the CLUSTER command is disabled;
this exists for clients that need to distinguish “retry elsewhere” from “the cluster moved me”.
Follower reads are only served once the node considers the log reasonably loaded; until then it answers as a non-leader.
Topology management #
Membership changes go through the Raft configuration, not a config file. The two supported paths are
equivalent — the first is what -j does internally:
# path 1 — let the node add itself
./bin/IceFireDB -n 4 -a 127.0.0.1:11004 -d ./data -j 127.0.0.1:11001
# path 2 — add it from an existing node, then start it
redis-cli -p 11001 RAFT SERVER ADD 4 127.0.0.1:11004
redis-cli -p 11001 RAFT SERVER LIST
redis-cli -p 11001 RAFT SERVER REMOVE 4
Rules that matter:
- Add before removing when replacing a node. Removing a member shrinks the quorum requirement, and a two-node cluster has no redundancy at all — during a replacement the surviving quorum must stay large enough to elect.
- Never reuse a node ID with a different data directory. The ID is the Raft server ID; the state
in
<dir>/IceFireDB/<id>/belongs to it. - A majority must be alive to elect a leader. Losing quorum does not corrupt data, but writes stop
and reads that need leadership fail with
-CLUSTERDOWN. - The full channel list is in System commands.
Snapshots #
Raft takes snapshots of the state machine so the log can be truncated. Each snapshot is written under
<data-dir>/IceFireDB/<node-id>/snapshots/<snapshot-id>/state.bin. The file is a gzip-compressed stream:
a 32-byte header (SNAP0001 + machine start time, timestamp, RNG seed), then every key/value pair
written by writeSnapshot in snapshot.go using sds framing — one pair per entry, backend agnostic.
redis-cli -p 11001 RAFT SNAPSHOT NOW # take one immediately
redis-cli -p 11001 RAFT SNAPSHOT LIST # id, timestamp and size per snapshot
redis-cli -p 11001 RAFT SNAPSHOT FILE <id> # path on the server that produced it
Snapshot files are the unit of backup and disaster recovery; see Operations.
Failure behaviour #
| Failure | Effect |
|---|---|
| One follower down (3-node cluster) | No impact on writes or leader stability |
| Leader down | Followers elect a new leader; in-flight uncommitted writes may be lost; clients see -MOVED/-TRY until they rediscover the leader |
| Minority partition | The minority side cannot elect, its writes fail with -CLUSTERDOWN; the majority keeps serving |
| Node restarted with the same data dir | Rejoins from persisted state, catches up from the log or a snapshot |
| Node started with a fresh data dir but an existing node ID | Rejected by the cluster as an ID conflict — clear the directory or use a new ID |
Reads on a follower with --openreads keep working during a leader election, at the cost of serving
state that may be behind.
What clustering does not do #
- No sharding: every node holds the full dataset.
CLUSTER SLOTSreports the whole0-16383range on the leader for redis-cluster-aware clients, but there is no key distribution. - No read-repair or anti-entropy beyond Raft: a node that is caught up stays caught up through the log.
ZINCRBY,ZREMRANGEBYRANKandZREMRANGEBYSCOREare registered as read commands, so they do not replicate. See Compatibility.