public class TestRandomAccessFileSynchronousWrites
extends junit.framework.TestCase
RandomAccessFile
opened using rss
or rdd
mode. A conforming platform will NOT reorder writes and will a request to
FileChannel.force(boolean)
will flush data through to stable media
before the write operation returns. A write cache in the operating system,
device driver, controller, or disk drive can defeat synchronous IO with the
results that: (a) the sequence in which writes are issued by the application
may not be the sequence in which the data are laid down on the disk; and (b)
the write operation may return before the data are stable on disk.
Both of these results can break the semantics of the atomic commit protocol in at least the following ways:
Modifier and Type | Field and Description |
---|---|
protected static org.apache.log4j.Logger |
log |
Constructor and Description |
---|
TestRandomAccessFileSynchronousWrites() |
TestRandomAccessFileSynchronousWrites(String name) |
Modifier and Type | Method and Description |
---|---|
protected void |
assertWriteCacheDisabled(com.bigdata.journal.TestRandomAccessFileSynchronousWrites.Stats baseline,
com.bigdata.journal.TestRandomAccessFileSynchronousWrites.Stats syncio)
Verify that the request to sync to disk with each IO (
rws or
rwd ) was honored by the underlying platform. |
protected com.bigdata.journal.TestRandomAccessFileSynchronousWrites.Stats |
doSyncWriteTest(String mode)
Test helper attempts to detect when a request for synchronous writes is
being ignored by the platform.
|
void |
test_syncWrites_rdd()
Test verifies whether or not the platform appears to perform synchronous
IOs when creating a
RandomAccessFile with mode rws . |
void |
test_syncWrites_rds()
Test verifies whether or not the platform appears to perform synchronous
IOs when creating a
RandomAccessFile with mode rws . |
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, setUp, tearDown, toString
public TestRandomAccessFileSynchronousWrites()
public TestRandomAccessFileSynchronousWrites(String name)
public void test_syncWrites_rds() throws IOException
RandomAccessFile
with mode rws
.IOException
public void test_syncWrites_rdd() throws IOException
RandomAccessFile
with mode rws
.IOException
protected void assertWriteCacheDisabled(com.bigdata.journal.TestRandomAccessFileSynchronousWrites.Stats baseline, com.bigdata.journal.TestRandomAccessFileSynchronousWrites.Stats syncio)
rws
or
rwd
) was honored by the underlying platform.baseline
- The rw
performance Stats
.syncio
- The performance for either the rws
or
rwd
modes, which require synchronization to the
disk after each write.junit.framework.AssertionFailedError
- unless the write IOPs are significantly lower for the
syncio condition.protected com.bigdata.journal.TestRandomAccessFileSynchronousWrites.Stats doSyncWriteTest(String mode) throws IOException
Note: The file is created using the temp file mechanisms so this is only really testing the behavior of the disk on which the temp files are stored.
Note: The more write operations that you request and the larger the file on which those writes are randomly distributed the more you are likely to defeat any cache mechanisms.
Results on a laptop class platform (Windows XP): write cache disabled in platform: elapsed=5063ms, mode=rwd, writesPerSec=988, bytesPerSec=1011258 elapsed=5031ms, mode=rws, writesPerSec=994, bytesPerSec=1017690 elapsed=109ms, mode=rw, writesPerSec=45872, bytesPerSec=46972477 write cache enabled in platform: elapsed=1797ms, mode=rwd, writesPerSec=2782, bytesPerSec=2849193 elapsed=1969ms, mode=rws, writesPerSec=2539, bytesPerSec=2600305 elapsed=62ms, mode=rw, writesPerSec=80645, bytesPerSec=82580645Based on the data above, you can see that merely requesting synchronous IO in Java clearly does not disable all layers of the write cache.
mode
- The file mode to be used.Stats
for that mode.IOException
Copyright © 2006–2019 SYSTAP, LLC DBA Blazegraph. All rights reserved.