You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2011/07/19 20:08:05 UTC

svn commit: r1148466 - in /cassandra/branches/cassandra-0.7: CHANGES.txt src/java/org/apache/cassandra/db/ColumnFamilyStore.java

Author: jbellis
Date: Tue Jul 19 18:08:04 2011
New Revision: 1148466

URL: http://svn.apache.org/viewvc?rev=1148466&view=rev
Log:
fix re-using index CF sstable names after drop/recreate
patch by jbellis; reviewed by slebresne for CASSANDRA-2872

Modified:
    cassandra/branches/cassandra-0.7/CHANGES.txt
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyStore.java

Modified: cassandra/branches/cassandra-0.7/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/CHANGES.txt?rev=1148466&r1=1148465&r2=1148466&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.7/CHANGES.txt Tue Jul 19 18:08:04 2011
@@ -3,6 +3,7 @@
    reads with dynamic snitch + read repair disabled (CASSANDRA-2870)
  * support spaces in path to log4j configuration (CASSANDRA-2383)
  * avoid including inferred types in CF update (CASSANDRA-2809)
+ * fix re-using index CF sstable names after drop/recreate (CASSANDRA-2872)
 
 
 0.7.7

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=1148466&r1=1148465&r2=1148466&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyStore.java (original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyStore.java Tue Jul 19 18:08:04 2011
@@ -466,13 +466,24 @@ public class ColumnFamilyStore implement
     {
         // get the max generation number, to prevent generation conflicts
         List<Integer> generations = new ArrayList<Integer>();
-        for (Descriptor desc : files(table.name, columnFamily, true).keySet())
+        for (String path : DatabaseDescriptor.getAllDataFileLocationsForTable(table.name))
         {
-            generations.add(desc.generation);
-            if (desc.isFromTheFuture())
+            Iterable<Pair<Descriptor, Component>> pairs = files(new File(path));
+            File incrementalsPath = new File(path, "backups");
+            if (incrementalsPath.exists())
+                pairs = Iterables.concat(pairs, files(incrementalsPath));
+
+            for (Pair<Descriptor, Component> pair : pairs)
             {
-                throw new RuntimeException(String.format("Can't open sstables from the future! Current version %s, found file: %s",
-                                                         Descriptor.CURRENT_VERSION, desc));
+                Descriptor desc = pair.left;
+                if (!desc.cfname.equals(columnFamily))
+                    continue;
+                generations.add(desc.generation);
+                if (desc.isFromTheFuture())
+                {
+                    throw new RuntimeException(String.format("Can't open sstables from the future! Current version %s, found file: %s",
+                                                             Descriptor.CURRENT_VERSION, desc));
+                }
             }
         }
         Collections.sort(generations);
@@ -622,34 +633,45 @@ public class ColumnFamilyStore implement
         final Map<Descriptor,Set<Component>> sstables = new HashMap<Descriptor,Set<Component>>();
         for (String directory : DatabaseDescriptor.getAllDataFileLocationsForTable(keyspace))
         {
-            // NB: we never "accept" a file in the FilenameFilter sense: they are added to the sstable map
-            new File(directory).list(new FilenameFilter()
+            for (Pair<Descriptor, Component> component : files(new File(directory)))
             {
-                public boolean accept(File dir, String name)
+                if (component != null && component.left.cfname.equals(columnFamily))
                 {
-                    Pair<Descriptor,Component> component = SSTable.tryComponentFromFilename(dir, name);
-                    if (component != null && component.left.cfname.equals(columnFamily))
+                    if (includeCompacted || !new File(component.left.filenameFor(Component.COMPACTED_MARKER)).exists())
                     {
-                        if (includeCompacted || !new File(component.left.filenameFor(Component.COMPACTED_MARKER)).exists())
+                        Set<Component> components = sstables.get(component.left);
+                        if (components == null)
                         {
-                            Set<Component> components = sstables.get(component.left);
-                            if (components == null)
-                            {
-                                components = new HashSet<Component>();
-                                sstables.put(component.left, components);
-                            }
-                            components.add(component.right);
+                            components = new HashSet<Component>();
+                            sstables.put(component.left, components);
                         }
-                        else
-                            logger.debug("not including compacted sstable " + component.left.cfname + "-" + component.left.generation);
+                        components.add(component.right);
                     }
-                    return false;
+                    else
+                        logger.debug("not including compacted sstable " + component.left.cfname + "-" + component.left.generation);
                 }
-            });
+            }
         }
         return sstables;
     }
 
+    private static List<Pair<Descriptor, Component>> files(File path)
+    {
+        final List<Pair<Descriptor, Component>> sstables = new ArrayList<Pair<Descriptor, Component>>();
+        // NB: we never "accept" a file in the FilenameFilter sense: they are added to the sstable map
+        path.list(new FilenameFilter()
+        {
+            public boolean accept(File dir, String name)
+            {
+                Pair<Descriptor, Component> pair = SSTable.tryComponentFromFilename(dir, name);
+                if (pair != null)
+                    sstables.add(pair);
+                return false;
+            }
+        });
+        return sstables;
+    }
+
     /**
      * @return the name of the column family
      */