SuperCache.Cluster.Replicator (SuperCache v1.3.0)

Copy Markdown View Source

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-operation spawn/1 overhead.
  • :sync — Adaptive quorum writes. Returns :ok once 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

apply_op(partition_idx, op_name, op_arg)

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

apply_op_batch(partition_idx, op_name, op_args)

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

push_partition(partition_idx, target_node)

@spec push_partition(non_neg_integer(), node()) :: :ok

Push all records for partition_idx to target_node in batches.

replicate(partition_idx, op_name, op_arg \\ nil)

@spec replicate(non_neg_integer(), atom(), any()) :: :ok | {:error, term()}

replicate_batch(partition_idx, op_name, op_args)

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