MARS documentation
Rust librariesmars-shard

mars-shard · affinity

Public declarations and documentation for mars-shard::affinity.

Prototype / draft — separate from production registry operations.

Package: mars-shard · Workspace version: 0.1.0 · Module: affinity

Status: prototype / draft. This is not the production registry topology.

This reference follows declared modules and public syntax, including public implementation methods. Function bodies and constant values are omitted. Feature conditions are retained. Private-module re-exports and trait resolution require the compiler; not every declaration is a root import.

affinity::AffinityFunction

Determines the key extraction strategy for shard assignment.

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum AffinityFunction {
    /// Hash on the organization DID from lineage.
    Organization,
    /// Hash on the human root DID.
    HumanRoot,
    /// Hash on the entry DID prefix/namespace.
    Namespace,
}

Source line: 20.

affinity::AffinityRouter

Consistent-hashing ring that maps entries to shard IDs.

Each shard is represented by virtual_nodes_per_shard positions on the ring. SHA-256 is used for hash computation.

pub struct AffinityRouter {

}

Source line: 37.

affinity::AffinityRouter::new

Create a new router with the given shard IDs and virtual node count.

virtual_nodes_per_shard should be at least 1. A typical value is 150.

pub fn new(shard_ids: &[String], virtual_nodes_per_shard: u32) -> Self;

Source line: 48.

affinity::AffinityRouter::assign

Assign a raw key to a shard using the consistent hashing ring.

Returns the shard ID that owns the key, or an error if the ring is empty.

pub fn assign(&self, key: &str) -> Result<String, ShardError>;

Source line: 70.

affinity::AffinityRouter::assign_entry

Assign an entry to a shard using the specified affinity function.

The affinity function determines which key is extracted from the entry metadata for hashing.

pub fn assign_entry(
        &self,
        entry_did: &str,
        publisher_did: &str,
        affinity: AffinityFunction,
    ) -> Result<String, ShardError>;

Source line: 90.

affinity::AffinityRouter::add_shard

Add a shard to the ring. Generates virtual nodes for it.

pub fn add_shard(&mut self, shard_id: &str);

Source line: 105.

affinity::AffinityRouter::remove_shard

Remove a shard from the ring and its virtual nodes.

pub fn remove_shard(&mut self, shard_id: &str);

Source line: 118.

affinity::AffinityRouter::shard_count

Returns the number of shards currently in the ring.

pub fn shard_count(&self) -> u32;

Source line: 125.

affinity::AffinityRouter::ring_size

Returns the total number of virtual nodes on the ring.

pub fn ring_size(&self) -> usize;

Source line: 130.

Source provenance

Source: mars-shard/src/affinity.rs · SHA-256 1bcd918d3e55a21b535ceb5557ee757a90de9da9e1549454a7aab58b0a719aa5. Package overview.

On this page