-
Notifications
You must be signed in to change notification settings - Fork 594
HDDS-13722. Refactor duplicate code in OMDirectoriesPurgeRequestWithFSO #9102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HDDS-13722. Refactor duplicate code in OMDirectoriesPurgeRequestWithFSO #9102
Conversation
1b674c6 to
216f57a
Compare
adoroszlai
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @unknowntpo for the patch. Please enable the build-branch workflow in your fork.
| @SuppressWarnings("visibilitymodifier") | ||
| private static class ProcessedKeyInfo { | ||
| final OmKeyInfo keyInfo; | ||
| final String deleteKey; | ||
| final String volumeName; | ||
| final String bucketName; | ||
| final Pair<String, String> volBucketPair; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suppression doesn't seem to be necessary.
| @SuppressWarnings("visibilitymodifier") | |
| private static class ProcessedKeyInfo { | |
| final OmKeyInfo keyInfo; | |
| final String deleteKey; | |
| final String volumeName; | |
| final String bucketName; | |
| final Pair<String, String> volBucketPair; | |
| private static class ProcessedKeyInfo { | |
| private final OmKeyInfo keyInfo; | |
| private final String deleteKey; | |
| private final String volumeName; | |
| private final String bucketName; | |
| private final Pair<String, String> volBucketPair; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, build-branch is enabled. And suggestion is applied.
There was a problem hiding this comment.
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 refactors duplicate code in OMDirectoriesPurgeRequestWithFSO by extracting common key processing logic into a reusable helper method. The changes eliminate code duplication between subdirectory and subfile processing loops while maintaining the same functionality.
- Extracted common key processing logic into
processDeleteKeyhelper method - Introduced
ProcessedKeyInfohelper class to encapsulate processed key information - Replaced duplicate code blocks in both subdirectory and subfile processing loops
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| private static class ProcessedKeyInfo { | ||
| private final OmKeyInfo keyInfo; | ||
| private final String deleteKey; | ||
| private final String volumeName; | ||
| private final String bucketName; | ||
| private final Pair<String, String> volBucketPair; |
Copilot
AI
Oct 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ProcessedKeyInfo class exposes all fields as package-private, but they should be private with getter methods for better encapsulation. Direct field access breaks encapsulation principles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getter is too verbose.
| ProcessedKeyInfo(OmKeyInfo keyInfo, String deleteKey, String volumeName, String bucketName, | ||
| Pair<String, String> volBucketPair) { |
Copilot
AI
Oct 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor accepts both individual volumeName/bucketName parameters and a volBucketPair containing the same information, creating redundancy. Consider creating the volBucketPair internally from volumeName and bucketName to eliminate this duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, fixed at 05ffdc8
9d0e607 to
05ffdc8
Compare
|
+1 |
|
Merged. Thanks @unknowntpo for contribution and @adoroszlai for review. |
…RequestWithFSO (apache#9102) (cherry picked from commit 2ae1f65) Conflicts: hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/request/key/OMDirectoriesPurgeRequestWithFSO.java Change-Id: I02c7d85a3b21fbcfce52e1708b769d1fd8bd8841
…RequestWithFSO (apache#9102) Change-Id: Ia129a097f64815d38eea725733db2aca6e4cec77
Extract duplicate code for processing keys and acquiring locks into a helper method. Both subdirectory and subfile processing loops had identical code for:
volBucketPairIntroduced ProcessedKeyInfo helper class to encapsulate all extracted information (keyInfo, deleteKey, volumeName, bucketName, volBucketPair) and processDeleteKey method to eliminate code duplication.
What changes were proposed in this pull request?
Extract duplicated code.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-13722
How was this patch tested?
UT:
TestOMDirectoriesPurgeRequestAndResponse