amit-jain commented on code in PR #2558:
URL: https://github.com/apache/jackrabbit-oak/pull/2558#discussion_r2434956307


##########
oak-blob-cloud/src/main/java/org/apache/jackrabbit/oak/blob/cloud/s3/S3Backend.java:
##########
@@ -516,19 +509,34 @@ public void addMetadataRecord(final InputStream input, 
final String name) throws
 
         ClassLoader contextClassLoader = 
Thread.currentThread().getContextClassLoader();
 
+        // Executor required to handle reading from the InputStream on a 
separate thread so the main upload is not blocked.
+        final ExecutorService executor = Executors.newSingleThreadExecutor();
         try {
             
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-
-            Upload upload = tmx.upload(s3ReqDecorator
-                .decorate(new PutObjectRequest(bucket, addMetaKeyPrefix(name), 
input, new ObjectMetadata())));
-            upload.waitForUploadResult();
-        } catch (InterruptedException e) {
-            LOG.error("Error in uploading", e);
-            throw new DataStoreException("Error in uploading", e);
+            // Specify `null` for the content length when you don't know the 
content length.
+            final AsyncRequestBody body = 
AsyncRequestBody.fromInputStream(input, null, executor);
+            final Upload upload = tmx.upload(uploadReq ->
+                    uploadReq.requestBody(body).
+                            putObjectRequest(
+                                    
s3ReqDecorator.decorate(PutObjectRequest.builder().bucket(bucket).key(addMetaKeyPrefix(name)).build()))
+                            .build());
+            upload.completionFuture().join();
+        } catch (Exception e) {
+            LOG.error("Exception in uploading {}", e.getMessage());
+            throw new DataStoreException("Error in uploading metadata file", 
e);
         } finally {
             if (contextClassLoader != null) {
                 
Thread.currentThread().setContextClassLoader(contextClassLoader);
             }
+            executor.shutdown();

Review Comment:
   Should preferably use 
https://github.com/apache/jackrabbit-oak/blob/trunk/oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/concurrent/ExecutorCloser.java
 here



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

Reply via email to