You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "Gargi-jais11 (via GitHub)" <gi...@apache.org> on 2026/06/30 09:02:38 UTC

[PR] HDDS-15616. ListBuckets API ignores MaxBuckets parameter and returns all buckets [ozone]

Gargi-jais11 opened a new pull request, #10639:
URL: https://github.com/apache/ozone/pull/10639

   ## What changes were proposed in this pull request?
   S3 test test_list_buckets_paginated is failing today as ListBuckets pagination using MaxBuckets and ContinuationToken on GET / (ListAllMyBuckets) is not supported. 
   
   creates 2 buckets and calls list_buckets(MaxBuckets=1).
   
   **Expected:** 1 bucket per page + ContinuationToken when more exist.
   **Ozone:** Ignores MaxBuckets and returns both buckets → assert len == 1 fails with 2.
   
   Simple example:
    
    ```
    Buckets: [bucket-A, bucket-B]
    Client: list_buckets(MaxBuckets=1) 
   
    AWS: { Buckets: [bucket-A], ContinuationToken: "..." }
    Ozone: { Buckets: [bucket-A, bucket-B] } ← 2 items, no token 
   ```
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-15616
   
   ## How was this patch tested?
   
   Added UT and IT.
   Also tested manually.
   **Before Fix:**
   ```
   // no continuation token is given and send all the buckets stored.
   bash-5.1$ aws s3api list-buckets --max-buckets 1 --endpoint-url http://s3g:9878 --output json
   {
       "Buckets": [
           {
               "Name": "buck1",
               "CreationDate": "2026-06-30T07:04:27.544Z"
           },
           {
               "Name": "buck2",              -----------------------------> wrong behaviour
               "CreationDate": "2026-06-30T07:04:30.460Z"
           },
           {
               "Name": "buck3",       -----------------------------> wrong behaviour
               "CreationDate": "2026-06-30T07:04:35.556Z"
           },
           {
               "Name": "buck4",           -----------------------------> wrong behaviour
               "CreationDate": "2026-06-30T07:04:40.205Z"
           },
           {
               "Name": "buck5",        -----------------------------> wrong behaviour
               "CreationDate": "2026-06-30T07:04:43.890Z"
           }
       ],
       "Owner": {
           "DisplayName": "om",
           "ID": "bb2bd7ca4a327f84e6cd3979f8fa3828a50a08893c1b68f9d6715352c8d07b93"
       }
   }
   ```
   
   **After Fix:**
   ```
   bash-5.1$ aws s3api list-buckets --max-buckets 1 --endpoint-url http://s3g:9878/ --output json
   {
       "Buckets": [
           {
               "Name": "buck1",
               "CreationDate": "2026-06-23T08:51:13.848Z"
           }
       ],
       "Owner": {
           "DisplayName": "om",
           "ID": "bb2bd7ca4a327f84e6cd3979f8fa3828a50a08893c1b68f9d6715352c8d07b93"
       },
       "ContinuationToken": "000000056275636b31-f239795a4c8be1e364face563bdc554b5559cbc1978becf3086b5079c2c44850"
   }
   
   bash-5.1$ aws s3api list-buckets --max-buckets 2 --endpoint-url http://s3g:9878/ --output json
   {
       "Buckets": [
           {
               "Name": "buck1",
               "CreationDate": "2026-06-23T08:51:13.848Z"
           },
           {
               "Name": "buck2",
               "CreationDate": "2026-06-23T08:51:16.495Z"
           }
       ],
       "Owner": {
           "DisplayName": "om",
           "ID": "bb2bd7ca4a327f84e6cd3979f8fa3828a50a08893c1b68f9d6715352c8d07b93"
       }
   }
   
   bash-5.1$ ozone sh bucket create /s3v/buck3
   bash-5.1$ aws s3api list-buckets --max-buckets 2 --endpoint-url http://s3g:9878/ --output json
   {
       "Buckets": [
           {
               "Name": "buck1",
               "CreationDate": "2026-06-23T08:51:13.848Z"
           },
           {
               "Name": "buck2",
               "CreationDate": "2026-06-23T08:51:16.495Z"
           }
       ],
       "Owner": {
           "DisplayName": "om",
           "ID": "bb2bd7ca4a327f84e6cd3979f8fa3828a50a08893c1b68f9d6715352c8d07b93"
       },
       "ContinuationToken": "000000056275636b32-0880ee15253ee89c74cbc13b73c026a3ecd9529d0682e4d61e85dde392eb3ed3"
   }
   
   bash-5.1$ aws s3api list-buckets --max-buckets 1 --continuation-token 000000056275636b32-0880ee15253ee89c74cbc13b73c026a3ecd9529d0682e4d61e85dde392eb3ed3 \
       --endpoint-url http://s3g:9878/ --output json
   {
       "Buckets": [
           {
               "Name": "buck3",
               "CreationDate": "2026-06-23T08:52:25.003Z"
           }
       ],
       "Owner": {
           "DisplayName": "om",
           "ID": "bb2bd7ca4a327f84e6cd3979f8fa3828a50a08893c1b68f9d6715352c8d07b93"
       }
   }
   bash-5.1$ aws s3api list-buckets --max-buckets 2 --endpoint-url http://s3g:9878/
   {
       "Buckets": [
           {
               "Name": "buck1",
               "CreationDate": "2026-06-23T08:51:13.848Z"
           },
           {
               "Name": "buck2",
               "CreationDate": "2026-06-23T08:51:16.495Z"
           }
       ],
       "Owner": {
           "DisplayName": "om",
           "ID": "bb2bd7ca4a327f84e6cd3979f8fa3828a50a08893c1b68f9d6715352c8d07b93"
       },
       "ContinuationToken": "000000056275636b32-0880ee15253ee89c74cbc13b73c026a3ecd9529d0682e4d61e85dde392eb3ed3"
   }
   ```
   


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-15616. ListBuckets API ignores MaxBuckets parameter and returns all buckets [ozone]

Posted by "ayushtkn (via GitHub)" <gi...@apache.org>.
ayushtkn commented on code in PR #10639:
URL: https://github.com/apache/ozone/pull/10639#discussion_r3503385706


##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/RootEndpoint.java:
##########
@@ -153,22 +153,49 @@ private Response listAllBuckets()
     long startNanos = Time.monotonicNowNanos();
     boolean auditSuccess = true;
     try {
+      final String continueToken = queryParams().get(QueryParams.CONTINUATION_TOKEN);
+      final String maxBucketsParam = queryParams().get(QueryParams.MAX_BUCKETS);
+      final boolean paginated = maxBucketsParam != null || continueToken != null;
+      final int maxBuckets = paginated
+          ? validateMaxBuckets(queryParams().getInt(QueryParams.MAX_BUCKETS,
+              S3Consts.MAX_BUCKETS_LIMIT))
+          : Integer.MAX_VALUE;

Review Comment:
   can we not do this logic inside the method itself `validateMaxBuckets`, actually this isn't validate, it is like `getMaxBuckets`, because it does
   ```
    return Math.min(maxBuckets, S3Consts.MAX_BUCKETS_LIMIT);
   ```
   Maybe we can drop the ternary here and do all this logic inside the method



##########
hadoop-ozone/s3gateway/src/test/java/org/apache/hadoop/ozone/s3/endpoint/TestRootList.java:
##########
@@ -68,4 +73,95 @@ public void testListBucket() throws Exception {
     assertEquals(S3Owner.DEFAULT_S3OWNER_ID, response.getOwner().getId());
   }
 
+  @Test
+  public void testListAllBucketsPaginated() throws Exception {
+    ListBucketResponse response = listWithMaxBuckets(1);
+    assertEquals(0, response.getBucketsNum());
+    assertNull(response.getContinuationToken());
+
+    clientStub.getObjectStore().createS3Bucket("bucket-a");
+    response = listWithMaxBuckets(1);
+    assertEquals(1, response.getBucketsNum());
+    assertEquals("bucket-a", response.getBuckets().get(0).getName());
+    assertNull(response.getContinuationToken());
+
+    clientStub.getObjectStore().createS3Bucket("bucket-b");
+    response = listWithMaxBuckets(1);
+    assertEquals(1, response.getBucketsNum());
+    assertEquals("bucket-a", response.getBuckets().get(0).getName());
+    assertNotNull(response.getContinuationToken());
+
+    rootEndpoint.queryParamsForTest().set(QueryParams.CONTINUATION_TOKEN,
+        response.getContinuationToken());
+    rootEndpoint.queryParamsForTest().setInt(QueryParams.MAX_BUCKETS, 1);
+    response = (ListBucketResponse) rootEndpoint.get().getEntity();
+    assertEquals(1, response.getBucketsNum());
+    assertEquals("bucket-b", response.getBuckets().get(0).getName());
+    assertNull(response.getContinuationToken());
+  }
+
+  @Test
+  public void testListAllBucketsPaginationMultiplePages() throws Exception {
+    String bucketBaseName = "bucket-" + getClass().getName();
+    for (int i = 0; i < 5; i++) {
+      clientStub.getObjectStore().createS3Bucket(bucketBaseName + i);
+    }
+
+    rootEndpoint.queryParamsForTest().setInt(QueryParams.MAX_BUCKETS, 2);

Review Comment:
   could the `listWithMaxBuckets` be used here? 



##########
hadoop-ozone/integration-test-s3/src/test/java/org/apache/hadoop/ozone/s3/awssdk/v1/AbstractS3SDKV1Tests.java:
##########
@@ -286,6 +288,144 @@ public void testListBuckets() throws IOException {
     assertThat(s3AccountOwner.getId()).isEqualTo(S3Owner.DEFAULT_S3OWNER_ID);
   }
 
+  /**
+   * Integration tests for paginated ListBuckets (GET / ListAllMyBuckets).
+   */
+  @Nested
+  class ListBucketsPaginationTests {
+
+    /**
+     * Verifies {@code maxBuckets=1} returns one bucket per page and a continuation token
+     * when more buckets exist.
+     */
+    @Test
+    public void testListBucketsPaginatedMaxBucketsOne() {
+      final String bucketA = uniqueObjectName("bucket-a");
+      final String bucketB = uniqueObjectName("bucket-b");
+      s3Client.createBucket(bucketA);
+      s3Client.createBucket(bucketB);
+      try {
+        List<String> found = new ArrayList<>();
+        String continuationToken = null;
+
+        do {
+          ListBucketsPaginatedRequest request = new ListBucketsPaginatedRequest()
+              .withMaxBuckets(1);
+          if (continuationToken != null) {
+            request.withContinuationToken(continuationToken);
+          }
+
+          ListBucketsPaginatedResult page = s3Client.listBuckets(request);
+          assertEquals(1, page.getBuckets().size());
+          found.add(page.getBuckets().get(0).getName());
+          continuationToken = page.getContinuationToken();
+        } while (continuationToken != null
+            && !(found.contains(bucketA) && found.contains(bucketB)));

Review Comment:
   the second condition is unnecessary, pagination should naturally terminate when there are no elements remaining.
   
   We can maybe assert that it returns exactly 2 elements which are `bucketA` & `bucketB` 



##########
hadoop-ozone/integration-test-s3/src/test/java/org/apache/hadoop/ozone/s3/awssdk/v2/AbstractS3SDKV2Tests.java:
##########
@@ -2796,6 +2797,144 @@ private void verifyBucketOwnershipVerificationAccessDenied(Executable function)
     }
   }
 
+  /**
+   * Integration tests for paginated ListBuckets (GET / ListAllMyBuckets).
+   */
+  @Nested
+  class ListBucketsPaginationTests {
+
+    /**
+     * Verifies {@code maxBuckets=1} returns one bucket per page and a continuation token
+     * when more buckets exist.
+     */
+    @Test
+    public void testListBucketsPaginatedMaxBucketsOne() throws Exception {

Review Comment:
   is this a almost a copy from the V1 test, we should ideally refactor to make sure we are not having the same code both places.
   
   unless that is some established practice for the particular case



##########
hadoop-ozone/integration-test-s3/src/test/java/org/apache/hadoop/ozone/s3/awssdk/v1/AbstractS3SDKV1Tests.java:
##########
@@ -286,6 +288,144 @@ public void testListBuckets() throws IOException {
     assertThat(s3AccountOwner.getId()).isEqualTo(S3Owner.DEFAULT_S3OWNER_ID);
   }
 
+  /**
+   * Integration tests for paginated ListBuckets (GET / ListAllMyBuckets).
+   */
+  @Nested
+  class ListBucketsPaginationTests {
+
+    /**
+     * Verifies {@code maxBuckets=1} returns one bucket per page and a continuation token
+     * when more buckets exist.
+     */
+    @Test
+    public void testListBucketsPaginatedMaxBucketsOne() {
+      final String bucketA = uniqueObjectName("bucket-a");
+      final String bucketB = uniqueObjectName("bucket-b");
+      s3Client.createBucket(bucketA);
+      s3Client.createBucket(bucketB);
+      try {
+        List<String> found = new ArrayList<>();
+        String continuationToken = null;
+
+        do {
+          ListBucketsPaginatedRequest request = new ListBucketsPaginatedRequest()
+              .withMaxBuckets(1);
+          if (continuationToken != null) {
+            request.withContinuationToken(continuationToken);
+          }
+
+          ListBucketsPaginatedResult page = s3Client.listBuckets(request);
+          assertEquals(1, page.getBuckets().size());
+          found.add(page.getBuckets().get(0).getName());
+          continuationToken = page.getContinuationToken();
+        } while (continuationToken != null
+            && !(found.contains(bucketA) && found.contains(bucketB)));
+
+        assertThat(found).contains(bucketA, bucketB);

Review Comment:
    maybe         `assertThat(found).containsExactlyInAnyOrder(bucketA, bucketB);`



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-15616. ListBuckets API ignores MaxBuckets parameter and returns all buckets [ozone]

Posted by "Gargi-jais11 (via GitHub)" <gi...@apache.org>.
Gargi-jais11 commented on PR #10639:
URL: https://github.com/apache/ozone/pull/10639#issuecomment-4967219226

   Thanks @ayushtkn @chungen0126 @rich7420 for reviewing the patch.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-15616. ListBuckets API ignores MaxBuckets parameter and returns all buckets [ozone]

Posted by "Gargi-jais11 (via GitHub)" <gi...@apache.org>.
Gargi-jais11 merged PR #10639:
URL: https://github.com/apache/ozone/pull/10639


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org