xiangfu0 commented on code in PR #17806:
URL: https://github.com/apache/pinot/pull/17806#discussion_r2898430442


##########
pinot-plugins/pinot-file-system/pinot-adls/src/main/java/org/apache/pinot/plugin/filesystem/ADLSGen2PinotFS.java:
##########
@@ -637,42 +674,134 @@ private boolean copySrcToDst(URI srcUri, URI dstUri)
     PathProperties pathProperties =
         
_fileSystemClient.getFileClient(AzurePinotFSUtil.convertUriToAzureStylePath(srcUri)).getProperties();
     try (InputStream inputStream = open(srcUri)) {
-      return copyInputStreamToDst(inputStream, dstUri, 
pathProperties.getContentMd5());
+      return copyInputStreamToDst(inputStream, dstUri, 
pathProperties.getContentMd5(),
+          pathProperties.getFileSize());
     }
   }
 
   /**
    * Helper function to copy input stream to destination URI.
    *
+   * <p>Uses the Azure Blob API for uploads, which is compatible with storage 
accounts that have Blob Soft Delete
+   * enabled. The DFS (Data Lake) API does not support Soft Delete and will 
fail with 409
+   * EndpointUnsupportedAccountFeatures on such accounts.</p>
+   *
    * NOTE: the caller has to close the input stream.
    *
    * @param inputStream input stream that will be written to dstUri
    * @param dstUri destination URI
+   * @param contentMd5 optional MD5 hash of the content
+   * @param contentLength length of the content in bytes
    * @return true if the copy succeeds
    */
-  private boolean copyInputStreamToDst(InputStream inputStream, URI dstUri, 
byte[] contentMd5)
+  private boolean copyInputStreamToDst(InputStream inputStream, URI dstUri, 
byte[] contentMd5, long contentLength)
+      throws IOException {
+    String path = AzurePinotFSUtil.convertUriToAzureStylePath(dstUri);
+
+    if (_blobContainerClient != null) {
+      return copyInputStreamToDstViaBlob(inputStream, dstUri, path, 
contentMd5, contentLength);
+    }
+    return copyInputStreamToDstViaDfs(inputStream, dstUri, path, contentMd5);
+  }
+
+  /**
+   * Upload via Azure Blob API. Compatible with Blob Soft Delete.
+   */
+  private boolean copyInputStreamToDstViaBlob(InputStream inputStream, URI 
dstUri, String path, byte[] contentMd5,
+      long contentLength)
+      throws IOException {
+    try {
+      BlobClient blobClient = _blobContainerClient.getBlobClient(path);
+      BlobHttpHeaders blobHttpHeaders = contentMd5 != null ? 
getBlobHttpHeadersWithContentMd5(blobClient, contentMd5)
+          : null;
+      if (_enableChecksum) {
+        uploadWithBlockLevelChecksum(blobClient.getBlockBlobClient(), 
inputStream, blobHttpHeaders);
+      } else if (blobHttpHeaders != null) {
+        blobClient.uploadWithResponse(inputStream, contentLength, null, 
blobHttpHeaders, null, null, null, null,
+            Context.NONE);
+      } else {
+        blobClient.upload(inputStream, contentLength, true);
+      }
+      return true;
+    } catch (BlobStorageException e) {
+      LOGGER.error("Exception thrown while uploading to destination via Blob 
API (dstUri={}, errorStatus={})", dstUri,
+          e.getStatusCode(), e);
+      throw new IOException(e);

Review Comment:
   `uploadWithResponse` here does not pass `overwrite=true`. The 8th positional 
parameter (`BlobRequestConditions`) is `null`, which means Azure defaults to 
**no overwrite** (it sets an implicit `If-None-Match: *` condition).
   
   However, the `else` branch on line 731 calls `blobClient.upload(inputStream, 
contentLength, true)` with `overwrite=true`, and the DFS fallback path 
explicitly handles `PathAlreadyExists` by re-creating the file with 
`overwrite=true`.
   
   This means: when `contentMd5 != null` but `_enableChecksum` is `false` 
(i.e., the `copySrcToDst` path where the source blob happens to have MD5 
metadata), uploading to an **existing** blob path will fail with a 409 conflict.
   
   Suggested fix — restructure to eliminate the three-way branch:
   ```java
   if (_enableChecksum) {
       uploadWithBlockLevelChecksum(blobClient.getBlockBlobClient(), 
inputStream, blobHttpHeaders);
   } else {
       blobClient.upload(inputStream, contentLength, null, blobHttpHeaders, 
null, null, null, true, null, null, Context.NONE);
   }
   ```
   This handles both the `contentMd5 != null` and `contentMd5 == null` cases 
uniformly with overwrite enabled.



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