mcl_om_read_model (mcl_om v0.2.2)
View SourceCanonical barrel_docdb read-model wiring for hecate-services.
Encapsulates "open (or create) a database at data_dir/read_model_id". Services don't call this module directly — mcl_om:boot/1 dispatches here when the service module exports the optional read_model_id/0 + data_dir/0 callbacks from mcl_om_service, additionally arming barrel_docdb's native TTL sweeper when the service also exports read_model_ttl_sweep/0.
After boot, a service (its PRJ code, typically) reads/writes the read model with barrel_docdb directly, using the same read_model_id/0 binary as the database name — barrel_docdb accepts the name or the pid interchangeably everywhere, so there is no separate handle to thread through. This mirrors mcl_om_store, which likewise hands nothing back: the service already knows its own store_id/read_model_id.
Summary
Functions
Idempotent. Opens (creating on first boot) a barrel_docdb database named DbName at <DataDir>/<DbName>/, with no TTL sweep (barrel_docdb's default: nothing expires). Equivalent to ensure(DbName, DataDir, disabled).
Same as ensure/2, additionally arming barrel_docdb's native per-document TTL sweeper when TtlSweep is #{interval_ms := integer(), batch := integer()} rather than disabled. Arming the sweeper alone expires nothing — documents also need expires_at set in their own put_doc/3Opts — see the read_model_ttl_sweep/0 callback in mcl_om_service.
Functions
-spec ensure(binary(), file:filename_all()) -> ok | {error, term()}.
Idempotent. Opens (creating on first boot) a barrel_docdb database named DbName at <DataDir>/<DbName>/, with no TTL sweep (barrel_docdb's default: nothing expires). Equivalent to ensure(DbName, DataDir, disabled).
-spec ensure(binary(), file:filename_all(), disabled | #{interval_ms := pos_integer(), batch := pos_integer()}) -> ok | {error, term()}.
Same as ensure/2, additionally arming barrel_docdb's native per-document TTL sweeper when TtlSweep is #{interval_ms := integer(), batch := integer()} rather than disabled. Arming the sweeper alone expires nothing — documents also need expires_at set in their own put_doc/3Opts — see the read_model_ttl_sweep/0 callback in mcl_om_service.