Skip to content

HDDS-16195. Reuse computed replicated sizes in KeyDeletingService - #11028

Open
chihsuan wants to merge 2 commits into
apache:masterfrom
chihsuan:HDDS-16195
Open

HDDS-16195. Reuse computed replicated sizes in KeyDeletingService#11028
chihsuan wants to merge 2 commits into
apache:masterfrom
chihsuan:HDDS-16195

Conversation

@chihsuan

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

While building the reclaimable-key list, KeyManagerImpl already computes and stores each block's replicated size in DeletedBlock. It then traverses the key locations again through OMKeyRequest.sumBlockLengths() to recompute the same values for PurgedKey.

This change calculates purgedBytes from the DeletedBlock values already produced. It avoids another traversal of the key-location groups, their flattened-list allocations, and repeated QuotaUtil.getReplicatedSize() calls.

The resulting quota value and behavior are unchanged.

This complements HDDS-16183: that change improves sumBlockLengths() for its remaining callers, while this change removes a redundant call from the pending-deletion scan. The patches touch different files and can be merged independently.

What is the link to the Apache JIRA?

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

How was this patch tested?

Added checkPurgedBytesMatchBlocksQueuedForDeletion, which creates a versioned key spanning two location groups and verifies that purgedBytes equals the replicated-size sum of the blocks queued for deletion.

The targeted test passed:

  • TestKeyDeletingService$Normal#checkPurgedBytesMatchBlocksQueuedForDeletion

Checkstyle reports no errors for the changed files.

Generated-by: Claude Code (Opus 5)

Copilot AI lite review requested due to automatic review settings August 16, 2026 07:43
@chihsuan
chihsuan marked this pull request as ready for review August 16, 2026 07:45

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

This PR removes a redundant replicated-size recomputation during pending-deletion scans in OM by reusing the replicated sizes already computed into DeletedBlock entries when building PurgedKey objects. This keeps quota accounting behavior unchanged while reducing extra traversal/allocation work in the reclaimable-key listing path.

Changes:

  • Compute PurgedKey.purgedBytes by summing DeletedBlock.getReplicatedSize() instead of calling OMKeyRequest.sumBlockLengths().
  • Drop the now-unneeded OMKeyRequest import from KeyManagerImpl.
  • Add a unit test ensuring purgedBytes matches the replicated-size sum of the blocks queued for deletion for a versioned key spanning multiple location groups.

Reviewed changes

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

File Description
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/KeyManagerImpl.java Reuses already-computed per-block replicated sizes to derive purgedBytes, avoiding a second traversal of key location groups.
hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyDeletingService.java Adds coverage to validate purgedBytes exactly equals the sum of replicated sizes of queued DeletedBlocks.

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

@priyeshkaratha priyeshkaratha left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @chihsuan for working on this. Changes LGTM

@priyeshkaratha

Copy link
Copy Markdown
Member

@ashishkumar50 can you also have a look on this changes?

@ashishkumar50 ashishkumar50 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.

@chihsuan Thanks for the patch overall LGTM, Please update test code to validate in a better way.

.mapToLong(DeletedBlock::getReplicatedSize)
.sum();
assertEquals(blockSum, purgedKey.getPurgedBytes(),
"purged bytes must cover exactly the blocks queued for deletion");

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.

This is exactly the implementation formula used in test which will always be success. Instead assert the actual key size to validate whether the purge key yields the correct size.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, updated in 69ede2d. Thanks!

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.

4 participants