Malachi.Cluster.Catchup (malachi v0.8.13)

View Source

Copies a segment's records from a source replica to a target replica, offset range [from_offset, to_offset). This is the primitive behind two recoveries:

  • a follower that fell behind on the active segment catching the gap back up, and
  • a freshly placed replica (from Malachi.Cluster.Placement.heal/3) backfilling an entire sealed segment so it can carry its share of the replica set.

It runs as external orchestration, in the caller's process, issuing ordinary Malachi.Cluster.ReplicationServer calls to both servers (read/4 on the source, follow/4 on the target). Nothing runs inside a server's call while that server is being waited on, so it cannot deadlock the primary↔follower path the way an in-line pull would.

from_offset must be the target's current end for the segment (or the segment's base when the target holds none of it yet), so the appended records line up; Malachi.Cluster.ReplicationServer.end_offset/2 gives that for an existing replica. The source must hold the records being copied; if it is itself behind and runs out before to_offset, the copy stops at what the source has and returns the offset reached: the caller can check it against the target and pick another source.

Summary

Functions

Copies segment_id from source to target over [from_offset, to_offset). Returns {:ok, reached_offset}: the target's new end, which equals to_offset on full catch-up or less if the source ran out first, or {:error, {:source | :target, reason}}.

Functions

run(target, source, segment_id, from_offset, to_offset, opts \\ [])

@spec run(term(), term(), term(), non_neg_integer(), non_neg_integer(), keyword()) ::
  {:ok, non_neg_integer()} | {:error, {:source | :target, term()}}

Copies segment_id from source to target over [from_offset, to_offset). Returns {:ok, reached_offset}: the target's new end, which equals to_offset on full catch-up or less if the source ran out first, or {:error, {:source | :target, reason}}.

Options

  • :batch_size - records copied per round trip (default 1000).