cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r807364 - /incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java
Date Mon, 24 Aug 2009 20:31:57 GMT
Author: jbellis
Date: Mon Aug 24 20:31:56 2009
New Revision: 807364

URL: http://svn.apache.org/viewvc?rev=807364&view=rev
Log:
CASSANDRA-370 avoid opening multiple writers for the current file; the buffered nature of
the global logWriter_ could cause problems
patch by jbellis; reviewed by Sammy Yu for CASSANDRA-370

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java?rev=807364&r1=807363&r2=807364&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java Mon Aug 24 20:31:56
2009
@@ -247,16 +247,6 @@
     }
 
     /*
-     * Write the serialized commit log header into the specified commit log.
-    */
-    private static void writeCommitLogHeader(String commitLogFileName, byte[] bytes) throws
IOException
-    {
-        RandomAccessFile logWriter = CommitLog.createWriter(commitLogFileName);
-        writeCommitLogHeader(logWriter, bytes);
-        logWriter.close();
-    }
-
-    /*
      * This is invoked on startup via the ctor. It basically
      * writes a header with all bits set to zero.
     */
@@ -495,9 +485,9 @@
          * encounter the file in the context in our list of old commit log files
          * then we update the header and write it back to the commit log.
         */
-        for(String oldFile : oldFiles)
+        for (String oldFile : oldFiles)
         {
-            if(oldFile.equals(cLogCtx.file))
+            if (oldFile.equals(cLogCtx.file))
             {
                 /*
                  * We need to turn on again. This is because we always keep
@@ -506,23 +496,25 @@
                  * perform & operation and then turn on with the new position.
                 */
                 commitLogHeader.turnOn(id, cLogCtx.position);
-                writeCommitLogHeader(cLogCtx.file, commitLogHeader.toByteArray());
+                writeCommitLogHeader(logWriter_, commitLogHeader.toByteArray());
                 break;
             }
             else
             {
                 CommitLogHeader oldCommitLogHeader = clHeaders_.get(oldFile);
                 oldCommitLogHeader.and(commitLogHeader);
-                if(oldCommitLogHeader.isSafeToDelete())
+                if (oldCommitLogHeader.isSafeToDelete())
                 {
-                	if (logger_.isDebugEnabled())
-                	  logger_.debug("Deleting commit log:"+ oldFile);
+                    if (logger_.isDebugEnabled())
+                      logger_.debug("Deleting commit log:" + oldFile);
                     FileUtils.deleteAsync(oldFile);
                     listOfDeletedFiles.add(oldFile);
                 }
                 else
                 {
-                    writeCommitLogHeader(oldFile, oldCommitLogHeader.toByteArray());
+                    RandomAccessFile logWriter = CommitLog.createWriter(oldFile);
+                    writeCommitLogHeader(logWriter, oldCommitLogHeader.toByteArray());
+                    logWriter.close();
                 }
             }
         }



Mime
View raw message