SuperCache.Partition.Holder (SuperCache v1.3.0)

Copy Markdown View Source

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

  1. On application start, Partition.start/1 calls set_num_partition/1 and set/1 for each index to populate the registry.
  2. During runtime, get/1 and get_all/1 are used by the routing layer to resolve partition tables.
  3. On shutdown, stop/0 clears 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

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clean()

@spec clean() :: true

Clears all partition registrations from the ETS table.

Does NOT delete the ETS table itself — only removes its contents.

get(order)

@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"

get_all()

@spec get_all() :: [atom()]

Return all registered partition ETS table atoms.

Filters out non-partition entries (such as :num_partition).

set(order)

@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".

set_num_partition(num)

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

start_link(opts \\ [])

@spec start_link(keyword()) :: :ignore | {:error, any()} | {:ok, pid()}

Starts the Partition.Holder GenServer and its owned ETS table.

stop()

@spec stop() :: :ok

Stops the Partition.Holder GenServer.

The ETS table will be deleted when the GenServer terminates.