Skip to content

HDDS-16202. Avoid the list copy in ContainerEndpoint.getBlocks - #11038

Merged
sodonnel merged 1 commit into
apache:masterfrom
shuan1026:HDDS-16202
Aug 20, 2026
Merged

HDDS-16202. Avoid the list copy in ContainerEndpoint.getBlocks#11038
sodonnel merged 1 commit into
apache:masterfrom
shuan1026:HDDS-16202

Conversation

@shuan1026

@shuan1026 shuan1026 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

ContainerEndpoint.getBlocks called OmKeyLocationInfoGroup.getLocationList() and then stream().filter().collect(toList()) on the result, allocating two throwaway lists per key just to walk each block once. getLocationList() is documented as expensive: it flattens locationVersionMap.values() into a brand-new List on every call, instead of the O(1) getLocationLists() accessor.

This PR rewrites getBlocks to iterate getLocationLists() directly with a nested loop and an inline containerID check, removing both list allocations. Same pattern as OMKeyRequest.sumBlockLengths (HDDS-16183)
and KeyManagerImpl.refreshPipeline (HDDS-5384). Output ordering and contents are unchanged.

What is the link to the Apache JIRA

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

How was this patch tested?

Existing tests cover getBlocks through the Recon GET /api/v1/containers/:id/keys endpoint, including block-id and pagination assertions.

The following test suite passed (2 tests):

  • TestContainerEndpoint#testGetKeysForContainer
  • TestContainerEndpoint#testGetKeysForContainerWithPrevKey

Also ran checkstyle.sh and author.sh successfully.

@sravani-revuri sravani-revuri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall LGTM.
Now getBlocks uses getLocationLists() instead of flattening and applies the container ID check during iteration.

@sodonnel sodonnel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM - thanks for improving this.

@sodonnel
sodonnel merged commit 48d1c2f into apache:master Aug 20, 2026
88 of 90 checks passed
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.

3 participants