A minimal implementation of consistent hashing.
Clients can use the HashRing struct to add consistent hashing to their
applications.
- You can add and remove nodes to a HashRing.
- Find all nodes that (should) store a given key.
- Return all hash ranges within the HashRing to easily detect nodes and their responsibilities (containing replica nodes as well)
- Compare two HashRing clusters to receive replication instructions between both clusters (for each node, list hash ranges and target nodes to find keys that need to be replicated)
This implemementation is based on the original source: https://github.com/jeromefroe/hashring-rs
Example
Below is a simple example of how an application might use HashRing to make
use of consistent hashing. Since HashRing exposes only a minimal API clients
can build other abstractions, such as virtual nodes, on top of it. The example
below shows one potential implementation of virtual nodes on top of HashRing
extern crate hashring_coordinator;
use HashRing;
use IpAddr;
use FromStr;