cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdusba...@apache.org
Subject svn commit: r953376 - in /cassandra/branches/cassandra-0.6: CHANGES.txt src/java/org/apache/cassandra/db/commitlog/CommitLog.java test/unit/org/apache/cassandra/db/CommitLogTest.java
Date Thu, 10 Jun 2010 16:26:44 GMT
Author: gdusbabek
Date: Thu Jun 10 16:26:43 2010
New Revision: 953376

URL: http://svn.apache.org/viewvc?rev=953376&view=rev
Log:
detect incomplete commit log headers. patch by Matthew Dennis, reviewed by Gary Dusbabek.
CASSANDRA-1119

Modified:
    cassandra/branches/cassandra-0.6/CHANGES.txt
    cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLog.java
    cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/CommitLogTest.java

Modified: cassandra/branches/cassandra-0.6/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/CHANGES.txt?rev=953376&r1=953375&r2=953376&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.6/CHANGES.txt Thu Jun 10 16:26:43 2010
@@ -18,6 +18,7 @@
    (CASSANDRA-1118)
  * restructure the startup ordering of Gossiper and MessageService to avoid
    timing anomalies (CASSANDRA-1160)
+ * detect incomplete commit log hearders (CASSANDRA-1119)
 
 
 0.6.2

Modified: cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLog.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLog.java?rev=953376&r1=953375&r2=953376&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLog.java
(original)
+++ cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLog.java
Thu Jun 10 16:26:43 2010
@@ -18,28 +18,26 @@
 
 package org.apache.cassandra.db.commitlog;
 
+import org.apache.cassandra.concurrent.StageManager;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.db.ColumnFamily;
 import org.apache.cassandra.db.RowMutation;
 import org.apache.cassandra.db.Table;
-import org.apache.cassandra.io.util.BufferedRandomAccessFile;
 import org.apache.cassandra.io.DeletionService;
+import org.apache.cassandra.io.util.BufferedRandomAccessFile;
 import org.apache.cassandra.io.util.FileUtils;
 import org.apache.cassandra.utils.WrappedRunnable;
-import org.apache.cassandra.concurrent.StageManager;
-
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
 
 import java.io.*;
 import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.zip.Checksum;
-import java.util.zip.CRC32;
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.zip.CRC32;
+import java.util.zip.Checksum;
 
 /*
  * Commit Log tracks every write operation into the system. The aim
@@ -184,7 +182,18 @@ public class CommitLog
         {
             int bufferSize = (int)Math.min(file.length(), 32 * 1024 * 1024);
             BufferedRandomAccessFile reader = new BufferedRandomAccessFile(file.getAbsolutePath(),
"r", bufferSize);
-            final CommitLogHeader clHeader = CommitLogHeader.readCommitLogHeader(reader);
+
+            final CommitLogHeader clHeader;
+            try
+            {
+                clHeader = CommitLogHeader.readCommitLogHeader(reader);
+            }
+            catch (EOFException eofe)
+            {
+                logger.info("Attempted to recover an incomplete CommitLogHeader.  Everything
is ok, don't panic.");
+                continue;
+            }
+
             /* seek to the lowest position where any CF has non-flushed data */
             int lowPos = CommitLogHeader.getLowestPosition(clHeader);
             if (lowPos == 0)

Modified: cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/CommitLogTest.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/CommitLogTest.java?rev=953376&r1=953375&r2=953376&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/CommitLogTest.java
(original)
+++ cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/CommitLogTest.java
Thu Jun 10 16:26:43 2010
@@ -18,14 +18,16 @@
 */
 package org.apache.cassandra.db;
 
-import java.io.IOException;
-import java.util.concurrent.ExecutionException;
-
-import org.junit.Test;
-
 import org.apache.cassandra.CleanupHelper;
 import org.apache.cassandra.db.commitlog.CommitLog;
 import org.apache.cassandra.db.filter.QueryPath;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.concurrent.ExecutionException;
 
 public class CommitLogTest extends CleanupHelper
 {
@@ -59,4 +61,15 @@ public class CommitLogTest extends Clean
         store2.forceBlockingFlush();
         assert CommitLog.instance().getSegmentCount() == 1;
     }
+
+    @Test
+    public void testRecoveryWithPartiallyWrittenHeader() throws Exception
+    {
+        File tmpFile = File.createTempFile("testRecoveryWithPartiallyWrittenHeaderTestFile",
null);
+        tmpFile.deleteOnExit();
+        OutputStream out = new FileOutputStream(tmpFile);
+        out.write(new byte[6]);
+        //statics make it annoying to test things correctly
+        CommitLog.instance().recover(new File[] {tmpFile}); //CASSANDRA-1119 throws on failure
+    }
 }



Mime
View raw message