ARC 3Understand Replication and RepairChapters 10–14

Chapter 12 — Digest-Based Difference Detection and Replica Repair

Chapter objective: After this chapter, a developer can detect differences with a digest, explain replay/snapshot selection, and reject a repair that would move the requester backward.

Learning objectives

  1. Connect digest, anti-entropy, and repair.
  2. Select replay or snapshot from retention and estimated cost.
  3. Detect regression when the requester is newer or more complete at the same sequence.
  4. Separate current-state repair from business-event replay.

Prerequisites

Case progress

node-b misses ten route-hint updates while offline. On return it reports its collection digest. The source decides whether retained deltas can close the gap or a current-state snapshot is more appropriate; B does not request every business event.

From difference to repair plan

Repair chooses replay, snapshot, or rejects regression

A digest summarizes state so peers can compare observed sequence, entry count, or bucket hash. It carries no complete values and is not automatically authoritative; it supplies input to negotiation.

AdaptiveRepairPlanner follows four boundaries:

  1. No difference produces NONE.
  2. A requester that is ahead, or more complete at the same sequence, does not receive an older snapshot.
  3. When the requester remains inside the source's replay window, estimated replay and snapshot costs are compared.
  4. When replay is unavailable, snapshot restores current state.

Replay and snapshot differ in more than size

Dimension Replay Snapshot
Content retained deltas after a sequence chunked current collection state
Fit continuous gap inside retention gap too old/large or snapshot cheaper
Benefit incremental and ordered evolution independent of complete delta history
Risk retention exhausted; many small messages large transfer; safe assembly and switch needed
It is not business audit replay database backup or cross-resource recovery

Adaptive choice uses latency, throughput, and history in a peer profile. Without a profile, the planner falls back to a fixed strategy, which is more predictable than reacting to one slow request.

Repair cannot move state backward

If requester sequence is 101 while the source has 100, a hash difference does not authorize the source to overwrite the requester. At an equal sequence, a requester with more entries also rejects a smaller source snapshot. AdaptiveRepairPlannerTest fixes both cases at RepairMode.NONE.

Anti-entropy is a continuing control loop

exchange digest → detect difference → plan repair → transfer → apply → compare again

Control messages can also be lost. ChaosIntegrationTest injects 50% control-plane loss and shows that later sweeps can still detect and repair the difference. Completion of one request only proves one operation; equal final digests establish the repair outcome.

Counterexample and fault injection

Experiment

cd submodule/dsm
mvn -q -pl dsm-sync,dsm-integration-test -am \
  -Dtest=AdaptiveRepairPlannerTest,ChaosIntegrationTest \
  -Dsurefire.failIfNoSpecifiedTests=false test

For each requester/source pair in repair-scenarios.json, select NONE, REPLAY, or SNAPSHOT and state the reason for avoiding regression.

Experiment acceptance card

Field Content
Command The focused Maven tests above; node --test tests/chapter-assets.test.mjs
Input or fault inside/outside replay retention, cost samples, requester ahead, and control loss
Observable result explainable planner choice; requester never regresses; a later sweep repairs the gap
Evidence level E2 planner behavior plus E3 chaos repair
This experiment does not prove Optimal thresholds at production scale, cross-region bandwidth cost, or complete business history

Review

Next

Chapter 13 turns to observers: a slow subscriber can overflow the local change buffer even when collection replicas converge.