FerricStore.Instance (ferricstore v0.3.3)

Copy Markdown View Source

Instance context for a FerricStore instance.

Each instance owns its own shards, ETS tables, Raft system, atomics, and config — fully isolated from other instances. The context struct holds all references needed to route operations without any global state (no persistent_term lookups).

Created by FerricStore.Instance.Supervisor.start_link/2 and cached in persistentterm per module name for ~0ns access via `_instance/0`.

Fields

All fields are set once at startup and never change (except atomics/counters which are mutable shared references).

Summary

Functions

Builds the instance context from the given options.

Removes the cached instance context.

Retrieves the cached instance context for the given module name.

Injects optional callbacks into an existing instance.

Types

t()

@type t() :: %FerricStore.Instance{
  checkpoint_flags: reference(),
  config_table: atom() | reference(),
  connected_clients_fn: (-> non_neg_integer()),
  data_dir: binary(),
  disk_pressure: reference(),
  durability_mode: atom(),
  eviction_policy: atom(),
  hot_cache_max_value_size: non_neg_integer(),
  hotness_table: atom() | reference(),
  keydir_binary_bytes: reference(),
  keydir_max_ram: non_neg_integer(),
  keydir_refs: tuple(),
  latch_refs: term(),
  lfu_decay_time: non_neg_integer(),
  lfu_initial_ref: reference(),
  lfu_log_factor: non_neg_integer(),
  max_active_file_size: non_neg_integer(),
  max_memory_bytes: non_neg_integer(),
  memory_limit: non_neg_integer(),
  name: atom(),
  pressure_flags: reference(),
  process_rss_fn: (-> non_neg_integer() | nil) | nil,
  ra_system: atom(),
  raft_apply_hook: (term() -> term()) | nil,
  raft_enabled: boolean(),
  read_sample_rate: non_neg_integer(),
  server_info_fn: (-> map()),
  shard_count: non_neg_integer(),
  shard_names: tuple(),
  slot_map: tuple(),
  stats_counter: reference(),
  sync_flush_timeout_ms: non_neg_integer(),
  write_version: reference()
}

Functions

build(name, opts)

@spec build(
  atom(),
  keyword()
) :: t()

Builds the instance context from the given options.

This creates all the shared mutable references (atomics, counters, ETS tables) and computes the immutable config values. The returned context is stored in persistent_term for the module name.

cleanup(name)

@spec cleanup(atom()) :: :ok

Removes the cached instance context.

get(name)

@spec get(atom()) :: t()

Retrieves the cached instance context for the given module name.

inject_callbacks(name, callbacks)

@spec inject_callbacks(
  atom(),
  keyword()
) :: t()

Injects optional callbacks into an existing instance.

Used by server apps (e.g., ferricstore_server) to provide server-specific functions without the library needing to know about the server.

Accepted keys: :connected_clients_fn, :process_rss_fn, :server_info_fn.

update_durability_mode(name, mode)

@spec update_durability_mode(atom(), atom()) :: t()