macula_gossip (macula v0.20.5)
View SourceGossip protocol for CRDT state replication.
Implements a gossip-based protocol for eventually-consistent state synchronization across nodes. Uses push-pull-push anti-entropy:
- Push: Periodically sends local state changes to random peers - Pull: Requests state from peers when needed - Anti-entropy: Full state synchronization to repair divergence
Configuration Parameters: - push_interval: 1000ms (how often to push to peers) - anti_entropy_interval: 30000ms (how often to run anti-entropy) - fanout: 3 (number of peers to contact per round)
Summary
Functions
Add a peer to the gossip list.
Trigger anti-entropy synchronization.
Delete a CRDT value.
Force synchronization with all peers.
Get a CRDT value.
Get all stored CRDT states.
Get the list of known peers.
Get gossip statistics.
Handle incoming gossip_pull message.
Handle incoming gossip_pull_reply message.
Handle incoming gossip_push message.
Handle incoming gossip_sync message.
Handle incoming gossip_sync_reply message.
Pull state from a specific peer.
Push local state to a specific peer.
Store a CRDT value. Type is the CRDT type: lww_register, or_set, gcounter, pncounter
Remove a peer from the gossip list.
Start the gossip server.
Stop the gossip server.
Types
-type gossip_state() :: #state{node_id :: binary(), realm :: binary(), states :: #{binary() => {atom(), term(), map()}}, pending_pulls :: #{binary() => {pid(), reference()}}, peers :: [binary()], send_fn :: fun((binary(), map()) -> ok | {error, term()}), push_interval :: pos_integer(), anti_entropy_interval :: pos_integer(), fanout :: pos_integer(), push_timer :: reference() | undefined, anti_entropy_timer :: reference() | undefined, push_count :: non_neg_integer(), pull_count :: non_neg_integer(), merge_count :: non_neg_integer(), conflict_count :: non_neg_integer()}.
Functions
Add a peer to the gossip list.
-spec anti_entropy(pid()) -> ok.
Trigger anti-entropy synchronization.
Delete a CRDT value.
-spec force_sync(pid()) -> ok.
Force synchronization with all peers.
Get a CRDT value.
Get all stored CRDT states.
Get the list of known peers.
Get gossip statistics.
Handle incoming gossip_pull message.
Handle incoming gossip_pull_reply message.
Handle incoming gossip_push message.
Handle incoming gossip_sync message.
Handle incoming gossip_sync_reply message.
Pull state from a specific peer.
Push local state to a specific peer.
Store a CRDT value. Type is the CRDT type: lww_register, or_set, gcounter, pncounter
Remove a peer from the gossip list.
Start the gossip server.
-spec stop(pid()) -> ok.
Stop the gossip server.