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

git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@807364 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Ellis 2009-08-24 20:31:56 +00:00
parent e871517c62
commit 5fd4ff7747
1 changed files with 9 additions and 17 deletions

View File

@ -246,16 +246,6 @@ public class CommitLog
return CommitLogHeader.serializer().deserialize(new DataInputStream(byteStream));
}
/*
* 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 @@ public class CommitLog
* 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 @@ public class CommitLog
* 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();
}
}
}