# `PaxosKV.Helpers`

Internal 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.

# `flush_messages`

Removes all the given messages from the process mailbox.

# `monitor_key`

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.

# `monitor_node`

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.

# `monitor_pid`

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.

# `name`

Returns `{bucket_name, full_module_name}` for the given bucket suffix.

# `node_alive?`

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

# `process_alive?`

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

# `quorum?`

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

# `random_backoff`

Sleeps for a random duration between 0 and 750 milliseconds.

Used for implementing randomized backoff when retrying operations
to avoid thundering herd problems.

# `still_valid?`

Checks if a value-metadata tuple is still valid (pid alive, node connected, time not expired).

# `wait_for`

This is a synchronization function. It blocks the caller until the `predicate`
function returns a truthy value (anything but `nil` or `false`).

# `wait_for_bucket`

Blocks until the bucket's learner, acceptor, and proposer processes are ready.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
