Mesh.Shards.ShardRouter (Mesh v0.1.4)

View Source

Routes processes to nodes based on hashing (hash ring).

The hashing strategy is configurable via application config:

config :mesh, :hash_strategy, Mesh.Shards.HashStrategy.EventualConsistency

The default strategy uses modulo-based distribution for deterministic routing.

Summary

Functions

Determines which node owns a given shard for a specific capability.

Computes the shard number for a given actor ID.

Functions

owner_node(shard, capability)

@spec owner_node(non_neg_integer(), atom()) :: {:ok, node()} | {:error, :no_nodes}

Determines which node owns a given shard for a specific capability.

Returns {:ok, node} if nodes are available for the capability, or {:error, :no_nodes} if no nodes support the capability.

The specific distribution algorithm is determined by the configured hash strategy.

shard_for(actor_id)

@spec shard_for(String.t()) :: non_neg_integer()

Computes the shard number for a given actor ID.