This is an automated email from the ASF dual-hosted git repository.
adoroszlai 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 c54af7db18b HDDS-17563. ListMultipartUploads returns no uploads when
key-marker sorts before prefix (#11862)
c54af7db18b is described below
commit c54af7db18b292d1ac6c3db6c029784b9a9c223c
Author: Chung En Lee <[email protected]>
AuthorDate: Mon Nov 2 23:25:44 2026 +0800
HDDS-17563. ListMultipartUploads returns no uploads when key-marker sorts
before prefix (#11862)
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../hadoop/ozone/om/OmMetadataManagerImpl.java | 62 +++++++--
.../hadoop/ozone/om/TestOmMetadataManager.java | 143 +++++++++++++++++++++
2 files changed, 191 insertions(+), 14 deletions(-)
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 bdfc455b651..deb358f534f 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
@@ -17,7 +17,6 @@
package org.apache.hadoop.ozone.om;
-import static
org.apache.hadoop.hdds.StringUtils.getLexicographicallyHigherString;
import static org.apache.hadoop.ozone.OzoneConsts.DB_TRANSIENT_MARKER;
import static org.apache.hadoop.ozone.OzoneConsts.OM_DB_NAME;
import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
@@ -1626,7 +1625,11 @@ public long countLiveBuckets() throws IOException {
/**
* Get the merged and paginated list of multipart upload keys from cache and
DB.
- * Only return at most maxUploads + 1 keys (lexicographical order).
+ * Only return at most maxUploads + 1 keys, in the order of their DB keys
(/volume/bucket/key/uploadId).
+ * <p>
+ * This differs from S3, which lists uploads in the order of key names. "/"
joins the key name and the
+ * upload ID, but sorts after characters like "." and "-", so e.g. key
"a.txt" is listed before key "a".
+ * key-marker and upload-id-marker are positions in this order as well, see
below.
*/
@Override
public List<OmMultipartUpload> getMultipartUploadKeys(
@@ -1639,19 +1642,23 @@ public List<OmMultipartUpload> getMultipartUploadKeys(
String prefixKey =
OmMultipartUpload.getDbKey(volumeName, bucketName, prefix);
+ String seekKey = prefixKey;
+ boolean shouldSkip = false, hasUploadIdMarker = false;
if (StringUtils.isNotBlank(keyMarker)) {
- prefix = keyMarker;
+ // The markers are positions in the DB key order, which differs from S3:
+ // - If upload-id-marker is not specified, the uploads after the uploads
of key-marker are listed.
+ // Seek to "key-marker/" and skip the uploads of key-marker itself.
Unlike S3, keys like "a.txt" are not
+ // listed for key-marker "a", and keys like "a" are listed for
key-marker "a.txt".
+ // - If upload-id-marker is specified, the uploads after the marker
upload are listed, which include
+ // the uploads of key-marker with upload IDs lexicographically greater
than upload-id-marker, as in S3.
+ // Seek to the DB key of the markers and skip only that upload.
+ shouldSkip = true;
+ seekKey = OmMultipartUpload.getDbKey(volumeName, bucketName, keyMarker)
+ OM_KEY_PREFIX;
if (StringUtils.isNotBlank(uploadIdMarker)) {
- prefix = prefix + OM_KEY_PREFIX + uploadIdMarker;
+ seekKey = OmMultipartUpload.getDbKey(volumeName, bucketName,
keyMarker, uploadIdMarker);
+ hasUploadIdMarker = true;
}
- // - If upload-id-marker is not specified,
- // only the keys lexicographically greater than the specified key-marker
will be included in the list.
- // - If upload-id-marker is specified,
- // any multipart uploads for a key equal to the key-marker might also be
included,
- // provided those multipart uploads have upload IDs lexicographically
greater than the specified upload-id-marker.
- prefix = getLexicographicallyHigherString(prefix);
}
- String seekKey = OmMultipartUpload.getDbKey(volumeName, bucketName,
prefix);
Iterator<Map.Entry<CacheKey<String>, CacheValue<OmMultipartKeyInfo>>>
cacheIterator = getMultipartInfoTable().cacheIterator();
@@ -1661,10 +1668,16 @@ public List<OmMultipartUpload> getMultipartUploadKeys(
cacheIterator.next();
String cacheKey = cacheEntry.getKey().getCacheKey();
if (cacheKey.startsWith(prefixKey)) {
+ if (cacheKey.compareTo(seekKey) < 0) {
+ // Not listed, and the DB iteration below never reaches keys before
seekKey either.
+ continue;
+ }
// Check if it is marked for delete, due to abort mpu
OmMultipartKeyInfo multipartKeyInfo =
cacheEntry.getValue().getCacheValue();
- if (multipartKeyInfo != null &&
- cacheKey.compareTo(seekKey) >= 0) {
+ if (multipartKeyInfo != null) {
+ if (shouldSkip && isNotAfterMarker(cacheKey, seekKey, keyMarker,
hasUploadIdMarker)) {
+ continue;
+ }
responseKeys.put(cacheKey, multipartKeyInfo);
} else {
aborted.add(cacheKey);
@@ -1677,11 +1690,17 @@ public List<OmMultipartUpload> getMultipartUploadKeys(
// so we don't need to check if the key is started with prefixKey again
try (TableIterator<String, Table.KeyValue<String, OmMultipartKeyInfo>>
iterator = getMultipartInfoTable().iterator(prefixKey)) {
- iterator.seek(seekKey);
+ // The prefix iterator already starts at prefixKey, and key-marker may
sort before it.
+ if (seekKey.compareTo(prefixKey) > 0) {
+ iterator.seek(seekKey);
+ }
// Try to get maxUploads + 1 keys to check if the list is truncated.
while (iterator.hasNext() && (noPagination || dbKeysCount < maxUploads +
1)) {
KeyValue<String, OmMultipartKeyInfo> entry = iterator.next();
+ if (shouldSkip && isNotAfterMarker(entry.getKey(), seekKey, keyMarker,
hasUploadIdMarker)) {
+ continue;
+ }
// If it is marked for abort, skip it.
if (!aborted.contains(entry.getKey())) {
responseKeys.put(entry.getKey(), entry.getValue());
@@ -1706,6 +1725,21 @@ public List<OmMultipartUpload> getMultipartUploadKeys(
return noPagination || result.size() <= maxUploads ? result :
result.subList(0, maxUploads + 1);
}
+ /**
+ * @return true if the given multipart upload DB key is not after the
key-marker and upload-id-marker,
+ * where seekKey is the DB key of the markers.
+ */
+ private static boolean isNotAfterMarker(String multipartDbKey, String
seekKey, String keyMarker,
+ boolean hasUploadIdMarker) {
+ if (hasUploadIdMarker) {
+ // If both key-marker and upload-id-marker are specified, skip only the
marker upload itself.
+ return multipartDbKey.equals(seekKey);
+ }
+ // If only key-marker is specified, skip the uploads of key-marker itself.
+ // The DB key also contains the upload ID, so compare the key names.
+ return
OmMultipartUpload.from(multipartDbKey).getKeyName().equals(keyMarker);
+ }
+
@Override
public void storeSecret(String kerberosId, S3SecretValue secret)
throws IOException {
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 5f569448658..c203a1e56b0 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
@@ -1623,6 +1623,149 @@ public void testGetMultipartUploadKeys() throws
Exception {
assertEquals(25, noPagination.size());
}
+ @Test
+ public void testGetMultipartUploadKeysWithKeyMarkerBeforePrefix() throws
Exception {
+ String volumeName = "vol1";
+ String bucketName = "bucket1";
+ OMRequestTestUtils.addVolumeToDB(volumeName, omMetadataManager);
+ addBucketsToCache(volumeName, bucketName);
+
+ // "c-key" sorts between key-marker "a" and prefix "dir/".
+ addMultipartUpload(volumeName, bucketName, "c-key", "upload1", false);
+ addMultipartUpload(volumeName, bucketName, "dir/key1", "upload2", false);
+ addMultipartUpload(volumeName, bucketName, "dir/key2", "upload3", false);
+
+ // key-marker sorts before the prefix, so all uploads under the prefix are
after the marker.
+ List<String> keys = omMetadataManager.getMultipartUploadKeys(volumeName,
bucketName, "dir/", "a", null, 10, false)
+ .stream()
+ .map(OmMultipartUpload::getKeyName)
+ .collect(Collectors.toList());
+ assertEquals(Arrays.asList("dir/key1", "dir/key2"), keys);
+
+ keys = omMetadataManager.getMultipartUploadKeys(volumeName, bucketName,
"dir/", "a", "upload0", 10, false)
+ .stream()
+ .map(OmMultipartUpload::getKeyName)
+ .collect(Collectors.toList());
+ assertEquals(Arrays.asList("dir/key1", "dir/key2"), keys);
+ }
+
+ @Test
+ public void testGetMultipartUploadKeysWithOnlyKeyMarker() throws Exception {
+ String volumeName = "vol1";
+ String bucketName = "bucket1";
+ OMRequestTestUtils.addVolumeToDB(volumeName, omMetadataManager);
+ addBucketsToCache(volumeName, bucketName);
+
+ addMultipartUpload(volumeName, bucketName, "a", "upload1", false);
+ addMultipartUpload(volumeName, bucketName, "a/x", "upload2", false);
+ addMultipartUpload(volumeName, bucketName, "ab", "upload3", false);
+ addMultipartUpload(volumeName, bucketName, "b", "upload4", false);
+ // The cache has to skip the uploads of key-marker itself but not the keys
starting with "key-marker/" either.
+ addMultipartUpload(volumeName, bucketName, "a", "upload5", true);
+ addMultipartUpload(volumeName, bucketName, "a/y", "upload6", true);
+ addMultipartUpload(volumeName, bucketName, "a.txt", "upload7", false);
+
+ // Uploads are listed in DB key order, where "a.txt" sorts before "a"
since "." < "/".
+ List<String> keys = omMetadataManager.getMultipartUploadKeys(volumeName,
bucketName, "", null, null, 10, false)
+ .stream()
+ .map(OmMultipartUpload::getKeyName)
+ .collect(Collectors.toList());
+ assertEquals(Arrays.asList("a.txt", "a", "a", "a/x", "a/y", "ab", "b"),
keys);
+
+ // Without upload-id-marker, only uploads of key-marker itself are
skipped, not keys starting with it.
+ // "a.txt" is not listed as it sorts before key-marker "a", unlike S3.
+ keys = omMetadataManager.getMultipartUploadKeys(volumeName, bucketName,
"", "a", null, 10, false)
+ .stream()
+ .map(OmMultipartUpload::getKeyName)
+ .collect(Collectors.toList());
+ assertEquals(Arrays.asList("a/x", "a/y", "ab", "b"), keys);
+
+ // "a" is listed as it sorts after key-marker "a.txt", unlike S3.
+ keys = omMetadataManager.getMultipartUploadKeys(volumeName, bucketName,
"", "a.txt", null, 10, false)
+ .stream()
+ .map(OmMultipartUpload::getKeyName)
+ .collect(Collectors.toList());
+ assertEquals(Arrays.asList("a", "a", "a/x", "a/y", "ab", "b"), keys);
+ }
+
+ @Test
+ public void testGetMultipartUploadKeysWithUploadIdMarker() throws Exception {
+ String volumeName = "vol1";
+ String bucketName = "bucket1";
+ OMRequestTestUtils.addVolumeToDB(volumeName, omMetadataManager);
+ addBucketsToCache(volumeName, bucketName);
+
+ addMultipartUpload(volumeName, bucketName, "a", "upload1", false);
+ addMultipartUpload(volumeName, bucketName, "a", "upload12", true);
+ addMultipartUpload(volumeName, bucketName, "a", "upload2", false);
+ addMultipartUpload(volumeName, bucketName, "b", "upload3", true);
+
+ // Only the marker itself is skipped, not upload IDs starting with it.
+ List<String> afterDbMarker =
omMetadataManager.getMultipartUploadKeys(volumeName, bucketName, "", "a",
"upload1",
+ 10, false).stream()
+ .map(OmMultipartUpload::getUploadId)
+ .collect(Collectors.toList());
+ assertEquals(Arrays.asList("upload12", "upload2", "upload3"),
afterDbMarker);
+
+ List<String> afterCacheMarker =
omMetadataManager.getMultipartUploadKeys(volumeName, bucketName, "", "a",
+ "upload12", 10, false).stream()
+ .map(OmMultipartUpload::getUploadId)
+ .collect(Collectors.toList());
+ assertEquals(Arrays.asList("upload2", "upload3"), afterCacheMarker);
+ }
+
+ @Test
+ public void testGetMultipartUploadKeysPaginationListsEachUploadOnce() throws
Exception {
+ String volumeName = "vol1";
+ String bucketName = "bucket1";
+ OMRequestTestUtils.addVolumeToDB(volumeName, omMetadataManager);
+ addBucketsToCache(volumeName, bucketName);
+
+ addMultipartUpload(volumeName, bucketName, "a.txt", "upload1", false);
+ addMultipartUpload(volumeName, bucketName, "a", "upload2", true);
+ addMultipartUpload(volumeName, bucketName, "a", "upload3", false);
+ addMultipartUpload(volumeName, bucketName, "a/x", "upload4", true);
+ addMultipartUpload(volumeName, bucketName, "ab", "upload5", false);
+ addMultipartUpload(volumeName, bucketName, "b", "upload6", true);
+
+ // Page through one upload at a time with both markers taken from the last
upload of the previous page,
+ // as KeyManagerImpl does. "a" sorts after "a.txt" in DB key order, so its
uploads must still be listed
+ // after key-marker "a.txt" even though "a" < "a.txt".
+ List<String> listed = new ArrayList<>();
+ String keyMarker = null;
+ String uploadIdMarker = null;
+ // Bounded in case a broken marker keeps returning the same upload.
+ for (int i = 0; i < 10; i++) {
+ List<OmMultipartUpload> page =
omMetadataManager.getMultipartUploadKeys(volumeName, bucketName, "", keyMarker,
+ uploadIdMarker, 1, false);
+ if (page.isEmpty()) {
+ break;
+ }
+ OmMultipartUpload lastReturned = page.get(0);
+ listed.add(lastReturned.getKeyName() + "/" + lastReturned.getUploadId());
+ if (page.size() == 1) {
+ break;
+ }
+ keyMarker = lastReturned.getKeyName();
+ uploadIdMarker = lastReturned.getUploadId();
+ }
+ assertEquals(Arrays.asList("a.txt/upload1", "a/upload2", "a/upload3",
"a/x/upload4", "ab/upload5", "b/upload6"),
+ listed);
+ }
+
+ private void addMultipartUpload(String volumeName, String bucketName, String
keyName, String uploadId,
+ boolean cacheOnly) throws Exception {
+ OmKeyInfo keyInfo = OMRequestTestUtils.createOmKeyInfo(volumeName,
bucketName, keyName,
+ RatisReplicationConfig.getInstance(ONE)).build();
+ OmMultipartKeyInfo multipartKeyInfo =
OMRequestTestUtils.createOmMultipartKeyInfo(uploadId, Time.now(),
+ HddsProtos.ReplicationType.RATIS, HddsProtos.ReplicationFactor.ONE,
0L);
+ if (cacheOnly) {
+ OMRequestTestUtils.addMultipartInfoToTableCache(keyInfo,
multipartKeyInfo, 0L, omMetadataManager);
+ } else {
+ OMRequestTestUtils.addMultipartInfoToTable(false, keyInfo,
multipartKeyInfo, 0L, omMetadataManager);
+ }
+ }
+
@Test
public void testS3RevokedStsTokenTablePutAndGet() throws Exception {
// Ensure the table is initialized
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]