barrel_ngram_corpus_config (barrel_ngram v0.9.0)
View SourceCorpus-level persisted config (corpus.meta).
One file per corpus, regardless of shard count -- unlike the per-shard manifest, this is layout-independent: barrel_ngram_shards ref shapes differ between a single-shard corpus (the bare corpus name) and a multi-shard one ({Corpus, I} per shard), so only a corpus-level file can record shards => N itself durably, closing the "shard count change orphans the old set" gap a per-shard-only manifest could not.
Content: #{version, state, db, db_instance_id, shards, phase2_selector_opts, fields, postings}. state (initializing or active) is internal bookkeeping for crash recovery, not a requested option -- see barrel_ngram_corpus_lifecycle.
Written/read atomically (temp file + rename), matching the existing per-shard manifest's own convention.
Summary
Functions
Remove a stray write-in-progress temp file, if one survived an interrupted save/2 (a VM/coordinator death, or a rename failure, between the temp write and the rename). Safe to call unconditionally, real corpus.meta present or not: the per-corpus lifecycle lock (the coordinator's own via-name registration) guarantees no concurrent writer to the same temp file could ever be racing this cleanup.
Remove the corpus.meta file outright (tolerating enoent).
Load the corpus.meta. Three-way, not collapsed to a boolean: not_found means genuinely no file (a fresh or pre-fix corpus); {error, Reason} means a file exists but could not be read/decoded (truncated, corrupt, permission denied) -- callers must never treat the two the same way (see barrel_ngram_corpus_lifecycle:run_op/2).
Write the corpus.meta atomically (temp + rename).
Types
-type config() :: #{version := pos_integer(), state := initializing | active, db := binary(), db_instance_id := binary(), shards := pos_integer(), phase2_selector_opts := map(), fields := all | [binary()], postings := varint | roaring}.
Functions
-spec cleanup_orphan_tmp(map()) -> ok.
Remove a stray write-in-progress temp file, if one survived an interrupted save/2 (a VM/coordinator death, or a rename failure, between the temp write and the rename). Safe to call unconditionally, real corpus.meta present or not: the per-corpus lifecycle lock (the coordinator's own via-name registration) guarantees no concurrent writer to the same temp file could ever be racing this cleanup.
Remove the corpus.meta file outright (tolerating enoent).
Load the corpus.meta. Three-way, not collapsed to a boolean: not_found means genuinely no file (a fresh or pre-fix corpus); {error, Reason} means a file exists but could not be read/decoded (truncated, corrupt, permission denied) -- callers must never treat the two the same way (see barrel_ngram_corpus_lifecycle:run_op/2).
Write the corpus.meta atomically (temp + rename).