cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dbros...@apache.org
Subject [3/4] git commit: Add debug logging to list filenames processed by o.a.c.db.Directories.migrateFile method patch by dbrosius reviewed by slebresne for CASSANDRA-4939
Date Tue, 13 Nov 2012 04:14:41 GMT
Add debug logging to list filenames processed by o.a.c.db.Directories.migrateFile method
patch by dbrosius reviewed by slebresne for CASSANDRA-4939


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

Branch: refs/heads/trunk
Commit: 6677d075e9cadc073633fd84f810b9fc5174db45
Parents: c57fc3b
Author: Dave Brosius <dbrosius@apache.org>
Authored: Mon Nov 12 19:57:31 2012 -0500
Committer: Dave Brosius <dbrosius@apache.org>
Committed: Mon Nov 12 19:57:31 2012 -0500

----------------------------------------------------------------------
 CHANGES.txt                                        |    4 ++
 src/java/org/apache/cassandra/db/Directories.java  |   42 ++++++++++-----
 .../org/apache/cassandra/db/DirectoriesTest.java   |   40 ++++++++++++--
 3 files changed, 67 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/6677d075/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 7d4882d..d7855af 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,7 @@
+1.2.1
+ * Add debug logging to list filenames processed by Directories.migrateFile method (CASSANDRA-4939)
+
+
 1.2-rc1
  * fix cqlsh DESCRIBE command (CASSANDRA-4913)
  * save truncation position in system table (CASSANDRA-4906)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6677d075/src/java/org/apache/cassandra/db/Directories.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/db/Directories.java b/src/java/org/apache/cassandra/db/Directories.java
index 877b5ed..9e53ab9 100644
--- a/src/java/org/apache/cassandra/db/Directories.java
+++ b/src/java/org/apache/cassandra/db/Directories.java
@@ -620,19 +620,35 @@ public class Directories
         if (file.isDirectory())
             return;
 
-        String name = file.getName();
-        boolean isManifest = name.endsWith(LeveledManifest.EXTENSION);
-        String cfname = isManifest
-                      ? name.substring(0, name.length() - LeveledManifest.EXTENSION.length())
-                      : name.substring(0, name.indexOf(Component.separator));
-
-        int idx = cfname.indexOf(SECONDARY_INDEX_NAME_SEPARATOR); // idx > 0 => secondary
index
-        String dirname = idx > 0 ? cfname.substring(0, idx) : cfname;
-        File destDir = getOrCreate(ksDir, dirname, additionalPath);
-
-        File destFile = new File(destDir, isManifest ? name : ksDir.getName() + Component.separator
+ name);
-        logger.debug(String.format("[upgrade to 1.1] Moving %s to %s", file, destFile));
-        FileUtils.renameWithConfirm(file, destFile);
+        try
+        {
+            String name = file.getName();
+            boolean isManifest = name.endsWith(LeveledManifest.EXTENSION);
+            int separatorIndex = name.indexOf(Component.separator);
+
+            if (isManifest || (separatorIndex >= 0))
+            {
+                String cfname = isManifest
+                              ? name.substring(0, name.length() - LeveledManifest.EXTENSION.length())
+                              : name.substring(0, separatorIndex);
+
+                int idx = cfname.indexOf(SECONDARY_INDEX_NAME_SEPARATOR); // idx > 0 =>
secondary index
+                String dirname = idx > 0 ? cfname.substring(0, idx) : cfname;
+                File destDir = getOrCreate(ksDir, dirname, additionalPath);
+
+                File destFile = new File(destDir, isManifest ? name : ksDir.getName() + Component.separator
+ name);
+                logger.debug(String.format("[upgrade to 1.1] Moving %s to %s", file, destFile));
+                FileUtils.renameWithConfirm(file, destFile);
+            }
+            else
+            {
+                logger.warn("Found unrecognized file {} while migrating sstables from pre
1.1 format, ignoring.", file);
+            }
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException(String.format("Failed migrating file %s from pre 1.1
format.", file.getPath()), e);
+        }
     }
 
     // Hack for tests, don't use otherwise

http://git-wip-us.apache.org/repos/asf/cassandra/blob/6677d075/test/unit/org/apache/cassandra/db/DirectoriesTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/db/DirectoriesTest.java b/test/unit/org/apache/cassandra/db/DirectoriesTest.java
index d1a44fd..ba6576d 100644
--- a/test/unit/org/apache/cassandra/db/DirectoriesTest.java
+++ b/test/unit/org/apache/cassandra/db/DirectoriesTest.java
@@ -22,13 +22,14 @@ import java.io.IOException;
 import java.util.*;
 
 import org.junit.AfterClass;
+import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import static org.junit.Assert.assertEquals;
 
 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.util.FileUtils;
-import org.apache.cassandra.io.sstable.*;
 
 public class DirectoriesTest
 {
@@ -103,14 +104,14 @@ public class DirectoriesTest
         for (String cf : CFS)
         {
             Directories directories = Directories.create(KS, cf);
-            assertEquals(cfDir(cf), directories.getDirectoryForNewSSTables(0));
+            Assert.assertEquals(cfDir(cf), directories.getDirectoryForNewSSTables(0));
 
             Descriptor desc = new Descriptor(cfDir(cf), KS, cf, 1, false);
             File snapshotDir = new File(cfDir(cf),  File.separator + Directories.SNAPSHOT_SUBDIR
+ File.separator + "42");
-            assertEquals(snapshotDir, directories.getSnapshotDirectory(desc, "42"));
+            Assert.assertEquals(snapshotDir, directories.getSnapshotDirectory(desc, "42"));
 
             File backupsDir = new File(cfDir(cf),  File.separator + Directories.BACKUPS_SUBDIR);
-            assertEquals(backupsDir, directories.getBackupsDirectory(desc));
+            Assert.assertEquals(backupsDir, directories.getBackupsDirectory(desc));
         }
     }
 
@@ -167,7 +168,34 @@ public class DirectoriesTest
         {
             Directories directories = Directories.create(KS, cf);
             File manifest = new File(cfDir(cf), cf + LeveledManifest.EXTENSION);
-            assertEquals(manifest, directories.tryGetLeveledManifest());
+            Assert.assertEquals(manifest, directories.tryGetLeveledManifest());
+        }
+    }
+
+    @Test
+    public void testHandleBadFiles() throws IOException
+    {
+        /* files not matching the pattern should just be ignored, with a log warning */
+        Directories directories = Directories.create(KS, "bad");
+        File dir = directories.getDirectoryForNewSSTables(1);
+        File f = File.createTempFile("bad", "file", dir.getParentFile());
+        Directories.migrateSSTables();
+        Assert.assertTrue(f.isFile());
+
+        /* real failures should throw an exception with informational message */
+        f = File.createTempFile("locked", ".json", dir.getParentFile());
+        File targetDir = new File(dir.getParentFile(), f.getName().substring(0, f.getName().length()
- ".json".length()));
+        targetDir.mkdirs();
+        targetDir.setReadOnly();
+
+        try
+        {
+            Directories.migrateSSTables();
+            Assert.assertFalse(true);
+        }
+        catch (Exception e)
+        {
+            Assert.assertTrue(e.getMessage().contains(f.getPath()));
         }
     }
 }


Mime
View raw message