This is an automated email from the ASF dual-hosted git repository.
smiklosovic pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push:
new c8854af030 Add -H option for human-friendly output in nodetool
compactionhistory
c8854af030 is described below
commit c8854af03064ae894e4d69253723a1f99f001450
Author: Cheng <[email protected]>
AuthorDate: Tue Oct 22 14:27:10 2024 -0700
Add -H option for human-friendly output in nodetool compactionhistory
patch by Cheng Wang; reviewed by Jordan West, Stefan Miklosovic for
CASSANDRA-20015
---
CHANGES.txt | 1 +
.../org/apache/cassandra/io/util/FileUtils.java | 8 ++++++
.../tools/nodetool/CompactionHistory.java | 7 ++++-
.../nodetool/stats/CompactionHistoryHolder.java | 13 +++++----
.../tools/nodetool/stats/TableStatsHolder.java | 33 +++++++++-------------
5 files changed, 37 insertions(+), 25 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index 239c04f4c9..7e5d6fede4 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
5.1
+ * Add -H option for human-friendly output in nodetool compactionhistory
(CASSANDRA-20015)
* Fix type check for referenced duration type for nested types
(CASSANDRA-19890)
* In simulation tests, correctly set the tokens of replacement nodes
(CASSANDRA-19997)
* During TCM upgrade, retain all properties of existing system tables
(CASSANDRA-19992)
diff --git a/src/java/org/apache/cassandra/io/util/FileUtils.java
b/src/java/org/apache/cassandra/io/util/FileUtils.java
index e32b059e68..cf6ea52be1 100644
--- a/src/java/org/apache/cassandra/io/util/FileUtils.java
+++ b/src/java/org/apache/cassandra/io/util/FileUtils.java
@@ -426,6 +426,14 @@ public final class FileUtils
}
}
+ public static String stringifyFileSize(long bytes, boolean humanReadable)
+ {
+ if (humanReadable)
+ return stringifyFileSize(bytes);
+ else
+ return Long.toString(bytes);
+ }
+
public static String stringifyFileSize(double value)
{
double d;
diff --git
a/src/java/org/apache/cassandra/tools/nodetool/CompactionHistory.java
b/src/java/org/apache/cassandra/tools/nodetool/CompactionHistory.java
index d1a506187c..e963d7a1c4 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/CompactionHistory.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/CompactionHistory.java
@@ -34,6 +34,11 @@ public class CompactionHistory extends NodeToolCmd
description = "Output format (json, yaml)")
private String outputFormat = "";
+ @Option(title = "human_readable",
+ name = {"-H", "--human-readable"},
+ description = "Display bytes in human readable form, i.e. KiB, MiB, GiB,
TiB")
+ private boolean humanReadable = false;
+
@Override
public void execute(NodeProbe probe)
{
@@ -41,7 +46,7 @@ public class CompactionHistory extends NodeToolCmd
{
throw new IllegalArgumentException("arguments for -F are json,yaml
only.");
}
- StatsHolder data = new CompactionHistoryHolder(probe);
+ StatsHolder data = new CompactionHistoryHolder(probe, humanReadable);
StatsPrinter printer = CompactionHistoryPrinter.from(outputFormat);
printer.print(data, probe.output().out);
}
diff --git
a/src/java/org/apache/cassandra/tools/nodetool/stats/CompactionHistoryHolder.java
b/src/java/org/apache/cassandra/tools/nodetool/stats/CompactionHistoryHolder.java
index 362bc67c34..189500bc9e 100644
---
a/src/java/org/apache/cassandra/tools/nodetool/stats/CompactionHistoryHolder.java
+++
b/src/java/org/apache/cassandra/tools/nodetool/stats/CompactionHistoryHolder.java
@@ -29,16 +29,19 @@ import java.util.Map;
import java.util.Set;
import javax.management.openmbean.TabularData;
+import org.apache.cassandra.io.util.FileUtils;
import org.apache.cassandra.tools.NodeProbe;
public class CompactionHistoryHolder implements StatsHolder
{
public final NodeProbe probe;
public List<String> indexNames;
+ private final boolean humanReadable;
- public CompactionHistoryHolder(NodeProbe probe)
+ public CompactionHistoryHolder(NodeProbe probe, boolean humanReadable)
{
this.probe = probe;
+ this.humanReadable = humanReadable;
}
/**
@@ -73,7 +76,7 @@ public class CompactionHistoryHolder implements StatsHolder
return Long.signum(chr.compactedAt - this.compactedAt);
}
- private HashMap<String, Object> getAllAsMap()
+ private HashMap<String, Object> getAllAsMap(boolean humanReadable)
{
HashMap<String, Object> compaction = new HashMap<>();
compaction.put("id", this.id);
@@ -82,8 +85,8 @@ public class CompactionHistoryHolder implements StatsHolder
Instant instant = Instant.ofEpochMilli(this.compactedAt);
LocalDateTime ldt = LocalDateTime.ofInstant(instant,
ZoneId.systemDefault());
compaction.put("compacted_at", ldt.toString());
- compaction.put("bytes_in", this.bytesIn);
- compaction.put("bytes_out", this.bytesOut);
+ compaction.put("bytes_in",
FileUtils.stringifyFileSize(this.bytesIn, humanReadable));
+ compaction.put("bytes_out",
FileUtils.stringifyFileSize(this.bytesOut, humanReadable));
compaction.put("rows_merged", this.rowMerged);
compaction.put("compaction_properties", this.compactionProperties);
return compaction;
@@ -122,7 +125,7 @@ public class CompactionHistoryHolder implements StatsHolder
Collections.sort(chrList);
for (CompactionHistoryHolder.CompactionHistoryRow chr : chrList)
{
- compactions.add(chr.getAllAsMap());
+ compactions.add(chr.getAllAsMap(humanReadable));
}
result.put("CompactionHistory", compactions);
return result;
diff --git
a/src/java/org/apache/cassandra/tools/nodetool/stats/TableStatsHolder.java
b/src/java/org/apache/cassandra/tools/nodetool/stats/TableStatsHolder.java
index d32d88bffa..338151a0d8 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/stats/TableStatsHolder.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/stats/TableStatsHolder.java
@@ -82,8 +82,8 @@ public class TableStatsHolder implements StatsHolder
mpKeyspace.put("write_count", keyspace.writeCount);
mpKeyspace.put("write_latency_ms", keyspace.writeLatency());
mpKeyspace.put("pending_flushes", keyspace.pendingFlushes);
- mpKeyspace.put("space_used_live", format(keyspace.spaceUsedLive,
humanReadable));
- mpKeyspace.put("space_used_total", format(keyspace.spaceUsedTotal,
humanReadable));
+ mpKeyspace.put("space_used_live",
FileUtils.stringifyFileSize(keyspace.spaceUsedLive, humanReadable));
+ mpKeyspace.put("space_used_total",
FileUtils.stringifyFileSize(keyspace.spaceUsedTotal, humanReadable));
// store each table's metrics to map
List<StatsTable> tables = keyspace.tables;
@@ -260,7 +260,7 @@ public class TableStatsHolder implements StatsHolder
for (int level = 0; level < leveledSSTablesBytes.length;
level++)
{
long size = leveledSSTablesBytes[level];
- statsTable.sstableBytesInEachLevel.add(format(size,
humanReadable));
+
statsTable.sstableBytesInEachLevel.add(FileUtils.stringifyFileSize(size,
humanReadable));
}
}
@@ -300,16 +300,16 @@ public class TableStatsHolder implements StatsHolder
throw e;
}
- statsTable.spaceUsedLive = format((Long)
probe.getColumnFamilyMetric(keyspaceName, tableName, "LiveDiskSpaceUsed"),
humanReadable);
- statsTable.spaceUsedTotal = format((Long)
probe.getColumnFamilyMetric(keyspaceName, tableName, "TotalDiskSpaceUsed"),
humanReadable);
- statsTable.spaceUsedBySnapshotsTotal = format((Long)
probe.getColumnFamilyMetric(keyspaceName, tableName, "SnapshotsSize"),
humanReadable);
+ statsTable.spaceUsedLive = FileUtils.stringifyFileSize((Long)
probe.getColumnFamilyMetric(keyspaceName, tableName, "LiveDiskSpaceUsed"),
humanReadable);
+ statsTable.spaceUsedTotal = FileUtils.stringifyFileSize((Long)
probe.getColumnFamilyMetric(keyspaceName, tableName, "TotalDiskSpaceUsed"),
humanReadable);
+ statsTable.spaceUsedBySnapshotsTotal =
FileUtils.stringifyFileSize((Long) probe.getColumnFamilyMetric(keyspaceName,
tableName, "SnapshotsSize"), humanReadable);
maybeAddTWCSWindowWithMaxDuration(statsTable, probe,
keyspaceName, tableName);
if (offHeapSize != null)
{
statsTable.offHeapUsed = true;
- statsTable.offHeapMemoryUsedTotal = format(offHeapSize,
humanReadable);
+ statsTable.offHeapMemoryUsedTotal =
FileUtils.stringifyFileSize(offHeapSize, humanReadable);
}
if (percentRepaired != null)
@@ -330,11 +330,11 @@ public class TableStatsHolder implements StatsHolder
statsTable.numberOfPartitionsEstimate =
estimatedPartitionCount;
statsTable.memtableCellCount =
probe.getColumnFamilyMetric(keyspaceName, tableName, "MemtableColumnsCount");
- statsTable.memtableDataSize = format((Long)
probe.getColumnFamilyMetric(keyspaceName, tableName, "MemtableLiveDataSize"),
humanReadable);
+ statsTable.memtableDataSize =
FileUtils.stringifyFileSize((Long) probe.getColumnFamilyMetric(keyspaceName,
tableName, "MemtableLiveDataSize"), humanReadable);
if (memtableOffHeapSize != null)
{
statsTable.memtableOffHeapUsed = true;
- statsTable.memtableOffHeapMemoryUsed =
format(memtableOffHeapSize, humanReadable);
+ statsTable.memtableOffHeapMemoryUsed =
FileUtils.stringifyFileSize(memtableOffHeapSize, humanReadable);
}
statsTable.memtableSwitchCount =
probe.getColumnFamilyMetric(keyspaceName, tableName, "MemtableSwitchCount");
statsTable.speculativeRetries =
probe.getColumnFamilyMetric(keyspaceName, tableName, "SpeculativeRetries");
@@ -356,23 +356,23 @@ public class TableStatsHolder implements StatsHolder
statsTable.bloomFilterFalsePositives =
probe.getColumnFamilyMetric(keyspaceName, tableName,
"BloomFilterFalsePositives");
statsTable.bloomFilterFalseRatio = bloomFilterFalseRatio !=
null ? bloomFilterFalseRatio : Double.NaN;
- statsTable.bloomFilterSpaceUsed = format((Long)
probe.getColumnFamilyMetric(keyspaceName, tableName,
"BloomFilterDiskSpaceUsed"), humanReadable);
+ statsTable.bloomFilterSpaceUsed =
FileUtils.stringifyFileSize((Long) probe.getColumnFamilyMetric(keyspaceName,
tableName, "BloomFilterDiskSpaceUsed"), humanReadable);
if (bloomFilterOffHeapSize != null)
{
statsTable.bloomFilterOffHeapUsed = true;
- statsTable.bloomFilterOffHeapMemoryUsed =
format(bloomFilterOffHeapSize, humanReadable);
+ statsTable.bloomFilterOffHeapMemoryUsed =
FileUtils.stringifyFileSize(bloomFilterOffHeapSize, humanReadable);
}
if (indexSummaryOffHeapSize != null)
{
statsTable.indexSummaryOffHeapUsed = true;
- statsTable.indexSummaryOffHeapMemoryUsed =
format(indexSummaryOffHeapSize, humanReadable);
+ statsTable.indexSummaryOffHeapMemoryUsed =
FileUtils.stringifyFileSize(indexSummaryOffHeapSize, humanReadable);
}
if (compressionMetadataOffHeapSize != null)
{
statsTable.compressionMetadataOffHeapUsed = true;
- statsTable.compressionMetadataOffHeapMemoryUsed =
format(compressionMetadataOffHeapSize, humanReadable);
+ statsTable.compressionMetadataOffHeapMemoryUsed =
FileUtils.stringifyFileSize(compressionMetadataOffHeapSize, humanReadable);
}
statsTable.compactedPartitionMinimumBytes = (Long)
probe.getColumnFamilyMetric(keyspaceName, tableName, "MinPartitionSize");
statsTable.compactedPartitionMaximumBytes = (Long)
probe.getColumnFamilyMetric(keyspaceName, tableName, "MaxPartitionSize");
@@ -420,16 +420,11 @@ public class TableStatsHolder implements StatsHolder
statsTable.twcs = String.format("%s %s, max duration: %s", size, unit,
maxDuration);
}
- private String format(long bytes, boolean humanReadable)
- {
- return humanReadable ? FileUtils.stringifyFileSize(bytes) :
Long.toString(bytes);
- }
-
private Map<String, String> format(Map<String, Long> map, boolean
humanReadable)
{
LinkedHashMap<String, String> retMap = new LinkedHashMap<>();
for (Map.Entry<String, Long> entry : map.entrySet())
- retMap.put(entry.getKey(), format(entry.getValue(),
humanReadable));
+ retMap.put(entry.getKey(),
FileUtils.stringifyFileSize(entry.getValue(), humanReadable));
return retMap;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]