Ferricstore.NamespaceConfig (ferricstore v0.4.1)

Copy Markdown View Source

GenServer managing per-namespace commit-window configuration.

Stores namespace-specific window overrides in :ferricstore_ns_config. Prefixes with no explicit override use a 1ms commit window.

Durability mode is intentionally not configurable. All writes use the quorum path. A future acknowledgement policy such as ack=all should be added as a separate feature, not by reviving the removed durability-mode switch.

ETS schema

{prefix, window_ms, changed_at, changed_by}

Where:

  • prefix -- binary namespace prefix (e.g. "rate", "session")
  • window_ms -- commit window in milliseconds (positive integer)
  • changed_at -- Unix timestamp (seconds) of the last change, or 0 for defaults
  • changed_by -- identifier of the client that made the change (empty string for defaults)

Summary

Types

Valid field names for set/3.

A namespace configuration entry.

Functions

Returns a specification to start this module under a supervisor.

Returns the default window_ms value.

Returns the configuration for a single namespace prefix.

Returns all explicitly configured namespace entries sorted by prefix.

Resets one namespace prefix to the default window.

Resets all namespace window overrides.

Sets a configuration field for the given namespace prefix.

Sets a configuration field and records caller identity for audit.

Starts the NamespaceConfig GenServer and creates the backing ETS table.

Returns the effective window_ms for a namespace prefix.

Types

field()

@type field() :: :window_ms

Valid field names for set/3.

ns_entry()

@type ns_entry() :: %{
  prefix: binary(),
  window_ms: non_neg_integer(),
  changed_at: non_neg_integer(),
  changed_by: binary()
}

A namespace configuration entry.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

default_window_ms()

@spec default_window_ms() :: pos_integer()

Returns the default window_ms value.

get(prefix)

@spec get(binary()) :: {:ok, ns_entry()}

Returns the configuration for a single namespace prefix.

get_all()

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

Returns all explicitly configured namespace entries sorted by prefix.

reset(prefix)

@spec reset(binary()) :: :ok

Resets one namespace prefix to the default window.

reset_all()

@spec reset_all() :: :ok

Resets all namespace window overrides.

set(prefix, field, value)

@spec set(binary(), binary(), binary()) :: :ok | {:error, binary()}

Sets a configuration field for the given namespace prefix.

Only window_ms is supported. Durability is not configurable.

set(prefix, field, value, changed_by)

@spec set(binary(), binary(), binary(), binary()) :: :ok | {:error, binary()}

Sets a configuration field and records caller identity for audit.

start_link(opts \\ [])

@spec start_link(keyword()) :: GenServer.on_start()

Starts the NamespaceConfig GenServer and creates the backing ETS table.

window_for(prefix)

@spec window_for(binary()) :: pos_integer()

Returns the effective window_ms for a namespace prefix.