Skip to content

Commit

Permalink
Add tool to reset SSTable level; patch by Marcus Eriksson, reviewed b…
Browse files Browse the repository at this point in the history
…y yukim for CASSANDRA-5271
  • Loading branch information
krummas authored and yukim committed Mar 4, 2013
1 parent 306a565 commit 6d5e083
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* drop unnecessary keyspace from user-defined compaction API (CASSANDRA-5139)
* more robust solution to incomplete compactions + counters (CASSANDRA-5151)
* Change order of directory searching for c*.in.sh (CASSANDRA-3983)
* Add tool to reset SSTable level (CASSANDRA-5271)


1.2.3
Expand Down
2 changes: 2 additions & 0 deletions debian/cassandra.install
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ bin/sstablescrub usr/bin
bin/cassandra-shuffle usr/bin
tools/bin/cassandra-stress usr/bin
tools/bin/token-generator usr/bin
tools/bin/sstablelevelreset usr/bin
tools/bin/sstablemetadata usr/bin
lib/*.jar usr/share/cassandra/lib
lib/*.zip usr/share/cassandra/lib
lib/licenses usr/share/doc/cassandra
80 changes: 80 additions & 0 deletions src/java/org/apache/cassandra/tools/SSTableLevelResetter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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 java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.cassandra.db.Directories;
import org.apache.cassandra.db.compaction.LeveledManifest;
import org.apache.cassandra.io.sstable.Component;
import org.apache.cassandra.io.sstable.Descriptor;
import org.apache.cassandra.io.sstable.SSTableMetadata;
import org.apache.cassandra.io.sstable.SSTableReader;

/**
* Reset level to 0 on a given set of sstables
*/
public class SSTableLevelResetter
{
/**
* @param args a list of sstables whose metadata we are changing
*/
public static void main(String[] args) throws IOException
{
PrintStream out = System.out;
if (args.length == 0)
{
out.println("This command should be run with Cassandra stopped!");
out.println("Usage: sstablelevelreset <keyspace> <columnfamily>");
System.exit(1);
}

if (!args[0].equals("--really-reset") || args.length != 3)
{
out.println("This command should be run with Cassandra stopped, otherwise you will get very strange behavior");
out.println("Verify that Cassandra is not running and then execute the command like this:");
out.println("Usage: sstablelevelreset --really-reset <keyspace> <columnfamily>");
System.exit(1);
}

String keyspace = args[1];
String columnfamily = args[2];
Directories directories = Directories.create(keyspace, columnfamily);
boolean foundSSTable = false;
for (Map.Entry<Descriptor, Set<Component>> sstable : directories.sstableLister().list().entrySet())
{
if (sstable.getValue().contains(Component.STATS))
{
foundSSTable = true;
Descriptor descriptor = sstable.getKey();
SSTableMetadata metadata = SSTableMetadata.serializer.deserialize(descriptor);
out.println("Changing level from " + metadata.sstableLevel + " to 0 on " + descriptor.filenameFor(Component.DATA));
LeveledManifest.mutateLevel(metadata, descriptor, descriptor.filenameFor(Component.STATS), 0);
}
}

if (!foundSSTable)
{
out.println("Found no sstables, did you give the correct keyspace/columnfamily?");
}
}
}
49 changes: 49 additions & 0 deletions tools/bin/sstablelevelreset
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/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$CASSANDRA_INCLUDE" = "x" ]; then
for include in "`dirname $0`/cassandra.in.sh" \
"$HOME/.cassandra.in.sh" \
/usr/share/cassandra/cassandra.in.sh \
/usr/local/share/cassandra/cassandra.in.sh \
/opt/cassandra/cassandra.in.sh; do
if [ -r $include ]; then
. $include
break
fi
done
elif [ -r $CASSANDRA_INCLUDE ]; then
. $CASSANDRA_INCLUDE
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

if [ -z $CLASSPATH ]; then
echo "You must set the CLASSPATH var" >&2
exit 1
fi

$JAVA -cp $CLASSPATH -Dstorage-config=$CASSANDRA_CONF \
-Dlog4j.configuration=log4j-tools.properties \
org.apache.cassandra.tools.SSTableLevelResetter "$@"

0 comments on commit 6d5e083

Please sign in to comment.