GenServer managing per-namespace (prefix) runtime configuration.
Stores namespace-specific overrides for commit window timing and durability
mode in an ETS table (:ferricstore_ns_config). Prefixes that have no
explicit override fall back to sensible defaults (1 ms window, :quorum
durability).
ETS schema
Each entry is a tuple:
{prefix, window_ms, durability, changed_at, changed_by}Where:
prefix-- binary namespace prefix (e.g."rate","session")window_ms-- commit window in milliseconds (positive integer)durability--:quorumor:asyncchanged_at-- Unix timestamp (seconds) of the last change, or0for defaultschanged_by-- identifier of the client that made the change (empty string for defaults)
Default values
When no override exists for a prefix, the effective configuration is:
window_ms--1durability--:quorum
Usage
Ferricstore.NamespaceConfig.set("rate", "window_ms", 10)
#=> :ok
Ferricstore.NamespaceConfig.get("rate")
#=> {:ok, %{prefix: "rate", window_ms: 10, durability: :quorum, changed_at: 1711111111, changed_by: ""}}
Ferricstore.NamespaceConfig.window_for("rate")
#=> 10
Ferricstore.NamespaceConfig.durability_for("rate")
#=> :quorum
Ferricstore.NamespaceConfig.reset("rate")
#=> :ok
Summary
Functions
Returns a specification to start this module under a supervisor.
Returns the default durability mode.
Returns the default window_ms value.
Returns the effective durability mode for a namespace prefix.
Returns the configuration for a single namespace prefix.
Returns configuration entries for all namespaces that have explicit overrides.
Resets the configuration for a single namespace prefix back to defaults.
Resets all namespace configurations back to defaults.
Sets a configuration field for the given namespace prefix.
Sets a configuration field for the given namespace prefix with caller identity.
Starts the NamespaceConfig GenServer and creates the backing ETS table.
Returns the effective window_ms for a namespace prefix.
Types
@type field() :: :window_ms | :durability
Valid field names for set/3.
@type ns_entry() :: %{ prefix: binary(), window_ms: non_neg_integer(), durability: :quorum | :async, changed_at: non_neg_integer(), changed_by: binary() }
A namespace configuration entry.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Returns the default durability mode.
@spec default_window_ms() :: pos_integer()
Returns the default window_ms value.
@spec durability_for(binary()) :: :quorum | :async
Returns the effective durability mode for a namespace prefix.
Falls back to the default (:quorum) when no override exists.
Parameters
prefix-- namespace prefix string
Returns
:quorum or :async.
Returns the configuration for a single namespace prefix.
If the prefix has no explicit override, returns the default configuration.
Parameters
prefix-- namespace prefix string
Returns
{:ok, ns_entry()}-- always succeeds; returns defaults for unconfigured prefixes
Examples
iex> Ferricstore.NamespaceConfig.get("rate")
{:ok, %{prefix: "rate", window_ms: 1, durability: :quorum, changed_at: 0, changed_by: ""}}
@spec get_all() :: [ns_entry()]
Returns configuration entries for all namespaces that have explicit overrides.
Returns an empty list when no overrides have been set.
Returns
A list of ns_entry() maps, sorted by prefix.
@spec reset(binary()) :: :ok
Resets the configuration for a single namespace prefix back to defaults.
Deletes the explicit override from ETS. Subsequent calls to get/1,
window_for/1, and durability_for/1 will return default values.
Parameters
prefix-- namespace prefix string
Returns
:ok-- always succeeds (no-op if the prefix had no override)
@spec reset_all() :: :ok
Resets all namespace configurations back to defaults.
Deletes all explicit overrides from ETS.
Returns
:ok
Sets a configuration field for the given namespace prefix.
Parameters
prefix-- namespace prefix string (e.g."rate")field-- field name string:"window_ms"or"durability"value-- field value string: a positive integer forwindow_ms, or"quorum"/"async"fordurability
Returns
:okon success{:error, reason}when the field name or value is invalid
Examples
iex> Ferricstore.NamespaceConfig.set("rate", "window_ms", "10")
:ok
iex> Ferricstore.NamespaceConfig.set("ts", "durability", "async")
:ok
Sets a configuration field for the given namespace prefix with caller identity.
Behaves identically to set/3 but also records changed_by for audit
trail purposes.
Parameters
prefix-- namespace prefix stringfield-- field name string:"window_ms"or"durability"value-- field value stringchanged_by-- identity of the caller making the change
Returns
:okon success{:error, reason}when the field name or value is invalid
@spec start_link(keyword()) :: GenServer.on_start()
Starts the NamespaceConfig GenServer and creates the backing ETS table.
@spec window_for(binary()) :: pos_integer()
Returns the effective window_ms for a namespace prefix.
Falls back to the default (1) when no override exists.
Parameters
prefix-- namespace prefix string
Returns
A positive integer representing the commit window in milliseconds.