Ferricstore.Store.SlotMap (ferricstore v0.3.5)

Copy Markdown View Source

Manages the 1,024-slot to shard-index mapping.

Provides the indirection layer between hash output and shard assignment:

key -> phash2(key) & 0x3FF -> slot -> slot_map[slot] -> shard_index

The slot map is a 1,024-element tuple stored in :persistent_term for ~10ns read access. Updates via put/1 are atomic -- all processes see the new map on their next read.

Summary

Functions

build_uniform(shard_count)

@spec build_uniform(pos_integer()) :: tuple()

get()

@spec get() :: tuple()

init(shard_count)

@spec init(pos_integer()) :: :ok

num_slots()

@spec num_slots() :: pos_integer()

put(new_map)

@spec put(tuple()) :: :ok

reassign_slot(map, slot, new_shard)

@spec reassign_slot(tuple(), non_neg_integer(), non_neg_integer()) :: tuple()

shard_for_slot(map, slot)

@spec shard_for_slot(tuple(), non_neg_integer()) :: non_neg_integer()

slot_count_for_shard(map, shard_index)

@spec slot_count_for_shard(tuple(), non_neg_integer()) :: non_neg_integer()

slot_for_key(key)

@spec slot_for_key(binary()) :: non_neg_integer()

slot_ranges(map)

@spec slot_ranges(tuple()) :: [
  {non_neg_integer(), non_neg_integer(), non_neg_integer()}
]