Problem
Replicas drift apart because of missed writes, dropped hints and bit rot. Comparing entire datasets to find differences wastes bandwidth and time. A background process must find only the differing ranges.
Also known as: merkle-tree-repair, replica-repair, anti-entropy
Detect and repair divergence between replicas efficiently by comparing hash trees instead of full datasets.
Replicas drift apart because of missed writes, dropped hints and bit rot. Comparing entire datasets to find differences wastes bandwidth and time. A background process must find only the differing ranges.
Anti-entropy is a background process that makes replicas converge by actively comparing their contents. Merkle trees make the comparison cheap: matching hashes at the top prove entire ranges equal. Cassandra, Riak and DynamoDB-style stores use it as a safety net behind read repair and hints.
root = H(h1 + h2)
/ \
h1 = H(a+b) h2 = H(c+d)
/ \ / \
a b c d (hash of key buckets)
Replica X and Y compare roots -> differ
compare h1: same ; compare h2: differ
compare c: same ; d: differ -> stream keys in bucket d
Each replica builds its tree for a token range, usually via a validation scan. Trees have fixed depth, such as 15 levels, so each leaf covers a range of keys. After diffing, the replicas exchange the keys in mismatched leaves and keep the version with the newest timestamp or merged value.
Extra IO and CPU during repair windows
Medium: schedule and monitor repairs
Medium: tree granularity tuning
Repairs skipped beyond tombstone grace period resurrect deleted data
Tree resolution too coarse streams excess data
Concurrent writes make trees stale and cause repeat repair