Skip to content

Conversation

@Jimmyweng006
Copy link
Contributor

@Jimmyweng006 Jimmyweng006 commented Jul 20, 2025

What changes were proposed in this pull request?

[S3G] ListObjectsV2 should accept maxKeys=0

Please describe your PR in detail:

  • Optimized Key Processing: In BucketEndpoint.java, a check if (maxKeys > 0) is introduced to wrap the key processing loop. This avoids unnecessary iteration and immediately returns an empty result, improving efficiency for this specific use case.
  • Corrected Validation: The validation logic is adjusted to only reject negative values for max-keys, while correctly permitting 0.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/HDDS-13447

How was this patch tested?

CI Pass

@Jimmyweng006 Jimmyweng006 marked this pull request as draft July 20, 2025 06:19
@ivandika3 ivandika3 added the s3 S3 Gateway label Jul 20, 2025
Copy link
Contributor

@jojochuang jojochuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost good to one. There's one potential corner case

}
String lastKey = null;
int count = 0;
while (ozoneKeyIterator != null && ozoneKeyIterator.hasNext()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get() mthod is too long, containing unrelated code pieces. Suggest to refactor it into multiple smaller helper methods in a follow up task.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

response.addPrefix(EncodingTypeObject.createNullable(
prefix + dirName + delimiter, encodingType));
prevDir = dirName;
if (maxKeys > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

potential bug:

If maxKeys = 0, it does not enter this if statement. Later, lastKey would still be null. If the bucket is not emtpy, and key iterator has next item, this line looks problematic:

      ContinueToken nextToken = new ContinueToken(lastKey, prevDir);
      response.setNextToken(nextToken.encodeToString());

@jojochuang
Copy link
Contributor

@Jimmyweng006 would you like to take another look? Or would you be ok if I push the proposed fix in?

@Jimmyweng006
Copy link
Contributor Author

Hi @jojochuang , sorry that I haven’t been able to focus on this issue recently. Please feel free to go ahead and push the commit. Thanks!

@peterxcli peterxcli marked this pull request as ready for review August 1, 2025 06:16
Copy link
Member

@peterxcli peterxcli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jojochuang I have handled the case you indicated, please take another look. Thanks.

}
String lastKey = null;
int count = 0;
while (ozoneKeyIterator != null && ozoneKeyIterator.hasNext()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@Jimmyweng006
Copy link
Contributor Author

Thanks @peterxcli for helping on this PR. After re-run all CI pass.

@peterxcli peterxcli requested a review from jojochuang August 1, 2025 18:39
Copy link
Contributor

@jojochuang jojochuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR fixes the bug, but a few nits were found in this piece of code that existed before.

I'll merge this one but we should refactor the code in a separate task.

if (count < maxKeys) {
response.setTruncated(false);
} else if (ozoneKeyIterator.hasNext()) {
} else if (ozoneKeyIterator.hasNext() && lastKey != null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ozoneKeyIterator could be null and throw NPE here.
But that's an existing problem. Suggest to move to a new issue.

if (maxKeys > 0) {
while (ozoneKeyIterator != null && ozoneKeyIterator.hasNext()) {
OzoneKey next = ozoneKeyIterator.next();
if (bucket != null && bucket.getBucketLayout().isFileSystemOptimized() &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bucket is always non-null here.

@jojochuang jojochuang merged commit b968353 into apache:master Aug 3, 2025
52 of 53 checks passed
@Jimmyweng006
Copy link
Contributor Author

Thanks @peterxcli for helping on the PR, and @jojochuang for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

s3 S3 Gateway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants