smengcl commented on code in PR #6859:
URL: https://github.com/apache/ozone/pull/6859#discussion_r1676443718


##########
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/BlockOutputStream.java:
##########
@@ -377,30 +399,35 @@ public void writeOnRetry(long len) throws IOException {
     if (LOG.isDebugEnabled()) {
       LOG.debug("Retrying write length {} for blockID {}", len, blockID);
     }
-    Preconditions.checkArgument(len <= 
streamBufferArgs.getStreamBufferMaxSize());
-    int count = 0;
-    while (len > 0) {
-      ChunkBuffer buffer = bufferPool.getBuffer(count);
-      long writeLen = Math.min(buffer.position(), len);
-      if (!buffer.hasRemaining()) {
-        writeChunk(buffer);
-      }
-      len -= writeLen;
-      count++;
-      writtenDataLength += writeLen;
-      // we should not call isBufferFull/shouldFlush here.
-      // The buffer might already be full as whole data is already cached in
-      // the buffer. We should just validate
-      // if we wrote data of size streamBufferMaxSize/streamBufferFlushSize to
-      // call for handling full buffer/flush buffer condition.
-      if (writtenDataLength % streamBufferArgs.getStreamBufferFlushSize() == 
0) {
-        // reset the position to zero as now we will be reading the
-        // next buffer in the list
-        updateFlushLength();
-        executePutBlock(false, false);
-      }
-      if (writtenDataLength == streamBufferArgs.getStreamBufferMaxSize()) {
-        handleFullBuffer();
+    synchronized (this) {
+      Preconditions.checkArgument(len <= 
streamBufferArgs.getStreamBufferMaxSize());
+      int count = 0;
+      List<ChunkBuffer> allocatedBuffers = bufferPool.getAllocatedBuffers();
+      while (len > 0) {
+        ChunkBuffer buffer = allocatedBuffers.get(count);
+        long writeLen = Math.min(buffer.position(), len);
+        if (!buffer.hasRemaining()) {
+          writeChunk(buffer);
+        }
+        len -= writeLen;
+        count++;
+        writtenDataLength += writeLen;
+        // we should not call isBufferFull/shouldFlush here.
+        // The buffer might already be full as whole data is already cached in
+        // the buffer. We should just validate
+        // if we wrote data of size streamBufferMaxSize/streamBufferFlushSize 
to
+        // call for handling full buffer/flush buffer condition.
+        if (writtenDataLength % streamBufferArgs.getStreamBufferFlushSize() == 
0) {
+          // reset the position to zero as now we will be reading the
+          // next buffer in the list
+          updateSyncedLength();
+          updateFlushedLength();
+          CompletableFuture<PutBlockResult> putBlockResultFuture = 
executePutBlock(false, false);
+          lastFlushFuture = watchForCommitAsync(putBlockResultFuture);
+        }
+        if (writtenDataLength == streamBufferArgs.getStreamBufferMaxSize()) {
+          handleFullBuffer();
+        }

Review Comment:
   For cleaniness sake we could extract this chunk to a new `synchronized` 
method called `writeOnRetryInternal`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org
For additional commands, e-mail: issues-h...@ozone.apache.org

Reply via email to