reschke commented on code in PR #2561:
URL: https://github.com/apache/jackrabbit-oak/pull/2561#discussion_r2410106352


##########
oak-blob-cloud-azure/src/main/java/org/apache/jackrabbit/oak/blob/cloud/azure/blobstorage/AzureBlobStoreBackend.java:
##########
@@ -500,13 +503,72 @@ private BlockBlobClient getMetaBlobClient(String name) 
throws DataStoreException
     private void addMetadataRecordImpl(final InputStream input, String name, 
long recordLength) throws DataStoreException {
         try {
             BlockBlobClient blockBlobClient = getMetaBlobClient(name);
-            blockBlobClient.upload(BinaryData.fromBytes(input.readAllBytes()), 
true);
+
+            // If length is unknown (-1), use a file buffer for the stream 
first
+            // This is necessary because Azure SDK requires a known length for 
upload
+            // and loading the entire stream into memory is too risky
+            if (recordLength < 0) {
+                LOG.debug("Metadata record length unknown. metadataName={}. 
Saving to temporary file before upload", name);
+                File tempFile = createTempFileFromStream(input, name, ".tmp");
+                LOG.debug("Metadata record temporary file created. 
metadataName={} path={}", name, tempFile.getAbsolutePath());
+                try (InputStream fis = new BufferedInputStream(new 
FileInputStream(tempFile))) {
+                    blockBlobClient.upload(fis, tempFile.length(), true);
+                } finally {
+                    tempFile.delete();
+                }
+            } else {
+                LOG.debug("Metadata record length known: {} bytes. 
metadataName={}. Uploading directly", recordLength, name);
+                InputStream markableInput = input.markSupported() ? input : 
new BufferedInputStream(input);

Review Comment:
   How is support for mark relevant for buffering?



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