Updated Branches:
  refs/heads/trunk 306a565a4 -> 6d5e0831a

Add tool to reset SSTable level; patch by Marcus Eriksson, reviewed by yukim 
for CASSANDRA-5271


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

Branch: refs/heads/trunk
Commit: 6d5e0831a42541a3ce4b1bac32d1285fb1004241
Parents: 306a565
Author: Marcus Eriksson <[email protected]>
Authored: Mon Mar 4 11:46:51 2013 -0600
Committer: Yuki Morishita <[email protected]>
Committed: Mon Mar 4 12:08:51 2013 -0600

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 debian/cassandra.install                           |    2 +
 .../cassandra/tools/SSTableLevelResetter.java      |   80 +++++++++++++++
 tools/bin/sstablelevelreset                        |   49 +++++++++
 4 files changed, 132 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/6d5e0831/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 720d76f..c71db7b 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -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

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6d5e0831/debian/cassandra.install
----------------------------------------------------------------------
diff --git a/debian/cassandra.install b/debian/cassandra.install
index 6fa84ce..56d6bf3 100644
--- a/debian/cassandra.install
+++ b/debian/cassandra.install
@@ -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

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6d5e0831/src/java/org/apache/cassandra/tools/SSTableLevelResetter.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/tools/SSTableLevelResetter.java 
b/src/java/org/apache/cassandra/tools/SSTableLevelResetter.java
new file mode 100644
index 0000000..7fe8059
--- /dev/null
+++ b/src/java/org/apache/cassandra/tools/SSTableLevelResetter.java
@@ -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?");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6d5e0831/tools/bin/sstablelevelreset
----------------------------------------------------------------------
diff --git a/tools/bin/sstablelevelreset b/tools/bin/sstablelevelreset
new file mode 100755
index 0000000..a6fb33b
--- /dev/null
+++ b/tools/bin/sstablelevelreset
@@ -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 "$@"

Reply via email to