ivankelly commented on a change in pull request #1228: Issue #570: Move logic of unpersistedbytes to bufferedchannel URL: https://github.com/apache/bookkeeper/pull/1228#discussion_r172258386
########## File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BufferedChannel.java ########## @@ -138,6 +182,20 @@ public long forceWrite(boolean forceMetadata) throws IOException { // the force write, any flush that happens after this may or may // not be flushed long positionForceWrite = writeBufferStartPosition.get(); + /* + * since forceWrite method is not called in synchronized block, to make + * sure we are not undercounting unpersistedBytes, setting + * unpersistedBytes to the current number of bytes in writeBuffer. + * + * since we are calling fileChannel.force, bytes which are written to + * filechannel (system filecache) will be persisted to the disk. So we + * dont need to consider those bytes for setting value to + * unpersistedBytes. + * + */ + synchronized (this) { + unpersistedBytes.set(writeBuffer.readableBytes()); Review comment: unpersistedBytes is called before the force, so the unpersisted bytes here is actually just the unflushed bytes. If this is correct, then unpersistedBytes should be updated in flushInternal. It can even be done by decrementAndGet ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services