barrel_p2p_map (barrel_p2p v0.1.0)

View Source

Summary

Functions

Stop the map on THIS node (node-local; not a cluster-wide erase). Also removes any persisted files, so a later new/2 starts fresh rather than reloading stale data. stop_map/1 is synchronous (it waits for the owner to terminate, which closes the log), so the delete runs strictly AFTER the log is closed - no terminate/2 write can race the delete. The file delete is a no-op for a map that did not persist.

Look up a live value (lock-free ETS read).

Live keys (lock-free ETS read).

Start a replicated map named Name on this node. Idempotent.

Put Value under Key. Rejected with {error, invalid_value} if the map's validator rejects the value.

Remove Key.

Subscribe the calling process to {barrel_p2p_map, Name, Event} change events, where Event is {put, Key, Value} or {remove, Key}.

Live key/value pairs (lock-free ETS read).

Types

opts/0

-type opts() ::
          #{validator => fun((term()) -> boolean()) | {module(), atom()},
            tombstone_ttl_ms => non_neg_integer(),
            scan_ms => pos_integer(),
            prune_on_peer_down => boolean(),
            persist => boolean()}.

Functions

delete(Name, Key)

-spec delete(atom(), term()) -> ok | {error, no_such_map}.

Alias for remove/2.

delete_map(Name)

-spec delete_map(atom()) -> ok.

Stop the map on THIS node (node-local; not a cluster-wide erase). Also removes any persisted files, so a later new/2 starts fresh rather than reloading stale data. stop_map/1 is synchronous (it waits for the owner to terminate, which closes the log), so the delete runs strictly AFTER the log is closed - no terminate/2 write can race the delete. The file delete is a no-op for a map that did not persist.

get(Name, Key)

-spec get(atom(), term()) -> {ok, term()} | not_found.

Look up a live value (lock-free ETS read).

handle_call(Req, From, State)

handle_cast(Msg, State)

handle_info(Info, State)

init(_)

keys(Name)

-spec keys(atom()) -> [term()].

Live keys (lock-free ETS read).

new(Name)

-spec new(atom()) -> {ok, pid()} | {error, term()}.

Start a replicated map named Name on this node. Idempotent.

new(Name, Opts)

-spec new(atom(), opts()) -> {ok, pid()} | {error, term()}.

owner_name(Name)

put(Name, Key, Value)

-spec put(atom(), term(), term()) -> ok | {error, invalid_value | no_such_map}.

Put Value under Key. Rejected with {error, invalid_value} if the map's validator rejects the value.

remove(Name, Key)

-spec remove(atom(), term()) -> ok | {error, no_such_map}.

Remove Key.

replica_anti_entropy()

replica_apply_full_sync(ReplicaName, Snapshot)

replica_full_sync_snapshot(ReplicaName)

replica_merge_delta(ReplicaName, Delta)

replica_name(Name)

replica_remove_node(ReplicaName, Node)

start_link(Name, Opts)

subscribe(Name)

-spec subscribe(atom()) -> ok | {error, no_such_map}.

Subscribe the calling process to {barrel_p2p_map, Name, Event} change events, where Event is {put, Key, Value} or {remove, Key}.

subscribe(Name, Pid)

-spec subscribe(atom(), pid()) -> ok | {error, no_such_map}.

tab_name(Name)

terminate(Reason, State)

to_list(Name)

-spec to_list(atom()) -> [{term(), term()}].

Live key/value pairs (lock-free ETS read).

unsubscribe(Name)

-spec unsubscribe(atom()) -> ok | {error, no_such_map}.

unsubscribe(Name, Pid)

-spec unsubscribe(atom(), pid()) -> ok | {error, no_such_map}.