|
@@ -49,6 +49,8 @@ public class EditLogFileOutputStream extends EditLogOutputStream {
|
|
|
private EditsDoubleBuffer doubleBuf;
|
|
|
static ByteBuffer fill = ByteBuffer.allocateDirect(MIN_PREALLOCATION_LENGTH);
|
|
|
|
|
|
+ private static boolean shouldSkipFsyncForTests = false;
|
|
|
+
|
|
|
static {
|
|
|
fill.position(0);
|
|
|
for (int i = 0; i < fill.capacity(); i++) {
|
|
@@ -184,7 +186,9 @@ public class EditLogFileOutputStream extends EditLogOutputStream {
|
|
|
}
|
|
|
preallocate(); // preallocate file if necessay
|
|
|
doubleBuf.flushTo(fp);
|
|
|
- fc.force(false); // metadata updates not needed
|
|
|
+ if (!shouldSkipFsyncForTests) {
|
|
|
+ fc.force(false); // metadata updates not needed
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -247,4 +251,15 @@ public class EditLogFileOutputStream extends EditLogOutputStream {
|
|
|
public FileChannel getFileChannelForTesting() {
|
|
|
return fc;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * For the purposes of unit tests, we don't need to actually
|
|
|
+ * write durably to disk. So, we can skip the fsync() calls
|
|
|
+ * for a speed improvement.
|
|
|
+ * @param skip true if fsync should <em>not</em> be called
|
|
|
+ */
|
|
|
+ @VisibleForTesting
|
|
|
+ public static void setShouldSkipFsyncForTesting(boolean skip) {
|
|
|
+ shouldSkipFsyncForTests = skip;
|
|
|
+ }
|
|
|
}
|