Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9FC71C93A for ; Wed, 2 May 2012 19:13:35 +0000 (UTC) Received: (qmail 53147 invoked by uid 500); 2 May 2012 19:13:35 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 53054 invoked by uid 500); 2 May 2012 19:13:35 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 52965 invoked by uid 99); 2 May 2012 19:13:35 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 May 2012 19:13:35 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 1B3EB13845; Wed, 2 May 2012 19:13:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jbellis@apache.org To: commits@cassandra.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [2/3] git commit: add sstablemetadata utility patch by jbellis; reviewed by brandonwilliams for CASSANDRA-4211 Message-Id: <20120502191335.1B3EB13845@tyr.zones.apache.org> Date: Wed, 2 May 2012 19:13:35 +0000 (UTC) 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/trunk Commit: 606e666f846a7be65716bdfad0afb2083cf4f797 Parents: 46e422a Author: Jonathan Ellis Authored: Wed May 2 13:28:27 2012 -0500 Committer: Jonathan Ellis 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 "); + 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 %*