barrel_p2p_replica_log (barrel_p2p v0.1.0)

View Source

Summary

Functions

Append a delta (the concrete OR-Map entries just minted, so replay never re-mints an HLC). A non-map or empty delta is ignored.

Close the log cleanly (called from the owner's terminate/2).

Remove the on-disk files for Name under Dir. Idempotent; used by delete_map/1 so a re-created map does not reload stale data.

Open (creating if needed) the store for Name under Dir and return the recovered OR-Map (snapshot with the logged deltas merged on top). The caller must barrel_p2p_ormap:absorb_clock/1 the result.

Write the full map to the snapshot atomically, then truncate the log. Bounds the log and purges GC'd tombstones from disk.

Flush the log to disk (persisted-before-ack for user writes).

Types

handle/0

-type handle() :: undefined | #{name := atom(), log := atom(), snapshot := file:filename_all()}.

Functions

append(Handle, Delta)

-spec append(handle(), barrel_p2p_ormap:ormap()) -> ok.

Append a delta (the concrete OR-Map entries just minted, so replay never re-mints an HLC). A non-map or empty delta is ignored.

close(_)

-spec close(handle()) -> ok.

Close the log cleanly (called from the owner's terminate/2).

delete(Name, Dir)

-spec delete(atom(), file:filename_all()) -> ok.

Remove the on-disk files for Name under Dir. Idempotent; used by delete_map/1 so a re-created map does not reload stale data.

open(Name, Dir)

-spec open(atom(), file:filename_all()) -> {ok, handle(), barrel_p2p_ormap:ormap()} | {error, term()}.

Open (creating if needed) the store for Name under Dir and return the recovered OR-Map (snapshot with the logged deltas merged on top). The caller must barrel_p2p_ormap:absorb_clock/1 the result.

snapshot(_, Map)

-spec snapshot(handle(), barrel_p2p_ormap:ormap()) -> ok | {error, term()}.

Write the full map to the snapshot atomically, then truncate the log. Bounds the log and purges GC'd tombstones from disk.

sync(_)

-spec sync(handle()) -> ok.

Flush the log to disk (persisted-before-ack for user writes).