Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions src/java/org/apache/cassandra/tools/nodetool/CompactionStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,21 @@ public void execute(NodeProbe probe)
TableBuilder tableBuilder = new TableBuilder();
pendingTasksAndConcurrentCompactorsStats(probe, tableBuilder);
compactionsStats(probe, tableBuilder);
reportCompactionTable(probe.getCompactionManagerProxy().getCompactions(), probe.getCompactionThroughputBytes(), humanReadable, vtableOutput, out, tableBuilder);
Map<String, String> currentCompactionThroughputMetricsMap = probe.getCurrentCompactionThroughputMiBPerSec();
String currentThroughput1MinStr = currentCompactionThroughputMetricsMap.get("1minute");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you "1minute" by default ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was my suggestion in the ticket, to use the most recent speed value, 5/15m stats may warm up too long, so you may get less accurate values at the beginning of compaction.

Double currentCompactionThroughputMiBPerSec = null;
Copy link
Contributor

@smiklosovic smiklosovic Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do long ... = -1 by default and renamed to currentCompactionThroughputBytesPerSec

try
{
if (currentThroughput1MinStr != null && !currentThroughput1MinStr.isEmpty())
{
currentCompactionThroughputMiBPerSec = Double.parseDouble(currentThroughput1MinStr);
Copy link
Contributor

@smiklosovic smiklosovic Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentCompactionThroughputBytesPerSec = Double.valueOf(...).longValue() * 1024 * 1024

}
}
catch (NumberFormatException e)
{
// If parsing fails, currentCompactionThroughputMiBPerSec remains null and we'll fall back to configured throughput
}
reportCompactionTable(probe.getCompactionManagerProxy().getCompactions(), probe.getCompactionThroughputBytes(), currentCompactionThroughputMiBPerSec, humanReadable, vtableOutput, out, tableBuilder);
}

private void pendingTasksAndConcurrentCompactorsStats(NodeProbe probe, TableBuilder tableBuilder)
Expand Down Expand Up @@ -118,10 +132,15 @@ private void compactionsStats(NodeProbe probe, TableBuilder tableBuilder)

public static void reportCompactionTable(List<Map<String,String>> compactions, long compactionThroughputInBytes, boolean humanReadable, PrintStream out, TableBuilder table)
{
reportCompactionTable(compactions, compactionThroughputInBytes, humanReadable, false, out, table);
reportCompactionTable(compactions, compactionThroughputInBytes, null, humanReadable, false, out, table);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-1

}

public static void reportCompactionTable(List<Map<String,String>> compactions, long compactionThroughputInBytes, boolean humanReadable, boolean vtableOutput, PrintStream out, TableBuilder table)
{
reportCompactionTable(compactions, compactionThroughputInBytes, null, humanReadable, vtableOutput, out, table);
}

public static void reportCompactionTable(List<Map<String,String>> compactions, long compactionThroughputInBytes, Double currentCompactionThroughputMiBPerSec, boolean humanReadable, boolean vtableOutput, PrintStream out, TableBuilder table)
Copy link
Contributor

@smiklosovic smiklosovic Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would not it be nice if all number parameters are primitives for being consistent? (Double -> long)

{
if (compactions.isEmpty())
{
Expand Down Expand Up @@ -162,9 +181,22 @@ public static void reportCompactionTable(List<Map<String,String>> compactions, l
}

String remainingTime = "n/a";
if (compactionThroughputInBytes != 0)
long throughputInBytes = 0;

// Use current compaction throughput (1 minute) if available and > 0, otherwise fall back to configured throughput
if (currentCompactionThroughputMiBPerSec != null && currentCompactionThroughputMiBPerSec > 0)
Copy link
Contributor

@smiklosovic smiklosovic Jan 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    if (currentCompactionThroughputBytesPerSec > 0)
        throughputInBytes = currentCompactionThroughputBytesPerSec;

{
// Convert MiB/s to bytes/s (1 MiB = 1024 * 1024 bytes)
throughputInBytes = (long) (currentCompactionThroughputMiBPerSec * 1024 * 1024);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you avoid this casting to long by making currentCompactionThroughputMiBPerSec as long already? Can you also not do this "math" at this place? We can do that upon parsing that value. That would make currentCompactionThroughputMiBPerSec to be called currentCompactionThroughputBytesPerSec.

}
else if (compactionThroughputInBytes != 0)
{
throughputInBytes = compactionThroughputInBytes;
}

if (throughputInBytes > 0)
{
long remainingTimeInSecs = remainingBytes / compactionThroughputInBytes;
long remainingTimeInSecs = remainingBytes / throughputInBytes;
remainingTime = format("%dh%02dm%02ds", remainingTimeInSecs / 3600, (remainingTimeInSecs % 3600) / 60, (remainingTimeInSecs % 60));
}

Expand Down