Double check if stream must be flush to allow tests to make better assumptions of what is visible and what isn't after tragic events

This commit is contained in:
Simon Willnauer 2016-01-05 17:58:20 +01:00
parent ea6718d878
commit dff30ece05

View File

@ -266,7 +266,13 @@ public class TranslogWriter extends TranslogReader {
protected void readBytes(ByteBuffer targetBuffer, long position) throws IOException {
if (position+targetBuffer.remaining() > getWrittenOffset()) {
synchronized (this) {
outputStream.flush();
// we only flush here if it's really really needed - try to minimize the impact of the read operation
// in some cases ie. a tragic event we might still be able to read the relevant value
// which is not really important in production but some test can make most strict assumptions
// if we don't fail in this call unless absolutely necessary.
if (position+targetBuffer.remaining() > getWrittenOffset()) {
outputStream.flush();
}
}
}
// we don't have to have a lock here because we only write ahead to the file, so all writes has been complete