hedge-rs
A cluster membership Rust library. It is built on spindle-rs, a distributed locking library built on Cloud Spanner and TrueTime. It is a port (subset only) of the original hedge, which is written in Go. Ported features include:
- Tracking of member nodes - good for clusters with sizes that can change dynamically overtime, such as GCP MIGs, and Kubernetes Deployments;
- Leader election - the cluster elects and maintains a single leader node at all times;
- List of members - get a list of all member nodes at any time;
- Send - any member node can send messages to the leader at any time; and
- Broadcast - any member node can broadcast messages to all nodes at any time.
Running the sample
First, create the Spanner table for spindle-rs:
(
name STRING(MAX) NOT NULL,
heartbeat TIMESTAMP OPTIONS (allow_commit_timestamp=true),
token TIMESTAMP OPTIONS (allow_commit_timestamp=true),
writer STRING(MAX),
) PRIMARY KEY (name)
Then you can run the sample like so:
# Clone and build:
# Run the first instance:
# (Use your actual values)
# Run this 2nd instance on a different terminal:
# (Use your actual values)
# Run this 3nd instance on a different terminal:
# (Use your actual values)
You can play around by adding more processes, killing the leader process, killing a non-leader process, restarting an existing process, etc. You can also remove the spindle_rs=off environment to see logs from spindle-rs.