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

 ##########
 File path: 
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BufferedChannel.java
 ##########
 @@ -70,28 +96,42 @@ public void close() throws IOException {
      * @param src The source ByteBuffer which contains the data to be written.
      * @throws IOException if a write operation fails.
      */
-    public synchronized void write(ByteBuf src) throws IOException {
+    public void write(ByteBuf src) throws IOException {
         int copied = 0;
-        int len = src.readableBytes();
-        while (copied < len) {
-            int bytesToCopy = Math.min(src.readableBytes() - copied, 
writeBuffer.writableBytes());
-            writeBuffer.writeBytes(src, src.readerIndex() + copied, 
bytesToCopy);
-            copied += bytesToCopy;
-
-            // if we have run out of buffer space, we should flush to the file
-            if (!writeBuffer.isWritable()) {
-                flushInternal();
+        boolean shouldForceWrite = false;
+        synchronized (this) {
+            int len = src.readableBytes();
+            while (copied < len) {
+                int bytesToCopy = Math.min(src.readableBytes() - copied, 
writeBuffer.writableBytes());
+                writeBuffer.writeBytes(src, src.readerIndex() + copied, 
bytesToCopy);
+                copied += bytesToCopy;
+
+                // if we have run out of buffer space, we should flush to the
+                // file
+                if (!writeBuffer.isWritable()) {
+                    flushInternal();
+                }
+            }
+            position.addAndGet(copied);
+            unpersistedBytes.addAndGet(copied);
 
 Review comment:
   Why do we need `AtomicInteger` if this is incremented withing a synchronized 
block?

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to