Skip to content

HDDS-12794. Improve Lifecycle rule validity checking#9593

Merged
ChenSammi merged 3 commits into
apache:HDDS-8342from
xichen01:HDDS-12794
Jan 16, 2026
Merged

HDDS-12794. Improve Lifecycle rule validity checking#9593
ChenSammi merged 3 commits into
apache:HDDS-8342from
xichen01:HDDS-12794

Conversation

@xichen01
Copy link
Copy Markdown
Contributor

@xichen01 xichen01 commented Jan 6, 2026

What changes were proposed in this pull request?

Add additional validations for Lifecycle Rules based on AWS S3's Lifecycle features and Ozone's inherent characteristics:

  1. Validate that the prefix length in the Rule is less than 1024 bytes [1]
  2. Validate that Tag keys within the same Rule are unique [2]
  3. Verify that the length of a tag key within a rule is less than 128 bytes. [2]
  4. Verify that the length of a tag value within a rule is less than 256 bytes. [2]
  5. Verify that the prefix within a rule cannot be the Trash Root directory or any of its subdirectories.

Ref:
[1] https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html
[2] https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-tagging.html

What is the link to the Apache JIRA

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

How was this patch tested?

unit test.

* @throws OMException if the prefix is a trash path
*/
public static void validateTrashPrefix(String prefix) throws OMException {
if (org.apache.commons.lang3.StringUtils.isEmpty(prefix)) {
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.

Can we import the StringUtils?

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.

Yes, import it.

String key = entry.getKey();
String value = entry.getValue();

if (key == null || key.isEmpty() ||
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.

StringUtils.isEmpty(key)

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.

updated

MAX_TAG_KEY_LENGTH, OMException.ResultCodes.INVALID_REQUEST);
}

if (value != null && value.getBytes(StandardCharsets.UTF_8).length > MAX_TAG_VALUE_LENGTH) {
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.

StringUtils.isEmpty(value)

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.

updated

/**
* Validates the OmLifecycleRuleAndOperator.
* Ensures the following:
* - Either tags or prefix must be specified.
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.

Can we keep these comments?


/**
* Validates the lifecycle rule.
* - ID length should not exceed the allowed limit
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.

Can we keep these comments?

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.

There are currently multiple validation rules in place.
I'm concerned that if comments aren't properly maintained in the future, errors may occur. Therefore, it might be advisable to directly remove the information obtained from the method code.

Copy link
Copy Markdown
Contributor

@ChenSammi ChenSammi Jan 13, 2026

Choose a reason for hiding this comment

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

I believe that AWS will not change it's API spec and behavior frequently, so the validation logic is likely being stable. Besides, any future patch of this feature, likely at least one of us will help with the review, so we can guarantee that comments can get updated together with code change.

Let's keep these comments. It's very useful when I want to check that what's valid, and what's invalid of a configuration, than going through the code, as there are a few edge cases I would totally not sure about the conclusion without referring to these comments.

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.

OK, updated

"Lifecycle rule prefix cannot be trash root");

// 2. Prefix too long
String longPrefix = RandomStringUtils.randomAlphanumeric(1025);
Copy link
Copy Markdown
Contributor

@ChenSammi ChenSammi Jan 8, 2026

Choose a reason for hiding this comment

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

We can use (OmLifecycleUtils#MAX_PREFIX_LENGTH + 1 ) here and for below 1024 , so it will be very straightforward.

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.

Yes, more readable, updated

@ChenSammi
Copy link
Copy Markdown
Contributor

Thanks @xichen01 , overall it looks good to me. Just a few minor comments.

Copy link
Copy Markdown
Contributor

@ChenSammi ChenSammi left a comment

Choose a reason for hiding this comment

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

Thanks @xichen01 .

@ChenSammi ChenSammi merged commit 8ee502a into apache:HDDS-8342 Jan 16, 2026
122 of 125 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

s3-lifecycle HDDS-8342

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants