erllama_cache_disk_srv (erllama v0.1.0)
View SourceDisk tier server (read_write mode).
One server per disk root directory. Owns no ETS tables; the disk itself is the source of truth for slabs. Reads, writes, and deletes all funnel through the gen_server, which keeps file ordering sequential per directory.
Save pipeline (save/3):
- Build framed bytes via
erllama_cache_kvc:build/2. - Open writer-unique temp file
<hex>.kvc.<writer_id>.tmpwith O_EXCL. prim_file:write/2an iolist of[Prefix, Payload]. Multi-GB payloads are not concatenated in BEAM memory; the IO subsystem uses writev under the hood.prim_file:datasync/1, then close.prim_file:make_link/2to publish at<hex>.kvc. EEXIST is handled: if the existing file is a valid KVC for this Key, we adopt it (delete our temp). Otherwise we delete the corrupt file and retry once.erllama_nif:fsync_dir/1on the root.- Reopen the published file and parse it (validation belt-and- braces against FS bugs).
Returns {ok, Header, Size} on success. The caller is responsible
for the meta_srv:reserve_save -> check_reservation -> mark_published -> announce_saved protocol around this call (the writer pool in
step 10 wires that up).
On startup, the server scans its directory: deletes any *.tmp
files (interrupted writes; safe to drop), parses every <hex>.kvc
header, and registers each valid file with the meta server. Files
that fail to parse are deleted.
Summary
Types
Functions
-spec abort_tmp(write_out()) -> ok.
-spec delete(atom(), erllama_cache:cache_key()) -> ok.
-spec load(atom(), erllama_cache:cache_key()) -> {ok, erllama_cache_kvc:info(), binary()} | miss | {error, term()}.
-spec publish(write_out()) -> {ok, erllama_cache:cache_key(), binary(), non_neg_integer()} | {error, term()}.
-spec publish(file:name(), file:name(), file:name(), erllama_cache:cache_key()) -> {ok, erllama_cache:cache_key(), binary(), non_neg_integer()} | {error, term()}.
-spec save(atom(), erllama_cache_kvc:build_meta(), binary()) -> {ok, erllama_cache:cache_key(), binary(), non_neg_integer()} | {error, term()}.
-spec scan(atom()) -> [{erllama_cache:cache_key(), binary(), non_neg_integer()}].
-spec touch_hits(file:name(), non_neg_integer()) -> ok.
-spec write_tmp(file:name(), erllama_cache_kvc:build_meta(), binary()) -> {ok, write_out()} | {error, term()}.