cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yu...@apache.org
Subject [2/6] git commit: Fix sstablelevelresetter hang
Date Fri, 25 Jul 2014 15:38:09 GMT
Fix sstablelevelresetter hang

patch by yukim; reviewed by krummas for CASSANDRA-7614


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

Branch: refs/heads/cassandra-2.1.0
Commit: e2219ebd8f30cd023affc76c3a3b20f3cb37fb9f
Parents: 17b26a2
Author: Yuki Morishita <yukim@apache.org>
Authored: Fri Jul 25 10:31:50 2014 -0500
Committer: Yuki Morishita <yukim@apache.org>
Committed: Fri Jul 25 10:36:45 2014 -0500

----------------------------------------------------------------------
 CHANGES.txt                                     |  1 +
 .../cassandra/tools/SSTableLevelResetter.java   | 62 ++++++++++++++------
 2 files changed, 45 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/e2219ebd/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 772e1f6..7a26fa6 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -6,6 +6,7 @@
  * Get java version correctly when JAVA_TOOL_OPTIONS is set (CASSANDRA-7572)
  * Fix NPE when dropping index from non-existent keyspace, AssertionError when
    dropping non-existent index with IF EXISTS (CASSANDRA-7590)
+ * Fix sstablelevelresetter hang (CASSANDRA-7614)
 Merged from 2.0:
  * Fix ReversedType(DateType) mapping to native protocol (CASSANDRA-7576)
  * Always merge ranges owned by a single node (CASSANDRA-6930)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/e2219ebd/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
index 2d95ad2..4c5e101 100644
--- a/src/java/org/apache/cassandra/tools/SSTableLevelResetter.java
+++ b/src/java/org/apache/cassandra/tools/SSTableLevelResetter.java
@@ -23,6 +23,7 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.config.Schema;
 import org.apache.cassandra.db.ColumnFamilyStore;
 import org.apache.cassandra.db.Keyspace;
 import org.apache.cassandra.io.sstable.Component;
@@ -56,29 +57,54 @@ public class SSTableLevelResetter
             System.exit(1);
         }
 
-        // load keyspace descriptions.
-        DatabaseDescriptor.loadSchemas();
-
-        String keyspaceName = args[1];
-        String columnfamily = args[2];
-        Keyspace keyspace = Keyspace.openWithoutSSTables(keyspaceName);
-        ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(columnfamily);
-        boolean foundSSTable = false;
-        for (Map.Entry<Descriptor, Set<Component>> sstable : cfs.directories.sstableLister().list().entrySet())
+        // TODO several daemon threads will run from here.
+        // So we have to explicitly call System.exit.
+        try
         {
-            if (sstable.getValue().contains(Component.STATS))
+            // load keyspace descriptions.
+            DatabaseDescriptor.loadSchemas();
+
+            String keyspaceName = args[1];
+            String columnfamily = args[2];
+            // validate columnfamily
+            if (Schema.instance.getCFMetaData(keyspaceName, columnfamily) == null)
             {
-                foundSSTable = true;
-                Descriptor descriptor = sstable.getKey();
-                StatsMetadata metadata = (StatsMetadata) descriptor.getMetadataSerializer().deserialize(descriptor,
MetadataType.STATS);
-                out.println("Changing level from " + metadata.sstableLevel + " to 0 on "
+ descriptor.filenameFor(Component.DATA));
-                descriptor.getMetadataSerializer().mutateLevel(descriptor, 0);
+                System.err.println("ColumnFamily not found: " + keyspaceName + "/" + columnfamily);
+                System.exit(1);
+            }
+
+            Keyspace keyspace = Keyspace.openWithoutSSTables(keyspaceName);
+            ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(columnfamily);
+            boolean foundSSTable = false;
+            for (Map.Entry<Descriptor, Set<Component>> sstable : cfs.directories.sstableLister().list().entrySet())
+            {
+                if (sstable.getValue().contains(Component.STATS))
+                {
+                    foundSSTable = true;
+                    Descriptor descriptor = sstable.getKey();
+                    StatsMetadata metadata = (StatsMetadata) descriptor.getMetadataSerializer().deserialize(descriptor,
MetadataType.STATS);
+                    if (metadata.sstableLevel > 0)
+                    {
+                        out.println("Changing level from " + metadata.sstableLevel + " to
0 on " + descriptor.filenameFor(Component.DATA));
+                        descriptor.getMetadataSerializer().mutateLevel(descriptor, 0);
+                    }
+                    else
+                    {
+                        out.println("Skipped " + descriptor.filenameFor(Component.DATA) +
" since it is already on level 0");
+                    }
+                }
             }
-        }
 
-        if (!foundSSTable)
+            if (!foundSSTable)
+            {
+                out.println("Found no sstables, did you give the correct keyspace/columnfamily?");
+            }
+        }
+        catch (Throwable e)
         {
-            out.println("Found no sstables, did you give the correct keyspace/columnfamily?");
+            e.printStackTrace();
+            System.exit(1);
         }
+        System.exit(0);
     }
 }


Mime
View raw message