reddycharan 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_r172317243
 
 

 ##########
 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:
   in flushInternal call, "fileChannel.write(toWrite);" method is called. It 
just writes to the file buffer but it is not guaranteed to be persisted to the 
storage device, hence flushInternal shouldn't affect unpersistedBytes count in 
anyway. But where as in the forceWrite method we are calling fileChannel.force 
method which "forces any updates to this channel's file to be written to the 
storage device that contains it", hence here we should decrement the count of 
the bytes which are written to filechannel.
   
   in summary, way i see this is like following : unpersistedbytes = 
writeBuffer.readableBytes + bytes written to filchannel (which are not 
persisted yet by calling filechannel.force)

----------------------------------------------------------------
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

Reply via email to