add sstablemetadata utility

patch by jbellis; reviewed by brandonwilliams for CASSANDRA-4211
This commit is contained in:
Jonathan Ellis 2012-05-02 13:28:27 -05:00
parent 46e422a941
commit 606e666f84
3 changed files with 152 additions and 0 deletions

View File

@ -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] : "")));
}
}
}

46
tools/bin/sstablemetadata Normal file
View File

@ -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 "$@"

View File

@ -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 %*