Skip to content

HDDS-16216. Avoid the flatten-copy in KeyInputStream.getBlockLocationInfo - #11099

Open
0lai0 wants to merge 1 commit into
apache:masterfrom
0lai0:HDDS-16216
Open

HDDS-16216. Avoid the flatten-copy in KeyInputStream.getBlockLocationInfo#11099
0lai0 wants to merge 1 commit into
apache:masterfrom
0lai0:HDDS-16216

Conversation

@0lai0

@0lai0 0lai0 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

KeyInputStream.getBlockLocationInfo runs on every per-block pipeline refresh / read retry. It flatten-copies the version map with createLocationList(), then does stream().filter().collect(toList()) just to pick get(0), two throwaway ArrayLists per call, no short-circuit.

OmKeyLocationInfoGroup.createLocationList() is documented a s"expensive ... Use getLocationLists() instead".

Fix: iterate getLocationLists() (the raw uncopied Collection<List<...>>) with a nested for-loop, return on first match. Zero allocations, short-circuits, same semantics.

What is the link to the Apache JIRA

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

How was this patch tested?

https://github.com/0lai0/ozone/actions/runs/32735325487

  • mvn -pl :ozone-client install -DskipTests — pass
  • mvn -pl :ozone-client test -Dtest=TestKeyInputStreamEC — pass
  • mvn -pl :ozone-client checkstyle:check — pass

Local JMH (target at last position → worst-case scan, gains are purely from removed allocations):

N / G before ns after ns before B/op after B/op
1 / 1 91 4 816 ≈0
1 / 4 131 11 1,080 ≈0
16 / 1 144 9 1,000 ≈0
16 / 4 288 33 1,944 ≈0
128 / 1 395 40 2,808 ≈0
128 / 4 1,365 158 7,760 ≈0

Generated-by: Claude Code (claude-opus-4-7)

Copilot AI lite review requested due to automatic review settings August 24, 2026 14:32

@yandrey321 yandrey321 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

Copilot AI 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.

Pull request overview

Optimizes block-location lookup by avoiding flattening, temporary allocations, and unnecessary stream processing.

Changes:

  • Uses short-circuiting nested iteration over location lists.
  • Restricts commons-collections4 to test scope.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/io/KeyInputStream.java Replaces stream-based lookup with direct allocation-free iteration.
hadoop-ozone/client/pom.xml Adjusts the Commons Collections dependency scope.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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