Skip to content

Commit

Permalink
Double check if stream must be flush to allow tests to make better as…
Browse files Browse the repository at this point in the history
…sumptions of what is visible and what isn't after tragic events
  • Loading branch information
s1monw committed Jan 5, 2016
1 parent ea6718d commit dff30ec
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,13 @@ public boolean syncUpTo(long offset) throws IOException {
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
Expand Down

0 comments on commit dff30ec

Please sign in to comment.