add sstablemetadata utility
patch by jbellis; reviewed by brandonwilliams for CASSANDRA-4211


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

Branch: refs/heads/cassandra-1.1
Commit: 606e666f846a7be65716bdfad0afb2083cf4f797
Parents: 46e422a
Author: Jonathan Ellis <jbel...@apache.org>
Authored: Wed May 2 13:28:27 2012 -0500
Committer: Jonathan Ellis <jbel...@apache.org>
Committed: Wed May 2 14:10:53 2012 -0500

----------------------------------------------------------------------
 .../cassandra/tools/SSTableMetadataViewer.java     |   76 +++++++++++++++
 tools/bin/sstablemetadata                          |   46 +++++++++
 tools/bin/sstablemetadata.bat                      |   30 ++++++
 3 files changed, 152 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/606e666f/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
new file mode 100644
index 0000000..13b491c
--- /dev/null
+++ b/src/java/org/apache/cassandra/tools/SSTableMetadataViewer.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.tools;
+
+import java.io.IOException;
+import java.io.PrintStream;
+
+import org.apache.cassandra.config.ConfigurationException;
+import org.apache.cassandra.io.sstable.Descriptor;
+import org.apache.cassandra.io.sstable.SSTableMetadata;
+
+/**
+ * Shows the contents of sstable metadata
+ */
+public class SSTableMetadataViewer
+{
+    /**
+     * @param args a list of sstables whose metadata we're interested in
+     */
+    public static void main(String[] args) throws IOException, 
ConfigurationException
+    {
+        PrintStream out = System.out;
+        if (args.length == 0)
+        {
+            out.println("Usage: sstablemetadata <sstable filenames>");
+            System.exit(1);
+        }
+
+        for (String fname : args)
+        {
+            Descriptor descriptor = Descriptor.fromFilename(fname);
+            SSTableMetadata metadata = 
SSTableMetadata.serializer.deserialize(descriptor);
+
+            out.printf("SSTable: %s\n", descriptor);
+            out.printf("Partitioner: %s\n", metadata.partitioner);
+            out.printf("Maximum timestamp: %s\n", metadata.maxTimestamp);
+            out.printf("Compression ratio: %s\n", metadata.compressionRatio);
+            out.printf("Estimated droppable tombstones: %s\n", 
metadata.getEstimatedDroppableTombstoneRatio((int) (System.currentTimeMillis() 
/ 1000)));
+            out.println(metadata.replayPosition);
+            printHistograms(metadata, out);
+        }
+    }
+
+    private static void printHistograms(SSTableMetadata metadata, PrintStream 
out)
+    {
+        long[] offsets = metadata.estimatedRowSize.getBucketOffsets();
+        long[] ersh = metadata.estimatedRowSize.getBuckets(false);
+        long[] ecch = metadata.estimatedColumnCount.getBuckets(false);
+
+        out.println(String.format("%-10s%18s%18s",
+                                  "Count", "Row Size", "Column Count"));
+
+        for (int i = 0; i < offsets.length; i++)
+        {
+            out.println(String.format("%-10d%18s%18s",
+                                      offsets[i],
+                                      (i < ersh.length ? ersh[i] : ""),
+                                      (i < ecch.length ? ecch[i] : "")));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/606e666f/tools/bin/sstablemetadata
----------------------------------------------------------------------
diff --git a/tools/bin/sstablemetadata b/tools/bin/sstablemetadata
new file mode 100644
index 0000000..5fe8cc4
--- /dev/null
+++ b/tools/bin/sstablemetadata
@@ -0,0 +1,46 @@
+#!/bin/sh
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+if [ "x$CLASSPATH" = "x" ]; then
+    
+    # execute from the build dir.
+    if [ -d `dirname $0`/../../build/classes ]; then
+        for directory in `dirname $0`/../../build/classes/*; do
+            CLASSPATH=$CLASSPATH:$directory
+        done
+    else
+        if [ -f `dirname $0`/../lib/stress.jar ]; then
+            CLASSPATH=`dirname $0`/../lib/stress.jar
+        fi
+    fi
+
+    for jar in `dirname $0`/../../lib/*.jar; do
+        CLASSPATH=$CLASSPATH:$jar
+    done
+fi
+
+# Use JAVA_HOME if set, otherwise look for java in PATH
+if [ -x $JAVA_HOME/bin/java ]; then
+    JAVA=$JAVA_HOME/bin/java
+else
+    JAVA=`which java`
+fi
+
+$JAVA -cp $CLASSPATH \
+        -Dlog4j.configuration=log4j-tools.properties \
+        org.apache.cassandra.tools.SSTableMetadataViewer "$@"

http://git-wip-us.apache.org/repos/asf/cassandra/blob/606e666f/tools/bin/sstablemetadata.bat
----------------------------------------------------------------------
diff --git a/tools/bin/sstablemetadata.bat b/tools/bin/sstablemetadata.bat
new file mode 100644
index 0000000..2b945ec
--- /dev/null
+++ b/tools/bin/sstablemetadata.bat
@@ -0,0 +1,30 @@
+@REM  Licensed to the Apache Software Foundation (ASF) under one or more
+@REM  contributor license agreements.  See the NOTICE file distributed with
+@REM  this work for additional information regarding copyright ownership.
+@REM  The ASF licenses this file to You under the Apache License, Version 2.0
+@REM  (the "License"); you may not use this file except in compliance with
+@REM  the License.  You may obtain a copy of the License at
+@REM
+@REM      http://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM  Unless required by applicable law or agreed to in writing, software
+@REM  distributed under the License is distributed on an "AS IS" BASIS,
+@REM  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@REM  See the License for the specific language governing permissions and
+@REM  limitations under the License.
+
+@echo off
+
+if NOT DEFINED CASSANDRA_HOME set CASSANDRA_HOME=%CD%\..\..
+
+set CLASSPATH=""
+for %%i in ("%CASSANDRA_HOME%\build\*.jar") do call :append "%%i"
+for %%i in ("%CASSANDRA_HOME%\lib\*.jar") do call :append "%%i"
+goto start
+
+:append
+set CLASSPATH=%CLASSPATH%;%1
+goto :eof
+
+:start
+"%JAVA_HOME%\bin\java" -cp %CLASSPATH% 
org.apache.cassandra.tools.SSTableMetadataViewer %*

Reply via email to