Struct Keyspace

Source
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>

Source

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.

Source

pub fn remove_node( &mut self, node_id: &N::Id, ) -> KeyspaceResult<MigrationPlan<N>>

Remove a node from the keyspace.

Source

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.

Source

pub fn version(&self) -> u64

Keyspace version.

Version is incremented each time the keyspace is modified.

Source

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).

Source

pub fn iter_node(&self, node_id: &N::Id) -> impl Iterator<Item = KeyRange>

Keyspace intervals controlled by the given node.

Auto Trait Implementations§

§

impl<N, R, const RF: usize, H> Freeze for Keyspace<N, R, RF, H>
where R: Freeze, H: Freeze,

§

impl<N, R = DefaultReplicationStrategy, const RF: usize = 3, H = BuildHasherDefault<RapidHasher>> !RefUnwindSafe for Keyspace<N, R, RF, H>

§

impl<N, R, const RF: usize, H> Send for Keyspace<N, R, RF, H>
where R: Send, H: Send, <N as KeyspaceNode>::Id: Send + Sync, N: Sync + Send,

§

impl<N, R, const RF: usize, H> Sync for Keyspace<N, R, RF, H>
where R: Sync, H: Sync, <N as KeyspaceNode>::Id: Send + Sync, N: Sync + Send,

§

impl<N, R, const RF: usize, H> Unpin for Keyspace<N, R, RF, H>
where R: Unpin, H: Unpin,

§

impl<N, R = DefaultReplicationStrategy, const RF: usize = 3, H = BuildHasherDefault<RapidHasher>> !UnwindSafe for Keyspace<N, R, RF, H>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.