Applies replicated writes on the local node and handles bulk partition transfers when a new node joins or a full sync is requested.
Replication Modes
:async— Fire-and-forget via a lightweight worker pool (Task.Supervisor). Eliminates per-operationspawn/1overhead.:sync— Adaptive quorum writes. Returns:okonce a strict majority of replicas acknowledge, avoiding waits for slow stragglers.:strong— Write-Ahead Log (WAL) based consistency. Replaces heavy 3PC with fast local write + async replication + majority ack (~200µs vs ~1500µs).
Every call to replicate/3 increments the appropriate
replicate_<mode> counter in SuperCache.Cluster.Metrics and records
a latency sample so the results are visible in
SuperCache.Cluster.Stats.api/0.
Summary
Functions
Apply a replicated operation on this node.
Apply a batch of replicated operations on this node.
Push all records for partition_idx to target_node in batches.
Replicate a batch of operations to all replicas in a single :erpc call.
Functions
@spec apply_op(non_neg_integer(), atom(), any()) :: :ok
Apply a replicated operation on this node.
Called via :erpc from the primary or worker pool — do NOT call directly.
@spec apply_op_batch(non_neg_integer(), atom(), [any()]) :: :ok
Apply a batch of replicated operations on this node.
Called via :erpc from the primary — do NOT call directly.
@spec push_partition(non_neg_integer(), node()) :: :ok
Push all records for partition_idx to target_node in batches.
@spec replicate(non_neg_integer(), atom(), any()) :: :ok | {:error, term()}
@spec replicate_batch(non_neg_integer(), atom(), [any()]) :: :ok | {:error, term()}
Replicate a batch of operations to all replicas in a single :erpc call.
Dramatically reduces network overhead for bulk writes by sending all operations in one message instead of one message per operation.