pub struct Keyspace<N, R = DefaultReplicationStrategy, const RF: usize = 3, H = RapidBuildHasher>{ /* private fields */ }Expand description
Keyspace.
Manages information about nodes and their intervals in the keyspace. Each node controls one or more intervals of the keyspace, and whenever a key needs to be stored or retrieved, the keyspace manager will provide all the replica nodes that are responsible for the key.
Whenever a node is added or removed, the keyspace manager will re-balance the internal structure in a way that minimizes the amount of data that needs to be moved around.
On each node addition or removal, the keyspace manager will provide a migration plan, which is a list of keyspace intervals that need to be moved from one node to another.
Supports replication out of the box, so that each key is stored redundantly on multiple of nodes, for fault tolerance.
Implementations§
Source§impl<N, R, const RF: usize, H> Keyspace<N, R, RF, H>
impl<N, R, const RF: usize, H> Keyspace<N, R, RF, H>
Sourcepub fn add_node(&mut self, node: N) -> KeyspaceResult<MigrationPlan<N>>
pub fn add_node(&mut self, node: N) -> KeyspaceResult<MigrationPlan<N>>
Add a node to the keyspace.
The node will claim one or more intervals of the keyspace.
Sourcepub fn remove_node(
&mut self,
node_id: &N::Id,
) -> KeyspaceResult<MigrationPlan<N>>
pub fn remove_node( &mut self, node_id: &N::Id, ) -> KeyspaceResult<MigrationPlan<N>>
Remove a node from the keyspace.
Sourcepub fn replicas<K: Hash>(&self, key: &K) -> impl Iterator<Item = NodeRef<N>>
pub fn replicas<K: Hash>(&self, key: &K) -> impl Iterator<Item = NodeRef<N>>
Returns replication factor (RF) number of nodes responsible for the
given key position.
The first node is assumed to be the primary node.
Sourcepub fn version(&self) -> u64
pub fn version(&self) -> u64
Keyspace version.
Version is incremented each time the keyspace is modified.
Sourcepub fn iter(&self) -> impl Iterator<Item = (KeyRange, NodeRef<N>)>
pub fn iter(&self) -> impl Iterator<Item = (KeyRange, NodeRef<N>)>
Keyspace as intervals controlled by the nodes.
Each interval is a half-open [start_key..end_key) range of controlled
keys, with one or more replicas assigned.
The intervals are returned as (key range, node ref) tuples, so that it
is trivial to collect them into a map (either by ranges or by nodes).