Add option to state current gc_grace_seconds to tools/bin/sstablemetadata

Patch by marcuse; reviewed by yukim for CASSANDRA-12208


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/ab98b115
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/ab98b115
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/ab98b115

Branch: refs/heads/cassandra-3.9
Commit: ab98b1151ecb61a62df30b9777fa962d60e97767
Parents: 4133c74
Author: Marcus Eriksson <marc...@apache.org>
Authored: Tue Aug 9 10:36:01 2016 +0200
Committer: Marcus Eriksson <marc...@apache.org>
Committed: Wed Aug 31 09:34:00 2016 +0200

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/tools/SSTableMetadataViewer.java  | 42 +++++++++++++++++---
 2 files changed, 38 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/ab98b115/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 5349c14..4b77e4d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 3.0.9
+ * Add option to state current gc_grace_seconds to tools/bin/sstablemetadata 
(CASSANDRA-12208)
  * Fix file system race condition that may cause LogAwareFileLister to fail to 
classify files (CASSANDRA-11889)
  * Fix file handle leaks due to simultaneous compaction/repair and
    listing snapshots, calculating snapshot sizes, or making schema

http://git-wip-us.apache.org/repos/asf/cassandra/blob/ab98b115/src/java/org/apache/cassandra/tools/SSTableMetadataViewer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/SSTableMetadataViewer.java 
b/src/java/org/apache/cassandra/tools/SSTableMetadataViewer.java
index 5f7513f..6076e32 100644
--- a/src/java/org/apache/cassandra/tools/SSTableMetadataViewer.java
+++ b/src/java/org/apache/cassandra/tools/SSTableMetadataViewer.java
@@ -23,6 +23,15 @@ import java.io.PrintStream;
 import java.util.EnumSet;
 import java.util.Map;
 
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
+
 import org.apache.cassandra.io.sstable.Descriptor;
 import org.apache.cassandra.io.sstable.metadata.*;
 
@@ -31,21 +40,37 @@ import org.apache.cassandra.io.sstable.metadata.*;
  */
 public class SSTableMetadataViewer
 {
+    private static final String GCGS_KEY = "gc_grace_seconds";
+
     /**
      * @param args a list of sstables whose metadata we're interested in
      */
     public static void main(String[] args) throws IOException
     {
         PrintStream out = System.out;
-        if (args.length == 0)
+        Option optGcgs = new Option(null, GCGS_KEY, true, "The "+GCGS_KEY+" to 
use when calculating droppable tombstones");
+
+        Options options = new Options();
+        options.addOption(optGcgs);
+        CommandLine cmd = null;
+        CommandLineParser parser = new PosixParser();
+        try
+        {
+            cmd = parser.parse(options, args);
+        }
+        catch (ParseException e)
         {
-            out.println("Usage: sstablemetadata <sstable filenames>");
-            System.exit(1);
+            printHelp(options, out);
         }
 
+        if (cmd.getArgs().length == 0)
+        {
+            printHelp(options, out);
+        }
+        int gcgs = Integer.parseInt(cmd.getOptionValue(GCGS_KEY, "0"));
         Util.initDatabaseDescriptor();
 
-        for (String fname : args)
+        for (String fname : cmd.getArgs())
         {
             if (new File(fname).exists())
             {
@@ -67,7 +92,7 @@ public class SSTableMetadataViewer
                     out.printf("Maximum timestamp: %s%n", stats.maxTimestamp);
                     out.printf("SSTable max local deletion time: %s%n", 
stats.maxLocalDeletionTime);
                     out.printf("Compression ratio: %s%n", 
stats.compressionRatio);
-                    out.printf("Estimated droppable tombstones: %s%n", 
stats.getEstimatedDroppableTombstoneRatio((int) (System.currentTimeMillis() / 
1000)));
+                    out.printf("Estimated droppable tombstones: %s%n", 
stats.getEstimatedDroppableTombstoneRatio((int) (System.currentTimeMillis() / 
1000) - gcgs));
                     out.printf("SSTable Level: %d%n", stats.sstableLevel);
                     out.printf("Repaired at: %d%n", stats.repairedAt);
                     out.printf("Replay positions covered: %s\n", 
stats.commitLogIntervals);
@@ -90,6 +115,13 @@ public class SSTableMetadataViewer
         }
     }
 
+    private static void printHelp(Options options, PrintStream out)
+    {
+        out.println();
+        new HelpFormatter().printHelp("Usage: sstablemetadata [--"+GCGS_KEY+" 
n] <sstable filenames>", "Dump contents of given SSTable to standard output in 
JSON format.", options, "");
+        System.exit(1);
+    }
+
     private static void printHistograms(StatsMetadata metadata, PrintStream 
out)
     {
         long[] offsets = metadata.estimatedPartitionSize.getBucketOffsets();

Reply via email to