Ferricstore.Config.Local (ferricstore v0.3.7)

Copy Markdown View Source

ETS-backed storage for node-local configuration parameters.

Node-local settings are NOT replicated via Raft and are NOT persisted by CONFIG REWRITE. They are intentionally ephemeral -- on restart, all local settings are lost.

Supported parameters

  • "log_level" -- maps to Logger.configure(level: level). Valid values: "debug", "info", "notice", "warning", "error".

Usage

Ferricstore.Config.Local.set("log_level", "debug")
#=> :ok

Ferricstore.Config.Local.get("log_level")
#=> {:ok, "debug"}

Ferricstore.Config.Local.get_all()
#=> %{"log_level" => "debug"}

Summary

Types

A local configuration parameter name.

A local configuration parameter value.

Functions

Ensures the local config ETS table exists.

Returns the current value of a node-local configuration parameter.

Returns all explicitly set local configuration parameters as a map.

Clears all local configuration settings.

Sets a node-local configuration parameter.

Types

param_name()

@type param_name() :: binary()

A local configuration parameter name.

param_value()

@type param_value() :: binary()

A local configuration parameter value.

Functions

ensure_table()

@spec ensure_table() :: :ok

Ensures the local config ETS table exists.

Called during application startup. Safe to call multiple times.

get(key)

@spec get(param_name()) :: {:ok, param_value()} | {:error, binary()}

Returns the current value of a node-local configuration parameter.

If the parameter has not been explicitly set via CONFIG SET LOCAL, returns the effective current value from the runtime (e.g. the current Logger level).

Parameters

  • key -- parameter name

Returns

  • {:ok, value} when the parameter is known
  • {:error, reason} when the parameter is unknown

Examples

iex> Ferricstore.Config.Local.get("log_level")
{:ok, "warning"}

get_all()

@spec get_all() :: %{required(param_name()) => param_value()}

Returns all explicitly set local configuration parameters as a map.

Parameters that have not been explicitly set are not included.

Returns

A map of %{param_name => param_value}.

reset_all()

@spec reset_all() :: :ok

Clears all local configuration settings.

Does NOT revert side-effects (e.g. Logger level stays at whatever it was last set to). The next get/1 call will read the live value.

set(key, value)

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

Sets a node-local configuration parameter.

Validates the parameter name and value. Applies the corresponding side-effect (e.g. configuring the Logger level).

Parameters

  • key -- parameter name (e.g. "log_level")
  • value -- new value as a string

Returns

  • :ok on success
  • {:error, reason} when the parameter is unknown or the value is invalid

Examples

iex> Ferricstore.Config.Local.set("log_level", "debug")
:ok

iex> Ferricstore.Config.Local.set("bogus", "value")
{:error, "ERR Unsupported local CONFIG parameter: bogus"}