PaxosKV.Helpers (paxos_kv v0.6.0)
Copy MarkdownInternal utility functions for PaxosKV.
This module provides helper functions for quorum validation, process and node monitoring, synchronization, and value validation. These functions are used internally by other PaxosKV modules.
Summary
Functions
Removes all the given messages from the process mailbox.
Tracks a dependency relationship between two keys.
Tracks that a key is associated with a specific node.
Monitors a process and associates it with a key.
Returns {bucket_name, full_module_name} for the given bucket suffix.
Checks if a node is alive and connected.
Checks if a process is alive, even on remote nodes.
Checks if the list contains enough elements (node names, replies from
nodes, etc.) to consider it a quorum.
Sleeps for a random duration between 0 and 750 milliseconds.
Checks if a value-metadata tuple is still valid (pid alive, node connected, time not expired).
This is a synchronization function. It blocks the caller until the predicate
function returns a truthy value (anything but nil or false).
Blocks until the bucket's learner, acceptor, and proposer processes are ready.
Functions
Removes all the given messages from the process mailbox.
Tracks a dependency relationship between two keys.
If key depends on xkey, this function updates the key_monitors map
to record this relationship. Returns the updated key_monitors map.
Tracks that a key is associated with a specific node.
Updates the node_monitors map to track which keys depend on which nodes. Returns the updated node_monitors map.
Monitors a process and associates it with a key.
If the pid is not nil, it demonitors any existing monitors for the same key, creates a new monitor for the pid, and updates the pid_monitors map.
Returns the updated pid_monitors map.
Returns {bucket_name, full_module_name} for the given bucket suffix.
Checks if a node is alive and connected.
Returns true if the node responds to ping, false otherwise.
Examples
iex> PaxosKV.Helpers.node_alive?(Node.self())
true
Checks if a process is alive, even on remote nodes.
For local processes, uses Process.alive?/1. For remote processes,
performs an RPC call to check the process status on the remote node.
Examples
iex> PaxosKV.Helpers.process_alive?(self())
true
Checks if the list contains enough elements (node names, replies from
nodes, etc.) to consider it a quorum.
Examples
iex> PaxosKV.Helpers.quorum?([:node1, :node2], 3)
true
iex> PaxosKV.Helpers.quorum?([:node1], 3)
false
Sleeps for a random duration between 0 and 750 milliseconds.
Used for implementing randomized backoff when retrying operations to avoid thundering herd problems.
Checks if a value-metadata tuple is still valid (pid alive, node connected, time not expired).
This is a synchronization function. It blocks the caller until the predicate
function returns a truthy value (anything but nil or false).
Blocks until the bucket's learner, acceptor, and proposer processes are ready.