Skip to content

HDDS-13444. Unify isValidKeyPath implementation#9521

Merged
ivandika3 merged 7 commits intoapache:masterfrom
rich7420:HDDS-13444-test
Feb 19, 2026
Merged

HDDS-13444. Unify isValidKeyPath implementation#9521
ivandika3 merged 7 commits intoapache:masterfrom
rich7420:HDDS-13444-test

Conversation

@rich7420
Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR unified the duplicated isValidKeyPath validation logic between OzoneFSUtils and OMClientRequest by extracting the common path validation into a shared private method validateKeyPathComponents, and made OMClientRequest.isValidKeyPath delegate to OzoneFSUtils.isValidKeyPath to remove code duplication.

What is the link to the Apache JIRA

HDDS-13444

How was this patch tested?

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

Copy link
Copy Markdown
Contributor

@echonesis echonesis left a comment

Choose a reason for hiding this comment

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

Thanks @rich7420 , left some comments.

Comment on lines +132 to +135
if (allowLeadingSlash && i == 0) {
// Allow empty at start for absolute paths
continue;
}
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.

It seems this section is not included in original OMClientRequest.isValidKeyPath().
Please describe more details in the commit message section.

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.

sure!

* Add reference counter to an object instance.
*/
class ReferenceCounted<T> {
public class ReferenceCounted<T> {
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.

Could we keep it package-private?

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.

I change to public cuz ci test error. I'll try to figure out the solution to keep it private.

* Whether the pathname is valid. Currently prohibits relative paths,
* names which contain a ":" or "//", or other non-canonical paths.
*/
public static boolean isValidName(String src) {
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.

nit: use path instead of src to keep it consistent with isValidKeyPath

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.

sure, thanks for the reminder!

}

@Test
public void testIsValidKeyPath() throws OMException {
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.

We could add some tests like

  • assertEquals("a/b/", OzoneFSUtils.isValidKeyPath("a/b/", true));
  • assertThrows(OMException.class, () -> OzoneFSUtils.isValidKeyPath("/a/b", false));

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.

no problem!

@adoroszlai adoroszlai added the code-cleanup Changes that aim to make code better, without changing functionality. label Dec 19, 2025
@adoroszlai adoroszlai requested a review from ivandika3 December 19, 2025 19:08
Copy link
Copy Markdown
Contributor

@sreejasahithi sreejasahithi left a comment

Choose a reason for hiding this comment

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

Thanks @rich7420 for working on this, left few comments

public static String isValidKeyPath(String path, boolean throwOnEmpty) throws OMException {
if (path.isEmpty()) {
if (throwOnEmpty) {
throw new OMException("Invalid KeyPath, empty keyName" + path,
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.

Suggested change
throw new OMException("Invalid KeyPath, empty keyName" + path,
throw new OMException("Invalid KeyPath, empty keyName " + path,

or we could instead remove path from the message as it is empty and the message already says empty KeyName.

}

@Test
public void testIsValidKeyPath() throws OMException {
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.

you can add some more test cases for key paths likefile.txt, ./file

@rich7420
Copy link
Copy Markdown
Contributor Author

@sreejasahithi thanks for the review!

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 5, 2026

This PR has been marked as stale due to 21 days of inactivity. Please comment or remove the stale label to keep it open. Otherwise, it will be automatically closed in 7 days.

@github-actions github-actions Bot added the stale label Feb 5, 2026
@ivandika3 ivandika3 removed the stale label Feb 5, 2026
Copy link
Copy Markdown
Contributor

@sreejasahithi sreejasahithi left a comment

Choose a reason for hiding this comment

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

Thanks @rich7420 , overall LGTM.

@rich7420
Copy link
Copy Markdown
Contributor Author

@sreejasahithi thanks for the review!

Copy link
Copy Markdown
Contributor

@ivandika3 ivandika3 left a comment

Choose a reason for hiding this comment

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

Thanks @rich7420 for the patch and apologies for the late review. LGTM +1.

@ivandika3 ivandika3 merged commit 72d69e5 into apache:master Feb 19, 2026
44 checks passed
@ivandika3
Copy link
Copy Markdown
Contributor

Thanks @rich7420 for the patch and @echonesis @sreejasahithi for the reviews.

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

Labels

code-cleanup Changes that aim to make code better, without changing functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants