Ferricstore.Application (ferricstore v0.3.4)

Copy Markdown View Source

OTP Application for the FerricStore core engine.

Starts the core supervision tree: shards, Raft, ETS tables, merge schedulers, PubSub, and MemoryGuard. Network-facing children (Ranch TCP/TLS listener, HTTP health endpoint) are started by the separate :ferricstore_server application.

Supervision tree (:one_for_one)

Ferricstore.Supervisor
 Ferricstore.Stats                   (global counters & run metadata)
 Ferricstore.SlowLog                 (slow command log)
 Ferricstore.AuditLog                (audit trail)
 Ferricstore.Config                  (runtime config)
 Ferricstore.NamespaceConfig         (per-namespace overrides)
 (ACL moved to ferricstore_server)
 Ferricstore.HLC                     (Hybrid Logical Clock)
 Ferricstore.Raft.Batcher (x N)     (group-commit batchers)
 Ferricstore.Store.BitcaskWriter (x N) (background Bitcask flushers)
 Ferricstore.Store.RmwCoordinator (x N) (async RMW contention fallback)
 Ferricstore.Store.ShardSupervisor   (one_for_one over N Shard GenServers)
 Ferricstore.Merge.Supervisor        (Semaphore + N Scheduler GenServers)
 Ferricstore.PubSub
 Ferricstore.FetchOrCompute
 Ferricstore.MemoryGuard

Stats starts first so counters are available before any connection arrives. The ShardSupervisor must start before the Ranch listener (in the server app) so that the key-value store is ready before any client connection arrives.

Configuration (application env)

  • :data_dir - Bitcask data directory (default: "data")
  • :shard_count - Number of shards (default: System.schedulers_online())
  • :max_memory_bytes - Memory budget for eviction (default: 1 GiB)

Summary

Functions

Scans all shard ETS tables for values exceeding the configured threshold.

Functions

scan_large_values(shard_count, threshold_bytes \\ nil)

@spec scan_large_values(non_neg_integer(), non_neg_integer()) ::
  {non_neg_integer(), binary() | nil, non_neg_integer()}

Scans all shard ETS tables for values exceeding the configured threshold.

Returns {count, largest_key, largest_size} where count is the number of entries whose value exceeds threshold_bytes, largest_key is the key with the largest value, and largest_size is its size in bytes.

Returns {0, nil, 0} when no large values are found.

This is a pure RAM scan -- ETS already holds the full value per entry, so no disk reads are needed.

Parameters

  • shard_count -- number of shards to scan
  • threshold_bytes -- values larger than this are flagged (default: Application.get_env(:ferricstore, :embedded_large_value_warning_bytes, 512 * 1024))