Author: jbellis
Date: Tue Jul 28 02:45:45 2009
New Revision: 798369
URL: http://svn.apache.org/viewvc?rev=798369&view=rev
Log:
naive fsync-after-each-log-entry
patch by jbellis; reviewed by Jun Rao for CASSANDRA-182
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/db/CommitLog.java
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/AbstractWriter.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=798369&r1=798368&r2=798369&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
Tue Jul 28 02:45:45 2009
@@ -349,7 +349,6 @@
try
{
/* serialize the row */
- cfBuffer.reset();
Row.serializer().serialize(row, cfBuffer);
currentPosition = logWriter_.getCurrentPosition();
cLogCtx = new CommitLogContext(logFile_, currentPosition);
@@ -357,7 +356,10 @@
maybeUpdateHeader(row);
logWriter_.writeLong(cfBuffer.getLength());
logWriter_.append(cfBuffer);
- checkThresholdAndRollLog();
+ if (!maybeRollLog())
+ {
+ logWriter_.sync();
+ }
}
catch (IOException e)
{
@@ -365,10 +367,6 @@
logWriter_.seek(currentPosition);
throw e;
}
- finally
- {
- cfBuffer.close();
- }
return cLogCtx;
}
@@ -466,7 +464,7 @@
}
}
- private void checkThresholdAndRollLog() throws IOException
+ private boolean maybeRollLog() throws IOException
{
if (logWriter_.getFileSize() >= SEGMENT_SIZE)
{
@@ -484,6 +482,8 @@
// with the current one.
clHeader_.zeroPositions();
writeCommitLogHeader(logWriter_, clHeader_.toByteArray());
+ return true;
}
+ return false;
}
}
\ No newline at end of file
Modified:
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/AbstractWriter.java
URL:
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/AbstractWriter.java?rev=798369&r1=798368&r2=798369&view=diff
==============================================================================
---
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/AbstractWriter.java
(original)
+++
incubator/cassandra/trunk/src/java/org/apache/cassandra/io/AbstractWriter.java
Tue Jul 28 02:45:45 2009
@@ -117,6 +117,9 @@
*/
public abstract long getFileSize() throws IOException;
+ /** fsync the writer */
+ public abstract void sync() throws IOException;
+
public static class Writer extends AbstractWriter
{
@@ -229,7 +232,7 @@
public void close() throws IOException
{
- file_.getChannel().force(true);
+ sync();
file_.close();
}
@@ -248,6 +251,11 @@
{
return file_.length();
}
+
+ public void sync() throws IOException
+ {
+ file_.getChannel().force(true);
+ }
}
public static class BufferWriter extends Writer