Akshat-Jain commented on code in PR #16481:
URL: https://github.com/apache/druid/pull/16481#discussion_r1618175763


##########
extensions-core/s3-extensions/src/main/java/org/apache/druid/storage/s3/output/RetryableS3OutputStream.java:
##########
@@ -199,15 +221,44 @@ private void pushCurrentChunk() throws IOException
   {
     currentChunk.close();
     final Chunk chunk = currentChunk;
-    try {
-      if (chunk.length() > 0) {
-        resultsSize += chunk.length();
+    if (chunk.length() > 0) {
+      uploadManager.incrementCurrentNumChunks();
+      pendingFiles.incrementAndGet();
 
-        pushStopwatch.start();
-        pushResults.add(push(chunk));
-        pushStopwatch.stop();
-        numChunksPushed++;
+      uploadManager.submitTask(() -> {
+        try {
+          uploadChunk(chunk);
+        }
+        catch (Exception e) {
+          error = true;
+          LOG.error(e, e.getMessage());
+          throw new RuntimeException(e);
+        }
+        finally {
+          synchronized (maxChunksLock) {
+            uploadManager.decrementCurrentNumChunks();
+            maxChunksLock.notifyAll();
+          }
+          if (pendingFiles.decrementAndGet() == 0) {
+            synchronized (fileLock) {
+              fileLock.notifyAll();
+            }
+          }
+        }
+      });
+    }
+  }

Review Comment:
   Or maybe exposing a method like this in S3UploadManager?
   ```java
   public boolean canWriteMoreChunksOnDisk()
     {
       synchronized (maxChunksLock) {
         while (uploadManager.getCurrentNumChunksOnDisk() > 
uploadManager.getMaxConcurrentNumChunks()) {
           try {
             LOG.debug("Waiting for lock for writing further chunks to local 
disk.");
             maxChunksLock.wait();
           }
           catch (InterruptedException e) {
             Thread.currentThread().interrupt();
             throw new RuntimeException(e);
           }
         }
       }
     }
   ```
   
   And replacing the above code in RetryableS3OutputStream with 
`canWriteMoreChunksOnDisk()` 🤔 



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

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to