Registry for partition ETS table names.
Maintains a mapping from partition index (integer) to the corresponding
ETS table atom. The mapping is stored in a :protected ETS table owned
by this GenServer so that:
- Reads are lock-free (
:read_concurrency). - The table survives crashes as long as this GenServer is alive.
- Multiple processes can look up partitions concurrently without blocking each other.
Lifecycle
- On application start,
Partition.start/1callsset_num_partition/1andset/1for each index to populate the registry. - During runtime,
get/1andget_all/1are used by the routing layer to resolve partition tables. - On shutdown,
stop/0clears the registry.
Example
SuperCache.Partition.Holder.set_num_partition(4)
SuperCache.Partition.Holder.set(0)
SuperCache.Partition.Holder.get(0)
# => :"SuperCache.Storage.Ets_0"
Summary
Functions
Returns a specification to start this module under a supervisor.
Clears all partition registrations from the ETS table.
Look up the ETS table atom for a given partition index.
Return all registered partition ETS table atoms.
Register a partition index with its corresponding ETS table name.
Store the total number of partitions in the registry.
Starts the Partition.Holder GenServer and its owned ETS table.
Stops the Partition.Holder GenServer.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec clean() :: true
Clears all partition registrations from the ETS table.
Does NOT delete the ETS table itself — only removes its contents.
@spec get(non_neg_integer()) :: atom() | nil
Look up the ETS table atom for a given partition index.
Reads directly from the ETS table — no GenServer hop. Raises if the index has not been registered.
Examples
SuperCache.Partition.Holder.get(0)
# => :"SuperCache.Storage.Ets_0"
@spec get_all() :: [atom()]
Return all registered partition ETS table atoms.
Filters out non-partition entries (such as :num_partition).
@spec set(non_neg_integer()) :: :ok
Register a partition index with its corresponding ETS table name.
The table name is derived from the configured :table_prefix and the
given order (index). For example, with prefix "SuperCache.Storage.Ets"
and order 2, the table name will be :"SuperCache.Storage.Ets_2".
@spec set_num_partition(pos_integer()) :: :ok
Store the total number of partitions in the registry.
Used by Partition.get_num_partition/0 to resolve the partition count
without a GenServer hop.
Starts the Partition.Holder GenServer and its owned ETS table.
@spec stop() :: :ok
Stops the Partition.Holder GenServer.
The ETS table will be deleted when the GenServer terminates.