Skip to content

HDDS-13532. Refactor BucketEndpoint.get()#10045

Open
rich7420 wants to merge 9 commits intoapache:masterfrom
rich7420:HDDS-13532
Open

HDDS-13532. Refactor BucketEndpoint.get()#10045
rich7420 wants to merge 9 commits intoapache:masterfrom
rich7420:HDDS-13532

Conversation

@rich7420
Copy link
Copy Markdown
Contributor

@rich7420 rich7420 commented Apr 5, 2026

What changes were proposed in this pull request?

Reopen: #9110
This pull request refactors the massively monolithic BucketEndpoint.get() method (ListObjects API implementation) to vastly improve codebase maintainability, readability, and unit-testability.

The original get() method was nearly 200 lines long. It tightly coupled logic across multiple domains—from parameter string deserialization, context variable instantiation, iterative key-prefix filtering logic, to S3 metrics/audit log emissions. This structure made it inherently risky to extend and nearly impossible to write isolated unit tests for individual components of the logic.

Key Refactoring Improvements in this PR:

  • Context Encapsulation (BucketListingContext): Introduced a dedicated package-private class to securely encapsulate listing state (such as bucketName, prefix, encodingType, maxKeys, decodedToken, ozoneKeyIterator, etc.). This successfully prevented "parameter-creep" and minimized variable clutter across the execution flow.
  • Method Extraction & Separation of Concerns: We systematically decomposed the unmaintainable block into multiple single-responsibility helper methods:
    • validateAndPrepareParameters(): Sanitizes configuration limits, handles token decodings, verifies encoding types, and enforces S3 Bucket owner conditions.
    • initializeListObjectResponse(): Generates the bare-bones boilerplate response structures.
    • processKeyListing(): Owns the complex computational burden (the while (ozoneKeyIterator.hasNext()) mechanism), resolving token depth matches, delimited deep structures, and CommonPrefixes allocations safely.
    • buildFinalResponse(): Isolates the responsibility of executing PerformanceStringBuilder increments and consistent auditReadSuccess publishing.
  • Seamless Upstream Synchronization: During refactoring, this branch was comprehensively synced and merged with master's recent additions (S3RequestContext, PerformanceStringBuilder, and the BucketOperationHandler Chain-of-Responsibility pattern). The refactor cleanly embraces these integrations while achieving optimal flow footprint.

What is the link to the Apache JIRA?

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

How was this patch tested?

https://github.com/rich7420/ozone/actions/runs/23993539910

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant