Q: When and how do you run incremental versus full anti-entropy repairs in Cassandra, and how do you keep them inside gc_grace_seconds?
Cassandra interview questions on nodetool repair: incremental vs full, -pr, Merkle trees, streaming throttles and finishing within gc_grace_seconds.
Want to master this scenario in a live sandbox? KodeKloud's PostgreSQL Database Administration & High Availability Course covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: Cassandra interview questions on repair are about operational discipline. Repair is how replicas that drifted apart, because of dropped mutations, downtime or an expired hint window, are brought back to the same data. It also protects against deleted data returning, since every tombstone must reach every replica before gc_grace_seconds expires. I explain repair as a scheduled maintenance job with a deadline, not a command I run when something looks wrong. The answer should cover how repair finds differences using Merkle trees, the difference between full and incremental runs, what -pr does, how to limit its network impact, and how to check progress. I stay careful about versions here, because incremental repair behaviour changed between 2.2, 3.x and 4.0, and I always confirm with nodetool help repair on the cluster in front of me.
Explain how repair finds differences with Merkle trees
During repair, each replica builds a Merkle tree, a hash tree over the token range for a table. The coordinator compares trees between replicas and streams only the ranges whose hashes differ. The tree has limited depth, so one mismatched leaf can cause a larger range to stream than the actual damage. That is one reason people run subrange repair on very large partitions.
# Full repair of one keyspace, primary ranges only on this node
nodetool repair -full -pr my_ks
# Typical log markers while it runs
grep -E 'Repair session|Merkle|Sync complete' /var/log/cassandra/system.log | tail
Choose between full and incremental repair
A full repair validates all data in the range, whether or not it was already repaired. An incremental repair validates only data not yet marked repaired, and then marks the SSTables it covered, so each run does less work. Incremental repair became the default for nodetool repair in the 2.2 line, and the 4.0 release reworked it and made it more reliable. I verify the behaviour of my exact version, and I pass -full explicitly when I want a full validation, for example after restoring data or when I suspect repaired and unrepaired data have been mixed.
# Confirm what your version defaults to
nodetool help repair | head -40
# Explicit forms
nodetool repair -full -pr my_ks my_table # full validation
nodetool repair -pr my_ks my_table # follows the version default
Use -pr correctly so each range is repaired once
The -pr flag repairs only the primary token ranges of the node I run it on. If I run nodetool repair -pr on every node in the cluster, every range gets covered exactly once instead of RF times. The trade-off is that -pr is meaningless if I run it on only one node, because the other ranges are skipped. I schedule it across all nodes, one at a time or in small groups, and I do not run it during peak load without a throttle.
# On node1, then node2, then node3 ... (sequentially)
nodetool repair -pr -full my_ks
# Restrict to the local datacenter if cross-DC repair is too heavy
nodetool repair -pr -local my_ks
Throttle streaming and watch it with netstats
Repair streams data between nodes, so I cap the impact. stream_throughput_outbound in cassandra.yaml sets the limit, and nodetool setstreamthroughput changes it at runtime. Units and setting names changed in recent versions, so I check the docs for the version in use. While a repair is running I watch nodetool netstats for streaming progress, and nodetool compactionstats for validation compactions.
# Runtime throttle (megabits per second on many versions)
nodetool getstreamthroughput
nodetool setstreamthroughput 100
nodetool netstats | head -20
nodetool compactionstats
Schedule within gc_grace_seconds and manage incremental sessions
The deadline for a full repair cycle on every node is gc_grace_seconds, 10 days by default. I leave margin, for example a 7 day cycle, so a failed run can be retried. On 4.0 and later, nodetool repair_admin lists and cancels incremental repair sessions, which helps when a session is stuck. For large clusters, a tool such as Cassandra Reaper can schedule subrange repairs, but it is an option and not a requirement.
# Inspect incremental repair sessions (4.0+)
nodetool repair_admin list
nodetool repair_admin cancel --session <session-uuid>
# Check the deadline for a table
cqlsh -e "SELECT gc_grace_seconds FROM system_schema.tables WHERE keyspace_name='my_ks' AND table_name='my_table';"
- Repair compares Merkle trees between replicas and streams only the ranges that differ.
- Full repair checks everything; incremental checks only unrepaired data, and its behaviour differs between versions, so I verify with nodetool help repair.
- I run nodetool repair -pr on every node, throttle streaming, and finish a full cycle well inside gc_grace_seconds.
- For stuck incremental sessions on 4.0 and later I use nodetool repair_admin, and I may use Reaper for scheduled subrange repair.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Running repair -pr on only one node Only that node's primary ranges are covered, so other ranges stay unrepaired and tombstones may be purged before reaching every replica.
- Never repairing because the cluster seems healthy Silent divergence from dropped mutations builds up, and old deleted data can reappear after gc_grace_seconds.
- Running repair at full speed during peak traffic Validation compaction and streaming compete with reads and writes and can push latency past your SLO.
- Mixing full and incremental runs without understanding the repaired state Repaired and unrepaired SSTables are kept apart by compaction, and inconsistent usage can create extra compaction work.