Expand description
ember-cluster: distributed coordination for ember.
This crate provides the building blocks for running ember as a distributed cluster with automatic failover and horizontal scaling.
§Architecture
The cluster layer sits between the protocol layer and the storage engine, handling:
- Slot management: 16384 hash slots distributed across nodes
- Topology tracking: Node membership and health monitoring
- Failure detection: SWIM gossip protocol for quick detection
- Consensus: Raft for cluster configuration changes
- Migration: Live slot resharding without downtime
§Quick Start
use ember_cluster::{ClusterState, ClusterNode, NodeId, key_slot};
// Create a single-node cluster
let node_id = NodeId::new();
let node = ClusterNode::new_primary(node_id, "127.0.0.1:6379".parse().unwrap());
let cluster = ClusterState::single_node(node);
// Route a key to its slot
let slot = key_slot(b"mykey");
assert!(cluster.owns_slot(slot));Structs§
- Basic
Node - An implementation of trait
Nodethat contains minimal node information. - Cluster
Node - Information about a single node in the cluster.
- Cluster
Secret - A shared secret used to authenticate cluster transport messages.
- Cluster
Snapshot - State machine snapshot.
- Cluster
State - The complete state of the cluster as seen by a node.
- Cluster
State Data - Internal cluster state managed by the state machine.
- Election
- State for an in-progress automatic failover election.
- Gossip
Config - Configuration for the gossip protocol.
- Gossip
Engine - The gossip engine manages cluster membership and failure detection.
- Member
Info - Information about a cluster member.
- Member
State - Internal state of a cluster member as tracked by gossip.
- Migration
- A single slot migration operation.
- Migration
Batch - Represents a batch of keys to migrate.
- Migration
Config - Configuration for migration behavior.
- Migration
Entry - A single key-value entry being migrated.
- Migration
Id - Unique identifier for a migration operation.
- Migration
Manager - Tracks all active migrations for a node.
- Node
Flags - Status flags for a node.
- NodeId
- Unique identifier for a cluster node.
- Node
Info - Information about a cluster node.
- Raft
Network Factory - Factory that creates per-peer
RaftNetworkClientinstances. - Raft
Node - High-level Raft node wrapper.
- Raft
Storage - Combined log and state machine storage for Raft.
- SlotMap
- Maps each of the 16384 slots to a node ID.
- Slot
Range - A contiguous range of slots assigned to a node.
- Type
Config - Type configuration for openraft.
Enums§
- Cluster
Command - Commands that modify cluster configuration.
- Cluster
Error - Errors that can occur during cluster operations.
- Cluster
Health - Overall cluster health status.
- Cluster
Response - Response from applying a cluster command.
- Config
Parse Error - Error returned when parsing a
nodes.conffile fails. - Gossip
Event - Events emitted by the gossip engine.
- Gossip
Message - Message types for the SWIM gossip protocol.
- Member
Status - Health status of a member.
- Migration
Error - Errors that can occur during migration.
- Migration
Redirect - Result of checking whether a command should be redirected during migration.
- Migration
State - Current state of a slot migration.
- Node
Role - The role of a node in the cluster.
- Node
Update - A state update about a node, piggybacked on protocol messages.
- Raft
Disk Error - Raft
Proposal Error - Error from proposing a command through Raft.
Constants§
- SLOT_
COUNT - Total number of hash slots in the cluster (Redis Cluster standard).
Functions§
- key_
slot - Computes the hash slot for a key.
- raft_
id_ from_ node_ id - Derives a stable
u64raft ID from aNodeIdUUID.