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 9db908917a Standardize nodetool tablestats formatting of data units
9db908917a is described below

commit 9db908917afeec7fc2c7ce1a4bd3303f235d6578
Author: Leo Toff <[email protected]>
AuthorDate: Fri Jan 5 12:31:55 2024 +0100

    Standardize nodetool tablestats formatting of data units
    
    patch by Leo Toff; reviewed by Stefan Miklosovic, Brandon Williams for 
CASSANDRA-19104
---
 CHANGES.txt                                        |   1 +
 .../tools/nodetool/stats/TableStatsPrinter.java    |  26 +-
 .../apache/cassandra/io/util/FileUtilsTest.java    |  29 ++
 .../nodetool/stats/TableStatsPrinterTest.java      | 345 +++++++++++++++++++--
 4 files changed, 365 insertions(+), 36 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index a71435ed58..152f63056f 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 5.1
+ * Standardize nodetool tablestats formatting of data units (CASSANDRA-19104)
  * Make nodetool tablestats use number of significant digits for time and 
average values consistently (CASSANDRA-19015)
  * Upgrade jackson to 2.15.3 and snakeyaml to 2.1 (CASSANDRA-18875)
  * Transactional Cluster Metadata [CEP-21] (CASSANDRA-18330)
diff --git 
a/src/java/org/apache/cassandra/tools/nodetool/stats/TableStatsPrinter.java 
b/src/java/org/apache/cassandra/tools/nodetool/stats/TableStatsPrinter.java
index e37fee3938..81dab5a6f8 100644
--- a/src/java/org/apache/cassandra/tools/nodetool/stats/TableStatsPrinter.java
+++ b/src/java/org/apache/cassandra/tools/nodetool/stats/TableStatsPrinter.java
@@ -22,6 +22,7 @@ import java.io.PrintStream;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.cassandra.io.util.FileUtils;
 import org.apache.cassandra.utils.FBUtilities;
 
 public class TableStatsPrinter<T extends StatsHolder>
@@ -74,18 +75,18 @@ public class TableStatsPrinter<T extends StatsHolder>
 
                 for (StatsTable table : tables)
                 {
-                    printStatsTable(table, table.tableName, "\t\t", out);
+                    printStatsTable(table, table.tableName, "\t\t", 
data.humanReadable, out);
                 }
                 out.println("----------------");
             }
         }
 
-        protected void printStatsTable(StatsTable table, String 
tableDisplayName, String indent, PrintStream out)
+        protected void printStatsTable(StatsTable table, String 
tableDisplayName, String indent, boolean humanReadable, PrintStream out)
         {
             out.println(indent + "Table" + (table.isIndex ? " (index): " : ": 
") + tableDisplayName);
             out.println(indent + "SSTable count: " + table.sstableCount);
             out.println(indent + "Old SSTable count: " + 
table.oldSSTableCount);
-            out.println(indent + "Max SSTable size: " + 
FBUtilities.prettyPrintMemory(table.maxSSTableSize));
+            out.println(indent + "Max SSTable size: " + 
formatDataSize(table.maxSSTableSize, humanReadable));
             if (table.twcs != null)
                 out.println(indent + "SSTables Time Window: " + table.twcs);
             if (table.isLeveledSstable)
@@ -121,9 +122,9 @@ public class TableStatsPrinter<T extends StatsHolder>
             out.println(indent + "Pending flushes: " + table.pendingFlushes);
             out.println(indent + "Percent repaired: " + table.percentRepaired);
 
-            out.println(indent +"Bytes repaired: " + 
FBUtilities.prettyPrintMemory(table.bytesRepaired));
-            out.println(indent +"Bytes unrepaired: " + 
FBUtilities.prettyPrintMemory(table.bytesUnrepaired));
-            out.println(indent +"Bytes pending repair: " + 
FBUtilities.prettyPrintMemory(table.bytesPendingRepair));
+            out.println(indent + "Bytes repaired: " + 
formatDataSize(table.bytesRepaired, humanReadable));
+            out.println(indent + "Bytes unrepaired: " + 
formatDataSize(table.bytesUnrepaired, humanReadable));
+            out.println(indent + "Bytes pending repair: " + 
formatDataSize(table.bytesPendingRepair, humanReadable));
 
             out.println(indent + "Bloom filter false positives: " + 
table.bloomFilterFalsePositives);
             out.println(indent + "Bloom filter false ratio: " + 
FBUtilities.prettyPrintRatio(table.bloomFilterFalseRatio));
@@ -136,9 +137,9 @@ public class TableStatsPrinter<T extends StatsHolder>
             if (table.compressionMetadataOffHeapUsed)
                 out.println(indent + "Compression metadata off heap memory 
used: " + table.compressionMetadataOffHeapMemoryUsed);
 
-            out.println(indent + "Compacted partition minimum bytes: " + 
table.compactedPartitionMinimumBytes);
-            out.println(indent + "Compacted partition maximum bytes: " + 
table.compactedPartitionMaximumBytes);
-            out.println(indent + "Compacted partition mean bytes: " + 
table.compactedPartitionMeanBytes);
+            out.println(indent + "Compacted partition minimum bytes: " + 
formatDataSize(table.compactedPartitionMinimumBytes, humanReadable));
+            out.println(indent + "Compacted partition maximum bytes: " + 
formatDataSize(table.compactedPartitionMaximumBytes, humanReadable));
+            out.println(indent + "Compacted partition mean bytes: " + 
formatDataSize(table.compactedPartitionMeanBytes, humanReadable));
             out.println(indent + "Average live cells per slice (last five 
minutes): " +
                         
FBUtilities.prettyPrintAverage(table.averageLiveCellsPerSliceLastFiveMinutes));
             out.println(indent + "Maximum live cells per slice (last five 
minutes): " + table.maximumLiveCellsPerSliceLastFiveMinutes);
@@ -167,6 +168,11 @@ public class TableStatsPrinter<T extends StatsHolder>
             }
             out.println("");
         }
+
+        private String formatDataSize(long bytes, boolean humanReadable)
+        {
+            return humanReadable ? FileUtils.stringifyFileSize(bytes) : 
Long.toString(bytes);
+        }
     }
 
     /**
@@ -192,7 +198,7 @@ public class TableStatsPrinter<T extends StatsHolder>
             out.println("----------------");
             for (StatsTable table : tables)
             {
-                printStatsTable(table, table.keyspaceName + "." + 
table.tableName, "\t", out);
+                printStatsTable(table, table.keyspaceName + "." + 
table.tableName, "\t", data.humanReadable, out);
             }
             out.println("----------------");
         }
diff --git a/test/unit/org/apache/cassandra/io/util/FileUtilsTest.java 
b/test/unit/org/apache/cassandra/io/util/FileUtilsTest.java
index c8359e07a3..9d97bcf50e 100644
--- a/test/unit/org/apache/cassandra/io/util/FileUtilsTest.java
+++ b/test/unit/org/apache/cassandra/io/util/FileUtilsTest.java
@@ -75,6 +75,35 @@ public class FileUtilsTest
             6621259022467L, FileUtils.parseFileSize("6.022 TiB"));
     }
 
+    @Test
+    public void testStringifyFileSize() throws Exception
+    {
+        // test straightforward conversions for each unit
+        assertEquals("FileUtils.stringifyFileSize() failed to stringify a 
whole number of bytes",
+                     "256 bytes", FileUtils.stringifyFileSize(256L));
+        assertEquals("FileUtils.stringifyFileSize() failed to stringify a 
whole number of kibibytes",
+                     "2 KiB", FileUtils.stringifyFileSize(2048L));
+        assertEquals("FileUtils.stringifyFileSize() failed to stringify a 
whole number of mebibytes",
+                     "4 MiB", FileUtils.stringifyFileSize(4194304L));
+        assertEquals("FileUtils.stringifyFileSize() failed to stringify a 
whole number of gibibytes",
+                     "3 GiB", FileUtils.stringifyFileSize(3221225472L));
+        assertEquals("FileUtils.stringifyFileSize() failed to stringify a 
whole number of tebibytes",
+                     "5 TiB", FileUtils.stringifyFileSize(5497558138880L));
+        // test conversions of fractional units
+        assertEquals("FileUtils.stringifyFileSize() failed to stringify a 
rational number of kibibytes",
+                     "1.5 KiB", FileUtils.stringifyFileSize(1536L));
+        assertEquals("FileUtils.stringifyFileSize() failed to stringify a 
rational number of kibibytes",
+                     "4.33 KiB", FileUtils.stringifyFileSize(4434L));
+        assertEquals("FileUtils.stringifyFileSize() failed to stringify a 
rational number of mebibytes",
+                     "2.25 MiB", FileUtils.stringifyFileSize(2359296L));
+        assertEquals("FileUtils.stringifyFileSize() failed to stringify a 
rational number of mebibytes",
+                     "3.14 MiB", FileUtils.stringifyFileSize(3292529L));
+        assertEquals("FileUtils.stringifyFileSize() failed to stringify a 
rational number of gibibytes",
+                     "1.21 GiB", FileUtils.stringifyFileSize(1299227607L));
+        assertEquals("FileUtils.stringifyFileSize() failed to stringify a 
rational number of tebibytes",
+                     "6.02 TiB", FileUtils.stringifyFileSize(6621259022467L));
+    }
+
     @Test
     public void testTruncate() throws IOException
     {
diff --git 
a/test/unit/org/apache/cassandra/tools/nodetool/stats/TableStatsPrinterTest.java
 
b/test/unit/org/apache/cassandra/tools/nodetool/stats/TableStatsPrinterTest.java
index ebffa1d45d..40041b63e2 100644
--- 
a/test/unit/org/apache/cassandra/tools/nodetool/stats/TableStatsPrinterTest.java
+++ 
b/test/unit/org/apache/cassandra/tools/nodetool/stats/TableStatsPrinterTest.java
@@ -39,7 +39,7 @@ public class TableStatsPrinterTest extends TableStatsTestBase
         "\tTable: %s\n" +
         "\tSSTable count: 60000\n" +
         "\tOld SSTable count: 0\n" +
-        "\tMax SSTable size: 0B\n" +
+        "\tMax SSTable size: 0\n" +
         "\tSpace used (live): 0\n" +
         "\tSpace used (total): 9001\n" +
         "\tSpace used by snapshots (total): 1111\n" +
@@ -56,9 +56,9 @@ public class TableStatsPrinterTest extends TableStatsTestBase
         "\tLocal read/write ratio: 0.000\n" +
         "\tPending flushes: 11111\n" +
         "\tPercent repaired: 100.0\n" +
-        "\tBytes repaired: 0B\n" +
-        "\tBytes unrepaired: 0B\n" +
-        "\tBytes pending repair: 0B\n" +
+        "\tBytes repaired: 0\n" +
+        "\tBytes unrepaired: 0\n" +
+        "\tBytes pending repair: 0\n" +
         "\tBloom filter false positives: 30\n" +
         "\tBloom filter false ratio: 0.400\n" +
         "\tBloom filter space used: 789\n" +
@@ -72,11 +72,48 @@ public class TableStatsPrinterTest extends 
TableStatsTestBase
         "\tDroppable tombstone ratio: 0.000\n" +
         "\n";
 
+    public static final String expectedDefaultHumanReadableTable1Output =
+        "\tTable: %s\n" +
+        "\tSSTable count: 60000\n" +
+        "\tOld SSTable count: 0\n" +
+        "\tMax SSTable size: 0 bytes\n" +
+        "\tSpace used (live): 0\n" +
+        "\tSpace used (total): 9001\n" +
+        "\tSpace used by snapshots (total): 1111\n" +
+        "\tSSTable Compression Ratio: 0.680\n" +
+        "\tNumber of partitions (estimate): 111111\n" +
+        "\tMemtable cell count: 111\n" +
+        "\tMemtable data size: 0\n" +
+        "\tMemtable switch count: 1\n" +
+        "\tSpeculative retries: 0\n" +
+        "\tLocal read count: 0\n" +
+        "\tLocal read latency: 2.000 ms\n" +
+        "\tLocal write count: 5\n" +
+        "\tLocal write latency: 0.050 ms\n" +
+        "\tLocal read/write ratio: 0.000\n" +
+        "\tPending flushes: 11111\n" +
+        "\tPercent repaired: 100.0\n" +
+        "\tBytes repaired: 0 bytes\n" +
+        "\tBytes unrepaired: 0 bytes\n" +
+        "\tBytes pending repair: 0 bytes\n" +
+        "\tBloom filter false positives: 30\n" +
+        "\tBloom filter false ratio: 0.400\n" +
+        "\tBloom filter space used: 789\n" +
+        "\tCompacted partition minimum bytes: 2 bytes\n" +
+        "\tCompacted partition maximum bytes: 60 bytes\n" +
+        "\tCompacted partition mean bytes: 6 bytes\n" +
+        "\tAverage live cells per slice (last five minutes): 6.00\n" +
+        "\tMaximum live cells per slice (last five minutes): 6\n" +
+        "\tAverage tombstones per slice (last five minutes): 5.00\n" +
+        "\tMaximum tombstones per slice (last five minutes): 1\n" +
+        "\tDroppable tombstone ratio: 0.000\n" +
+        "\n";
+
     public static final String expectedDefaultTable2Output =
         "\tTable: %s\n" +
         "\tSSTable count: 3000\n" +
         "\tOld SSTable count: 0\n" +
-        "\tMax SSTable size: 0B\n" +
+        "\tMax SSTable size: 0\n" +
         "\tSpace used (live): 22\n" +
         "\tSpace used (total): 1024\n" +
         "\tSpace used by snapshots (total): 222\n" +
@@ -95,9 +132,9 @@ public class TableStatsPrinterTest extends TableStatsTestBase
         "\tLocal read/write ratio: 0.000\n" +
         "\tPending flushes: 222222\n" +
         "\tPercent repaired: 99.9\n" +
-        "\tBytes repaired: 0B\n" +
-        "\tBytes unrepaired: 0B\n" +
-        "\tBytes pending repair: 0B\n" +
+        "\tBytes repaired: 0\n" +
+        "\tBytes unrepaired: 0\n" +
+        "\tBytes pending repair: 0\n" +
         "\tBloom filter false positives: 600\n" +
         "\tBloom filter false ratio: 0.010\n" +
         "\tBloom filter space used: 161718\n" +
@@ -114,11 +151,53 @@ public class TableStatsPrinterTest extends 
TableStatsTestBase
         "\tDroppable tombstone ratio: 0.222\n" +
         "\n";
 
+    public static final String expectedDefaultHumanReadableTable2Output =
+        "\tTable: %s\n" +
+        "\tSSTable count: 3000\n" +
+        "\tOld SSTable count: 0\n" +
+        "\tMax SSTable size: 0 bytes\n" +
+        "\tSpace used (live): 22\n" +
+        "\tSpace used (total): 1024\n" +
+        "\tSpace used by snapshots (total): 222\n" +
+        "\tOff heap memory used (total): 314159367\n" +
+        "\tSSTable Compression Ratio: 0.680\n" +
+        "\tNumber of partitions (estimate): 22222\n" +
+        "\tMemtable cell count: 22\n" +
+        "\tMemtable data size: 900\n" +
+        "\tMemtable off heap memory used: 314159265\n" +
+        "\tMemtable switch count: 22222\n" +
+        "\tSpeculative retries: 0\n" +
+        "\tLocal read count: 1\n" +
+        "\tLocal read latency: 3.000 ms\n" +
+        "\tLocal write count: 4\n" +
+        "\tLocal write latency: 0.000 ms\n" +
+        "\tLocal read/write ratio: 0.000\n" +
+        "\tPending flushes: 222222\n" +
+        "\tPercent repaired: 99.9\n" +
+        "\tBytes repaired: 0 bytes\n" +
+        "\tBytes unrepaired: 0 bytes\n" +
+        "\tBytes pending repair: 0 bytes\n" +
+        "\tBloom filter false positives: 600\n" +
+        "\tBloom filter false ratio: 0.010\n" +
+        "\tBloom filter space used: 161718\n" +
+        "\tBloom filter off heap memory used: 98\n" +
+        "\tIndex summary off heap memory used: 1\n" +
+        "\tCompression metadata off heap memory used: 3\n" +
+        "\tCompacted partition minimum bytes: 4 bytes\n" +
+        "\tCompacted partition maximum bytes: 30 bytes\n" +
+        "\tCompacted partition mean bytes: 4 bytes\n" +
+        "\tAverage live cells per slice (last five minutes): 4.01\n" +
+        "\tMaximum live cells per slice (last five minutes): 5\n" +
+        "\tAverage tombstones per slice (last five minutes): 4.00\n" +
+        "\tMaximum tombstones per slice (last five minutes): 2\n" +
+        "\tDroppable tombstone ratio: 0.222\n" +
+        "\n";
+
     public static final String expectedDefaultTable3Output =
         "\tTable: %s\n" +
         "\tSSTable count: 50000\n" +
         "\tOld SSTable count: 0\n" +
-        "\tMax SSTable size: 0B\n" +
+        "\tMax SSTable size: 0\n" +
         "\tSpace used (live): 0\n" +
         "\tSpace used (total): 512\n" +
         "\tSpace used by snapshots (total): 0\n" +
@@ -135,9 +214,9 @@ public class TableStatsPrinterTest extends 
TableStatsTestBase
         "\tLocal read/write ratio: 0.000\n" +
         "\tPending flushes: 333\n" +
         "\tPercent repaired: 99.8\n" +
-        "\tBytes repaired: 0B\n" +
-        "\tBytes unrepaired: 0B\n" +
-        "\tBytes pending repair: 0B\n" +
+        "\tBytes repaired: 0\n" +
+        "\tBytes unrepaired: 0\n" +
+        "\tBytes pending repair: 0\n" +
         "\tBloom filter false positives: 20\n" +
         "\tBloom filter false ratio: 0.500\n" +
         "\tBloom filter space used: 456\n" +
@@ -151,11 +230,48 @@ public class TableStatsPrinterTest extends 
TableStatsTestBase
         "\tDroppable tombstone ratio: 0.333\n" +
         "\n";
 
+    public static final String expectedDefaultHumanReadableTable3Output =
+        "\tTable: %s\n" +
+        "\tSSTable count: 50000\n" +
+        "\tOld SSTable count: 0\n" +
+        "\tMax SSTable size: 0 bytes\n" +
+        "\tSpace used (live): 0\n" +
+        "\tSpace used (total): 512\n" +
+        "\tSpace used by snapshots (total): 0\n" +
+        "\tSSTable Compression Ratio: 0.320\n" +
+        "\tNumber of partitions (estimate): 3333\n" +
+        "\tMemtable cell count: 333333\n" +
+        "\tMemtable data size: 1999\n" +
+        "\tMemtable switch count: 3333\n" +
+        "\tSpeculative retries: 0\n" +
+        "\tLocal read count: 2\n" +
+        "\tLocal read latency: 4.000 ms\n" +
+        "\tLocal write count: 3\n" +
+        "\tLocal write latency: NaN ms\n" +
+        "\tLocal read/write ratio: 0.000\n" +
+        "\tPending flushes: 333\n" +
+        "\tPercent repaired: 99.8\n" +
+        "\tBytes repaired: 0 bytes\n" +
+        "\tBytes unrepaired: 0 bytes\n" +
+        "\tBytes pending repair: 0 bytes\n" +
+        "\tBloom filter false positives: 20\n" +
+        "\tBloom filter false ratio: 0.500\n" +
+        "\tBloom filter space used: 456\n" +
+        "\tCompacted partition minimum bytes: 2 bytes\n" +
+        "\tCompacted partition maximum bytes: 50 bytes\n" +
+        "\tCompacted partition mean bytes: 5 bytes\n" +
+        "\tAverage live cells per slice (last five minutes): 0.00\n" +
+        "\tMaximum live cells per slice (last five minutes): 5\n" +
+        "\tAverage tombstones per slice (last five minutes): NaN\n" +
+        "\tMaximum tombstones per slice (last five minutes): 3\n" +
+        "\tDroppable tombstone ratio: 0.333\n" +
+        "\n";
+
     public static final String expectedDefaultTable4Output =
         "\tTable: %s\n" +
         "\tSSTable count: 2000\n" +
         "\tOld SSTable count: 0\n" +
-        "\tMax SSTable size: 0B\n" +
+        "\tMax SSTable size: 0\n" +
         "\tSpace used (live): 4444\n" +
         "\tSpace used (total): 256\n" +
         "\tSpace used by snapshots (total): 44\n" +
@@ -174,9 +290,9 @@ public class TableStatsPrinterTest extends 
TableStatsTestBase
         "\tLocal read/write ratio: 0.000\n" +
         "\tPending flushes: 4444\n" +
         "\tPercent repaired: 50.0\n" +
-        "\tBytes repaired: 0B\n" +
-        "\tBytes unrepaired: 0B\n" +
-        "\tBytes pending repair: 0B\n" +
+        "\tBytes repaired: 0\n" +
+        "\tBytes unrepaired: 0\n" +
+        "\tBytes pending repair: 0\n" +
         "\tBloom filter false positives: 500\n" +
         "\tBloom filter false ratio: 0.020\n" +
         "\tBloom filter space used: 131415\n" +
@@ -193,11 +309,53 @@ public class TableStatsPrinterTest extends 
TableStatsTestBase
         "\tDroppable tombstone ratio: 0.444\n" +
         "\n";
 
+    public static final String expectedDefaultHumanReadableTable4Output =
+        "\tTable: %s\n" +
+        "\tSSTable count: 2000\n" +
+        "\tOld SSTable count: 0\n" +
+        "\tMax SSTable size: 0 bytes\n" +
+        "\tSpace used (live): 4444\n" +
+        "\tSpace used (total): 256\n" +
+        "\tSpace used by snapshots (total): 44\n" +
+        "\tOff heap memory used (total): 441213818\n" +
+        "\tSSTable Compression Ratio: 0.950\n" +
+        "\tNumber of partitions (estimate): 444\n" +
+        "\tMemtable cell count: 4\n" +
+        "\tMemtable data size: 3000\n" +
+        "\tMemtable off heap memory used: 141421356\n" +
+        "\tMemtable switch count: 444444\n" +
+        "\tSpeculative retries: 0\n" +
+        "\tLocal read count: 3\n" +
+        "\tLocal read latency: NaN ms\n" +
+        "\tLocal write count: 2\n" +
+        "\tLocal write latency: 2.000 ms\n" +
+        "\tLocal read/write ratio: 0.000\n" +
+        "\tPending flushes: 4444\n" +
+        "\tPercent repaired: 50.0\n" +
+        "\tBytes repaired: 0 bytes\n" +
+        "\tBytes unrepaired: 0 bytes\n" +
+        "\tBytes pending repair: 0 bytes\n" +
+        "\tBloom filter false positives: 500\n" +
+        "\tBloom filter false ratio: 0.020\n" +
+        "\tBloom filter space used: 131415\n" +
+        "\tBloom filter off heap memory used: 299792458\n" +
+        "\tIndex summary off heap memory used: 2\n" +
+        "\tCompression metadata off heap memory used: 2\n" +
+        "\tCompacted partition minimum bytes: 5 bytes\n" +
+        "\tCompacted partition maximum bytes: 20 bytes\n" +
+        "\tCompacted partition mean bytes: 4 bytes\n" +
+        "\tAverage live cells per slice (last five minutes): NaN\n" +
+        "\tMaximum live cells per slice (last five minutes): 3\n" +
+        "\tAverage tombstones per slice (last five minutes): 0.00\n" +
+        "\tMaximum tombstones per slice (last five minutes): 3\n" +
+        "\tDroppable tombstone ratio: 0.444\n" +
+        "\n";
+
     public static final String expectedDefaultTable5Output =
         "\tTable: %s\n" +
         "\tSSTable count: 40000\n" +
         "\tOld SSTable count: 0\n" +
-        "\tMax SSTable size: 0B\n" +
+        "\tMax SSTable size: 0\n" +
         "\tSpace used (live): 55555\n" +
         "\tSpace used (total): 64\n" +
         "\tSpace used by snapshots (total): 55555\n" +
@@ -214,9 +372,9 @@ public class TableStatsPrinterTest extends 
TableStatsTestBase
         "\tLocal read/write ratio: 0.000\n" +
         "\tPending flushes: 5\n" +
         "\tPercent repaired: 93.0\n" +
-        "\tBytes repaired: 0B\n" +
-        "\tBytes unrepaired: 0B\n" +
-        "\tBytes pending repair: 0B\n" +
+        "\tBytes repaired: 0\n" +
+        "\tBytes unrepaired: 0\n" +
+        "\tBytes pending repair: 0\n" +
         "\tBloom filter false positives: 10\n" +
         "\tBloom filter false ratio: 0.600\n" +
         "\tBloom filter space used: 123\n" +
@@ -230,11 +388,48 @@ public class TableStatsPrinterTest extends 
TableStatsTestBase
         "\tDroppable tombstone ratio: 0.556\n" +
         "\n";
 
+    public static final String expectedDefaultHumanReadableTable5Output =
+        "\tTable: %s\n" +
+        "\tSSTable count: 40000\n" +
+        "\tOld SSTable count: 0\n" +
+        "\tMax SSTable size: 0 bytes\n" +
+        "\tSpace used (live): 55555\n" +
+        "\tSpace used (total): 64\n" +
+        "\tSpace used by snapshots (total): 55555\n" +
+        "\tSSTable Compression Ratio: 0.990\n" +
+        "\tNumber of partitions (estimate): 55\n" +
+        "\tMemtable cell count: 55555\n" +
+        "\tMemtable data size: 20000\n" +
+        "\tMemtable switch count: 5\n" +
+        "\tSpeculative retries: 0\n" +
+        "\tLocal read count: 4\n" +
+        "\tLocal read latency: 0.000 ms\n" +
+        "\tLocal write count: 1\n" +
+        "\tLocal write latency: 1.000 ms\n" +
+        "\tLocal read/write ratio: 0.000\n" +
+        "\tPending flushes: 5\n" +
+        "\tPercent repaired: 93.0\n" +
+        "\tBytes repaired: 0 bytes\n" +
+        "\tBytes unrepaired: 0 bytes\n" +
+        "\tBytes pending repair: 0 bytes\n" +
+        "\tBloom filter false positives: 10\n" +
+        "\tBloom filter false ratio: 0.600\n" +
+        "\tBloom filter space used: 123\n" +
+        "\tCompacted partition minimum bytes: 3 bytes\n" +
+        "\tCompacted partition maximum bytes: 40 bytes\n" +
+        "\tCompacted partition mean bytes: 4 bytes\n" +
+        "\tAverage live cells per slice (last five minutes): 4.00\n" +
+        "\tMaximum live cells per slice (last five minutes): 3\n" +
+        "\tAverage tombstones per slice (last five minutes): 4.01\n" +
+        "\tMaximum tombstones per slice (last five minutes): 5\n" +
+        "\tDroppable tombstone ratio: 0.556\n" +
+        "\n";
+
     public static final String expectedDefaultTable6Output =
         "\tTable: %s\n" +
         "\tSSTable count: 1000\n" +
         "\tOld SSTable count: 0\n" +
-        "\tMax SSTable size: 0B\n" +
+        "\tMax SSTable size: 0\n" +
         "\tSpace used (live): 666666\n" +
         "\tSpace used (total): 0\n" +
         "\tSpace used by snapshots (total): 0\n" +
@@ -253,9 +448,9 @@ public class TableStatsPrinterTest extends 
TableStatsTestBase
         "\tLocal read/write ratio: 0.000\n" +
         "\tPending flushes: 66\n" +
         "\tPercent repaired: 0.0\n" +
-        "\tBytes repaired: 0B\n" +
-        "\tBytes unrepaired: 0B\n" +
-        "\tBytes pending repair: 0B\n" +
+        "\tBytes repaired: 0\n" +
+        "\tBytes unrepaired: 0\n" +
+        "\tBytes pending repair: 0\n" +
         "\tBloom filter false positives: 400\n" +
         "\tBloom filter false ratio: 0.030\n" +
         "\tBloom filter space used: 101112\n" +
@@ -272,6 +467,48 @@ public class TableStatsPrinterTest extends 
TableStatsTestBase
         "\tDroppable tombstone ratio: 0.667\n" +
         "\n";
 
+    public static final String expectedDefaultHumanReadableTable6Output =
+        "\tTable: %s\n" +
+        "\tSSTable count: 1000\n" +
+        "\tOld SSTable count: 0\n" +
+        "\tMax SSTable size: 0 bytes\n" +
+        "\tSpace used (live): 666666\n" +
+        "\tSpace used (total): 0\n" +
+        "\tSpace used by snapshots (total): 0\n" +
+        "\tOff heap memory used (total): 162470810\n" +
+        "\tSSTable Compression Ratio: 0.680\n" +
+        "\tNumber of partitions (estimate): 6\n" +
+        "\tMemtable cell count: 6666\n" +
+        "\tMemtable data size: 1000000\n" +
+        "\tMemtable off heap memory used: 161803398\n" +
+        "\tMemtable switch count: 6\n" +
+        "\tSpeculative retries: 0\n" +
+        "\tLocal read count: 5\n" +
+        "\tLocal read latency: 1.000 ms\n" +
+        "\tLocal write count: 0\n" +
+        "\tLocal write latency: 0.500 ms\n" +
+        "\tLocal read/write ratio: 0.000\n" +
+        "\tPending flushes: 66\n" +
+        "\tPercent repaired: 0.0\n" +
+        "\tBytes repaired: 0 bytes\n" +
+        "\tBytes unrepaired: 0 bytes\n" +
+        "\tBytes pending repair: 0 bytes\n" +
+        "\tBloom filter false positives: 400\n" +
+        "\tBloom filter false ratio: 0.030\n" +
+        "\tBloom filter space used: 101112\n" +
+        "\tBloom filter off heap memory used: 667408\n" +
+        "\tIndex summary off heap memory used: 3\n" +
+        "\tCompression metadata off heap memory used: 1\n" +
+        "\tCompacted partition minimum bytes: 6 bytes\n" +
+        "\tCompacted partition maximum bytes: 20 bytes\n" +
+        "\tCompacted partition mean bytes: 3 bytes\n" +
+        "\tAverage live cells per slice (last five minutes): 5.00\n" +
+        "\tMaximum live cells per slice (last five minutes): 2\n" +
+        "\tAverage tombstones per slice (last five minutes): 6.00\n" +
+        "\tMaximum tombstones per slice (last five minutes): 6\n" +
+        "\tDroppable tombstone ratio: 0.667\n" +
+        "\n";
+
     /**
      * Expected output of TableStatsPrinter DefaultPrinter for this dataset.
      * Total number of tables is zero because it's non-trivial to simulate 
that metric
@@ -308,6 +545,42 @@ public class TableStatsPrinterTest extends 
TableStatsTestBase
         String.format(duplicateTabs(expectedDefaultTable6Output), "table6") +
         "----------------\n";
 
+    /**
+     * Expected output of TableStatsPrinter DefaultPrinter (human-readble) for 
this dataset.
+     * Total number of tables is zero because it's non-trivial to simulate 
that metric
+     * without leaking test implementation into the TableStatsHolder 
implementation.
+     */
+    public static final String expectedDefaultHumanReadablePrinterOutput =
+        "Total number of tables: 6\n" +
+        "----------------\n" +
+        "Keyspace: keyspace1\n" +
+        "\tRead Count: 3\n" +
+        "\tRead Latency: 0.000 ms\n" +
+        "\tWrite Count: 12\n" +
+        "\tWrite Latency: 0.000 ms\n" +
+        "\tPending Flushes: 233666\n" +
+        String.format(duplicateTabs(expectedDefaultHumanReadableTable1Output), 
"table1") +
+        String.format(duplicateTabs(expectedDefaultHumanReadableTable2Output), 
"table2") +
+        String.format(duplicateTabs(expectedDefaultHumanReadableTable3Output), 
"table3") +
+        "----------------\n" +
+        "Keyspace: keyspace2\n" +
+        "\tRead Count: 7\n" +
+        "\tRead Latency: 0.000 ms\n" +
+        "\tWrite Count: 3\n" +
+        "\tWrite Latency: 0.000 ms\n" +
+        "\tPending Flushes: 4449\n" +
+        String.format(duplicateTabs(expectedDefaultHumanReadableTable4Output), 
"table4") +
+        String.format(duplicateTabs(expectedDefaultHumanReadableTable5Output), 
"table5") +
+        "----------------\n" +
+        "Keyspace: keyspace3\n" +
+        "\tRead Count: 5\n" +
+        "\tRead Latency: 0.000 ms\n" +
+        "\tWrite Count: 0\n" +
+        "\tWrite Latency: NaN ms\n" +
+        "\tPending Flushes: 66\n" +
+        String.format(duplicateTabs(expectedDefaultHumanReadableTable6Output), 
"table6") +
+        "----------------\n";
+
     /**
      * Expected output from SortedDefaultPrinter for data sorted by reads in 
this test.
      */
@@ -366,6 +639,21 @@ public class TableStatsPrinterTest extends 
TableStatsTestBase
         }
     }
 
+    @Test
+    public void testDefaultHumanReadablePrinter() throws Exception
+    {
+        TestTableStatsHolder holder = new TestTableStatsHolder(testKeyspaces, 
"", 0, true);
+        holder.numberOfTables = testKeyspaces.stream().map(ks -> 
ks.tables.size()).mapToInt(Integer::intValue).sum();
+        StatsPrinter<StatsHolder> printer = TableStatsPrinter.from("", false);
+        try (ByteArrayOutputStream byteStream = new ByteArrayOutputStream())
+        {
+            printer.print(holder, new PrintStream(byteStream));
+            assertEquals("StatsTablePrinter.DefaultPrinter (human-readable) 
does not print test vector as expected",
+                         expectedDefaultHumanReadablePrinterOutput,
+                         byteStream.toString());
+        }
+    }
+
     @Test
     public void testSortedDefaultPrinter() throws Exception
     {
@@ -595,13 +883,18 @@ public class TableStatsPrinterTest extends 
TableStatsTestBase
     private static class TestTableStatsHolder extends TableStatsHolder
     {
 
-        public TestTableStatsHolder(List<StatsKeyspace> testKeyspaces, String 
sortKey, int top)
+        public TestTableStatsHolder(List<StatsKeyspace> testKeyspaces, String 
sortKey, int top, boolean humanReadable)
         {
-            super(null, false, false, new ArrayList<>(), sortKey, top, false);
+            super(null, humanReadable, false, new ArrayList<>(), sortKey, top, 
false);
             this.keyspaces.clear();
             this.keyspaces.addAll(testKeyspaces);
         }
 
+        public TestTableStatsHolder(List<StatsKeyspace> testKeyspaces, String 
sortKey, int top)
+        {
+            this(testKeyspaces, sortKey, top, false);
+        }
+
         @Override
         protected boolean isTestTableStatsHolder()
         {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to