All articles

Adaptive Regulation of Cassandra Repair

Running repair on a small Cassandra cluster can give you very little reason to worry about it until the data grows and the same job starts competing with production queries for CPU and disk I/O. I’ve spent enough time operating Cassandra to want repair to take care of itself without having to choose between keeping replicas consistent and keeping query latency under control.

We used Reaper before building our own repair tooling and still encountered periods when repair put more pressure on a cluster than we were comfortable with. I wanted a system that could follow changes in the workload and adjust repair as it progressed rather than rely on settings chosen before the run started.

Cassandra repair execution model

Cassandra repair compares data held by replicas and reconciles differences between copies that should agree. Cassandra provides the repair mechanism through JMX and operators commonly invoke it with nodetool. Repairs need to run regularly so that replicas receive missed updates and deletions before tombstones can be removed.

At the command line, the most familiar form of this is:

nodetool repair -full -pr

Completing this full primary-range repair across the cluster requires coordinating runs on all nodes rather than invoking it on one node and considering the job finished. Each run works through the replica data for the primary ranges and tables in scope.

Comparing replicas requires scanning their data to generate Merkle trees for each table and token range being repaired. Cassandra compares those trees to identify differences and then streams data to bring the replicas into agreement.

Generating Merkle trees consumes CPU and disk bandwidth that the node also needs for queries and background work. A node already busy with compaction or flushing has less capacity available for validation without affecting the applications using it.

You may see I/O wait rise alongside pending threadpool tasks as the extra work accumulates. Replica latency can increase before the effect becomes apparent in coordinator latency, which is why watching only the application-facing measurements can miss the pressure developing underneath.

We need to account for that resource usage when deciding how much repair work to launch alongside production traffic.

Info

If you want the underlying Cassandra mechanics in more detail, these references are the right places to start:

Token-range segmentation and repair granularity

Working through smaller token ranges gives us more control over how much repair work a node takes on at once. Cassandra has long supported this through nodetool, allowing an orchestrator to divide the work into segments and decide when to launch each one.

Smaller validation jobs give the orchestrator more opportunities to pause between segments and spread disk reads over time instead of committing the node to one large repair operation.

The first command below requests a full repair of a table while the second limits repair to a specified token range.

nodetool repair --full my_keyspace my_table
nodetool repair -st <start_token> -et <end_token> my_keyspace my_table

Choosing the segment count still requires care because too few segments leave each validation job large enough to put considerable load on a node. Too many segments add orchestration overhead for very little work per job, so table size needs to inform the choice rather than assigning every table the same count.

Limitations of fixed segmentation and static scheduling

A repair run that starts during a quiet period may still be running when application traffic increases or compaction starts consuming more of the available I/O. Splitting the work into segments does not help enough if the orchestrator keeps launching them at the same rate regardless of what else the cluster is doing.

This was the problem I kept encountering with fixed repair settings because the amount of work a cluster could comfortably absorb changed during the run. We needed to adjust the launch rate and parallelism using measurements taken while repair was running rather than trying to predict the whole repair window in advance.

Control-theory model for repair regulation

We approached this using feedback control, much as a thermostat adjusts heating based on the difference between the measured temperature and the temperature you want. It keeps measuring and adjusting as conditions change instead of assuming that a fixed heating output will keep the house comfortable all day.

For repair we want to complete the work within a deadline derived from each table’s gc_grace_seconds while limiting the impact on queries. The controller therefore needs to measure both repair progress and cluster load so it can determine whether to speed up or give the database more time for other work.

The control outputs are the knobs that repair can really change:

  • pause duration between repair segments
  • repair parallelism

Simple control-theory feedback loop with an input, summing point, controller, output, and feedback path.

Figure: A basic feedback loop. The + symbol is the summing point where the input and feedback are compared. A is the forward controller or gain block that drives the system output. B is the feedback block that returns part of the output so the next control decision can be adjusted.

We borrowed the feedback principle rather than implementing a textbook controller using transfer functions and Laplace-domain analysis. Repair progresses through discrete jobs whose durations vary with the data and with competing work on the cluster. Our controller uses those completion times and live performance measurements to adjust the pause between segments and the number of repairs running concurrently.

Functional requirements for adaptive repair regulation

The repair regulator needs to satisfy a few hard requirements.

  1. Derive each table’s completion deadline from gc_grace_seconds so that repair is scheduled to finish within that window.
  2. Calculate the segment count from table disk usage to keep validation jobs manageable without creating excessive orchestration overhead.
  3. Repair must slow down when the cluster becomes loaded.
  4. Repair must speed up when the cluster has spare capacity and the deadline requires it.
  5. The control loop must use signals that reflect real Cassandra stress rather than a single synthetic score.
  6. Those signals have to be measured frequently enough that short-lived changes are visible while the repair is still running.

With measurements arriving only every 30 or 60 seconds the controller can miss changes that should affect whether it launches the next segment.

Load indicators and control-loop input signals

The repair regulator needs live signals from both Cassandra and Linux.

From Cassandra itself, the useful inputs include:

  • pending threadpool metrics
  • coordinator read and write latencies
  • replica read and write latencies
  • compaction-related pressure
  • repair-related task backlogs where relevant

From the host, the useful inputs include:

  • I/O wait
  • CPU saturation
  • disk throughput pressure
  • network pressure when streaming becomes significant

AxonOps threadpool dashboard showing pending MutationStage and ReadStage activity during live cluster load.

Growing queues in MutationStage or ReadStage tell us that requests are waiting for processing. Continuing to launch repair segments adds validation and streaming work to nodes that are already struggling to keep up with application traffic, so these pending-task measurements are useful inputs when deciding whether to pause.

AxonOps collects Cassandra and Linux performance metrics every five seconds so the controller can respond to increasing queues and latency while the repair is running. Host measurements such as I/O wait help it assess whether the node is under pressure even before that pressure becomes apparent in query latency.

If you want the metric surface behind this in more detail, Cassandra Monitoring Best Practice Series 1: Diagnosing High Latency shows the coordinator, replica, threadpool, table, and host-level metrics that make this kind of control loop possible.

The control model

The first quantity we need is the running average repair time per completed segment:

⟨T⟩=∑i=0ntin\left \langle T \right \rangle = \frac{\sum_{i=0}^{n} t_i}{n}

Here nn counts the segments completed by time tt and tit_i records how long the ii‘th segment took to repair. Averaging those durations gives us an estimate based on work completed during this run.

From there we can express the average repair velocity as segments completed per unit time:

⟨Vsegs⟩=n∑i=0nti=1⟨T⟩\left \langle V_{segs} \right \rangle = \frac{n}{\sum_{i=0}^{n} t_i} = \frac{1}{\left \langle T \right \rangle}

This gives the controller a measured repair rate to compare with the rate needed to finish the remaining work.

The next quantity is the required velocity if the repair is to finish on time:

V′=N−nT−tV' = \frac{N - n}{T - t}

Dividing the remaining segment count N−nN - n by the time left before the deadline T−tT - t gives the completion rate we need for the rest of the run.

If the current repair is moving too quickly for the health of the cluster, the regulator needs to add pause time between segments:

tsleep=T−tN−n−⟨T⟩t_{sleep} = \frac{T - t}{N - n} - \left \langle T \right \rangle

That expression gives the amount of time to wait between repair segments so that repair progress stays aligned with the target end time instead of simply running flat out.

If the current repair is too slow and needs to catch up, the regulator uses parallelism instead:

α=V′⟨Vsegs⟩\alpha = \frac{V'}{\left \langle V_{segs} \right \rangle}

Here, α\alpha expresses the repair parallelism factor as the ratio of required velocity to the measured average velocity.

The controller also adjusts its working target end time as cluster load changes, using a repair-strength term calculated from weighted live measurements:

Rstrength∝∑i=0nwiAMi⟨M⟩R_{strength} \propto \sum_{i=0}^{n}\frac{w_i}{A}\frac{M_i}{\left \langle M \right \rangle}

With:

A=∑i=0nwiA = \sum_{i=0}^{n} w_i

And:

∑i=0nwiA=1\sum_{i=0}^{n}\frac{w_i}{A} = 1

Comparing each live metric MiM_i with its moving average ⟨M⟩\left \langle M \right \rangle lets the controller account for increases relative to that metric’s recent behaviour. Several measurements rising together increase the calculated pressure and allow the controller to reduce repair intensity.

How AxonOps regulates repair in practice

Adaptive repair regulation across Murmur3 token ranges, showing completed repair segments, current progress at time t, remaining segments up to deadline T, and the use of average segment repair time and pause control.

Figure: Adaptive repair regulation across the Murmur3 token space. Completed segments sit to the left of the current state t, i=n, remaining segments sit to the right, and the controller uses the average segment repair time ⟨T⟩, sleep time t_sleep, and the final deadline T to decide how aggressively the next repair work should be launched.

AxonOps compares the measured repair rate with the rate needed to complete the remaining token ranges before the table’s deadline. It uses average segment completion times to estimate progress and live cluster measurements to decide how much additional work the nodes can accommodate.

From there the controller chooses between two complementary ways of adjusting repair intensity.

AxonOps recalculates the pause between segments as measurements arrive and stops launching further work when the cluster is under pressure. As conditions improve it can shorten the pause to increase progress before increasing parallelism where the remaining time budget requires more concurrent work.

AxonOps calculates segment counts for each table using its volume on each node alongside the vnode count and configured segment-size and count limits. This lets larger tables receive finer segmentation without imposing the same orchestration overhead on smaller tables.

At a high level, the embedded segmentation logic looks like this:

input:
  num_tokens_per_node
  table_volume_per_node
  target_segment_size_mb
  max_total_segments

total_table_volume_mb = sum(table_volume_per_node)
total_vnodes = node_count * num_tokens_per_node

if max_total_segments < total_vnodes:
  assign 1 segment per vnode
  return

total_segments = floor(total_table_volume_mb / target_segment_size_mb)

if total_segments > max_total_segments:
  total_segments = max_total_segments
  target_segment_size_mb = floor(total_table_volume_mb / max_total_segments)

for each node:
  node_segments = proportional_share(node_volume / total_table_volume_mb, total_segments)
  segments_per_vnode = max(1, floor(node_segments / num_tokens_per_node))
  per_segment_volume_mb = node_volume / (segments_per_vnode * num_tokens_per_node)

The resulting segments are the units of work the controller schedules against the repair deadline, with pauses and parallelism adjusted according to cluster load as those units complete.

AxonOps adaptive repair policy showing the configured target segment size, maximum segment count per table, repair timeout, retries, concurrency, and gc_grace_seconds threshold.

The policy lets you set segment size and count limits alongside the maximum number of concurrent repair processes. You can also configure timeouts and retries for stalled or failed segments while GC Grace Threshold (seconds) controls the scheduling threshold associated with the table’s repair deadline.

We’ve been running Adaptive Repair across hundreds of Cassandra clusters where differences in table sizes and production workloads continually test these decisions. That experience has informed the implementation because I wanted repair tooling that could keep adjusting throughout a run without an operator having to revisit its settings whenever the workload changed.

5-second metrics resolution as a control-loop requirement

This kind of regulator only works if the measurements are current enough to be useful.

An increase in pending tasks or query latency needs to reach the controller soon enough to affect its next scheduling decision. The same applies to host I/O pressure that may change while a segment is still running.

We use five-second measurements to keep those repair decisions close to the current state of the database and host. Longer intervals leave the controller working with older information and can conceal brief periods of load that would otherwise cause it to pause. I covered the sampling considerations in Time Series Metrics, Sampling Theory, and Enterprise Monitoring.

Apache Cassandra 5.0.8 and CEP-37

Cassandra 5.0.8 includes the CEP-37 repair scheduler, bringing repair orchestration into the database after years of operators arranging it through scripts or tools such as Reaper. I’m pleased to see the community putting this work into Cassandra because it gives teams a built-in way to run repairs without maintaining a separate orchestration service.

The scheduler provides automatic execution and token-range splitting together with node-level history and repair metrics. Teams can configure full and incremental repair policies with table-level enablement and node-level controls that help them manage how repair runs.

Paul Chandler’s write-up of Cassandra Auto Repairs - Part 2 covers these controls and the protective throttles alongside limitations around time-of-day scheduling and repair intervals. He notes that the smallest gc_grace_seconds requirement in scope can determine the interval even when tables have different requirements.

For the workloads we manage with AxonOps we also want repair to respond to pending ReadStage and MutationStage tasks as well as query latency and host I/O pressure. Our controller uses those measurements every five seconds alongside the time remaining before each table’s deadline to adjust how much repair work it launches.

I’m grateful to the people bringing built-in repair scheduling to Cassandra and making it easier for more teams to keep their replicas consistent. Our work on adaptive regulation addresses the additional problem of keeping that repair progressing as production load changes throughout the day.

Closing

Repair has always been necessary in Cassandra, and its hard part has been making it predictable under real production load.

Smaller token ranges give us manageable repair jobs but we still need to decide when to launch them while queries and compaction compete for the same resources. The feedback model gives us a way to make those decisions using measured progress and current load against the time available before each table’s deadline.

That is what we built into AxonOps adaptive repair so that pause times and parallelism can follow the workload without an operator continually tuning them. You can sign up for AxonOps and connect an existing cluster to see how those adjustments work with your own traffic.

Demo Sandbox

Explore AxonOps for Apache Cassandra and Kafka in a live demo environment.

Try it now
All articles