apache/cassandra · error · RuntimeException
Unknown compaction metric
Error message
Unknown compaction metric
What it means
getCompactionMetric uses a switch over metricName; any name outside the supported set (CompactionCompleted, TotalCompactionsCompleted, PendingCompactions, etc.) hits the default branch and throws RuntimeException("Unknown compaction metric " + metricName). It is a fail-fast guard against unsupported metric names.
Solutions
- Use one of the supported compaction metric names exactly as spelled in NodeProbe's switch (case-sensitive).
- Check the NodeProbe source for your Cassandra version to enumerate valid names.
- Add the case to NodeProbe and rebuild if you need a metric that is legitimately present in JMX but not exposed here.
- Wrap the call in try-catch to convert the failure into a clear config error in your tooling.
Example fix
// before
probe.getCompactionMetric("CompactionsCompleted"); // unknown
// after
probe.getCompactionMetric("TotalCompactionsCompleted"); Defensive patterns
Strategy: try-catch
Validate before calling
Set<String> VALID = Set.of("PendingCompactions", "CompletedCompactions", "CompactionsAborted", "CompactionsReduced", "TotalCompactionsCompleted");
if (!VALID.contains(metricName)) throw new IllegalArgumentException("Unknown compaction metric: " + metricName); Try / catch
try {
return probe.getCompactionMetric(metricName);
} catch (RuntimeException e) {
if (String.valueOf(e.getMessage()).startsWith("Unknown compaction metric"))
throw new IllegalArgumentException(e.getMessage() + " — valid: PendingCompactions, CompletedCompactions, TotalCompactionsCompleted, ...", e);
throw e;
} Prevention
- Match case exactly — the switch is case-sensitive
- Re-check metric names after each Cassandra version bump
- Enumerate supported names from the NodeProbe switch of your build
- Prefer type-specific accessors over guessing names
When it happens
Trigger: Calling getCompactionMetric(metricName) with a string not matched by any case label — e.g. a misspelled name or a metric that exists in a different Cassandra version but not this one.
Common situations: Monitoring configs written for a different Cassandra release; typos like 'totalCompactionsCompleted' (wrong case); renaming of compaction metrics between major versions.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Unknown client metric
- Unknown metric
- appendAll() can only be called on non-frozen collections
- Can not initialize cluster with empty cluster identifier
- Can't abort bootstrap for - it does not exist in cluster…
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/b4a9f08c1796be97.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/tools/NodeProbe.java:2278
case "CompressedBytesCompacted":
case "CompactionsAborted":
case "CompactionsReduced":
case "SSTablesDroppedFromCompaction":
return JMX.newMBeanProxy(mbeanServerConn,
new ObjectName("org.apache.cassandra.metrics:type=Compaction,name=" + metricName),
CassandraMetricsRegistry.JmxCounterMBean.class);
case "CompletedTasks":
case "PendingTasks":
case "PendingTasksByTableName":
return JMX.newMBeanProxy(mbeanServerConn,
new ObjectName("org.apache.cassandra.metrics:type=Compaction,name=" + metricName),
CassandraMetricsRegistry.JmxGaugeMBean.class).getValue();
case "TotalCompactionsCompleted":
return JMX.newMBeanProxy(mbeanServerConn,
new ObjectName("org.apache.cassandra.metrics:type=Compaction,name=" + metricName),
CassandraMetricsRegistry.JmxMeterMBean.class);
default:
throw new RuntimeException("Unknown compaction metric " + metricName);
}
}
catch (MalformedObjectNameException e)
{
throw new RuntimeException(e);
}
}
/**
* Retrieve Proxy metrics
* @param metricName
*/
public Object getClientMetric(String metricName)
{
try
{
switch(metricName)
{View on GitHub (pinned to 88fd0f6a0e)