This is an automated email from the ASF dual-hosted git repository.

peterxcli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new baeceb96ae0 HDDS-17251. List open multipart uploads in ListOpenFiles 
(#11739)
baeceb96ae0 is described below

commit baeceb96ae0090834e853acaf716f4036d962b0b
Author: Alex Lin <[email protected]>
AuthorDate: Sun Oct 25 11:54:27 2026 +0800

    HDDS-17251. List open multipart uploads in ListOpenFiles (#11739)
---
 .../hadoop/ozone/om/OmMetadataManagerImpl.java     |  5 +-
 .../hadoop/ozone/om/TestOmMetadataManager.java     | 56 ++++++++++++++++++++++
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
index a724de39ec6..e59945f249b 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataManagerImpl.java
@@ -1051,7 +1051,10 @@ public ListOpenFilesResult listOpenFiles(BucketLayout 
bucketLayout,
         kv = openKeyIter.next();
         if (kv != null && kv.getKey().startsWith(dbOpenKeyPrefix)) {
           String dbKey = kv.getKey();
-          long clientID = OMMetadataManager.getClientIDFromOpenKeyDBKey(dbKey);
+          // The open key of a multipart upload ends with the upload ID and 
has no client ID, so it is listed with
+          // client ID 0, which no real client has
+          final boolean isUpload = 
OMMultipartUploadUtils.getUploadIdFromDbKey(dbKey) != null;
+          long clientID = isUpload ? 0 : 
OMMetadataManager.getClientIDFromOpenKeyDBKey(dbKey);
           OmKeyInfo omKeyInfo = kv.getValue();
           // Note with HDDS-10077, there is no need to check KeyTable for 
hsync metadata
           openKeySessionList.add(
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmMetadataManager.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmMetadataManager.java
index c284b460dd6..322948ffbcd 100644
--- 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmMetadataManager.java
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/TestOmMetadataManager.java
@@ -53,6 +53,7 @@
 import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.BUCKET_NOT_FOUND;
 import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.VOLUME_NOT_FOUND;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotEquals;
@@ -791,6 +792,61 @@ public void testListOpenFiles(BucketLayout bucketLayout) 
throws Exception {
     }
   }
 
+  /**
+   * The open key of a multipart upload ends with the upload ID, not a client 
ID.
+   * listOpenFiles lists it with client ID 0 next to the other open keys, 
whether or not it carries the
+   * isMultipartKey flag (rows written before HDDS-9017 do not), while the 
open key of a part being written,
+   * which has the flag, keeps its client ID.
+   */
+  @ParameterizedTest
+  @EnumSource
+  public void testListOpenFilesWithMultipartUpload(BucketLayout bucketLayout) 
throws Exception {
+    final long clientID = 1000L;
+    final long partClientID = 2000L;
+    String volumeName = "volume-lof-mpu";
+    String bucketName = "bucket-" + bucketLayout.name().toLowerCase();
+    OMRequestTestUtils.addVolumeAndBucketToDB(volumeName, bucketName, 
omMetadataManager, bucketLayout);
+
+    OmKeyInfo openKey = OMRequestTestUtils.createOmKeyInfo(volumeName, 
bucketName, "key0",
+        RatisReplicationConfig.getInstance(ONE)).build();
+    OmKeyInfo uploadKey = OMRequestTestUtils.createOmKeyInfo(volumeName, 
bucketName, "key1",
+        RatisReplicationConfig.getInstance(ONE)).build();
+    OmKeyInfo partKey = OMRequestTestUtils.createOmKeyInfo(volumeName, 
bucketName, "key1",
+        RatisReplicationConfig.getInstance(ONE), new 
OmKeyLocationInfoGroup(0L, new ArrayList<>(), true)).build();
+    String uploadId = OMMultipartUploadUtils.getMultipartUploadId();
+    String dbPrefix;
+    if (bucketLayout.isFileSystemOptimized()) {
+      OMRequestTestUtils.addFileToKeyTable(true, false, openKey.getFileName(), 
openKey, clientID, 0L,
+          omMetadataManager);
+      OMRequestTestUtils.addMultipartKeyToOpenFileTable(false, 
uploadKey.getFileName(), uploadKey, uploadId, 0L,
+          omMetadataManager);
+      OMRequestTestUtils.addFileToKeyTable(true, false, partKey.getFileName(), 
partKey, partClientID, 0L,
+          omMetadataManager);
+      dbPrefix = omMetadataManager.getOzoneKeyFSO(volumeName, bucketName, "");
+    } else {
+      OMRequestTestUtils.addKeyToTable(true, false, openKey, clientID, 0L, 
omMetadataManager);
+      OMRequestTestUtils.addMultipartKeyToOpenKeyTable(false, uploadKey, 
uploadId, 0L, omMetadataManager);
+      OMRequestTestUtils.addKeyToTable(true, false, partKey, partClientID, 0L, 
omMetadataManager);
+      dbPrefix = omMetadataManager.getOzoneKey(volumeName, bucketName, "");
+    }
+
+    ListOpenFilesResult res = omMetadataManager.listOpenFiles(bucketLayout, 
100, dbPrefix, false, dbPrefix);
+    assertThat(res.getTotalOpenKeyCount()).isEqualTo(3);
+    assertThat(res.hasMore()).isFalse();
+    assertThat(res.getOpenKeys())
+        .extracting(s -> s.getKeyInfo().getKeyName(), OpenKeySession::getId)
+        .containsExactlyInAnyOrder(tuple("key0", clientID), tuple("key1", 
partClientID), tuple("key1", 0L));
+
+    // Page through it: the continuation token of the first page is the open 
key before the upload
+    res = omMetadataManager.listOpenFiles(bucketLayout, 1, dbPrefix, false, 
dbPrefix);
+    assertThat(res.hasMore()).isTrue();
+    res = omMetadataManager.listOpenFiles(bucketLayout, 2, dbPrefix, true, 
res.getContinuationToken());
+    assertThat(res.hasMore()).isFalse();
+    assertThat(res.getOpenKeys())
+        .extracting(s -> s.getKeyInfo().getKeyName(), OpenKeySession::getId)
+        .containsExactlyInAnyOrder(tuple("key1", partClientID), tuple("key1", 
0L));
+  }
+
   private static BucketLayout getDefaultBucketLayout() {
     return BucketLayout.DEFAULT;
   }


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

Reply via email to