chihsuan commented on code in PR #12170:
URL: https://github.com/apache/ozone/pull/12170#discussion_r4739592522
##########
hadoop-ozone/client/src/main/java/org/apache/hadoop/ozone/client/OzoneKey.java:
##########
@@ -226,6 +229,19 @@ public String getEncryptionKeyName() {
return encryptionKeyName;
}
+ /**
+ * Returns when the key expires under the bucket lifecycle configuration,
null if no enabled Expiration rule
+ * applies to the key or it is not known. Only set for keys read through the
S3 APIs.
+ */
+ @JsonIgnore
+ public LifecycleExpirationInfo getLifecycleExpiration() {
+ return lifecycleExpiration;
+ }
+
+ public void setLifecycleExpiration(LifecycleExpirationInfo
lifecycleExpiration) {
Review Comment:
Could we carry expiration in an S3-specific result for HEAD and GET, similar
to how `S3HeadObjectAttributes` carries bucket layout? That would avoid adding
a public setter to `OzoneKey` for metadata populated only by S3 reads.
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataReader.java:
##########
@@ -236,6 +240,27 @@ public KeyInfoWithVolumeContext getKeyInfo(final OmKeyArgs
args,
}
}
+ /**
+ * Returns when the key expires under the bucket lifecycle configuration,
for the S3 x-amz-expiration header.
+ * Nothing is returned for a key read from a snapshot, and a failed lookup
only omits the expiration.
+ */
+ @Nullable
+ private LifecycleExpirationInfo getLifecycleExpiration(ResolvedBucket
bucket, String keyPath, OmKeyInfo keyInfo) {
Review Comment:
Is it intended to return `x-amz-expiration` while the lifecycle service is
disabled, which is the default? A matching rule still gives us a date, but the
service won't act on it.
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/KeyInfoWithVolumeContext.java:
##########
@@ -50,10 +52,19 @@ public KeyInfoWithVolumeContext(OmVolumeArgs volumeArgs,
String userPrincipal,
OmKeyInfo keyInfo,
BucketLayout bucketLayout) {
+ this(volumeArgs, userPrincipal, keyInfo, bucketLayout, null);
+ }
+
+ public KeyInfoWithVolumeContext(OmVolumeArgs volumeArgs,
Review Comment:
nit: Since the Builder is the only caller, could this new constructor be
private?
##########
hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmLifeCycleConfiguration.java:
##########
@@ -307,4 +311,53 @@ private OmLifecycleConfiguration.Builder
configurationWithFilter(OmLCFilter filt
.build();
return getOmLifecycleConfiguration("volume", "bucket",
Collections.singletonList(rule));
}
+
+ @Test
+ public void testGetExpiration() throws OMException {
+ long modificationTime =
Instant.parse("2026-11-25T10:30:00Z").toEpochMilli();
+ OmLifecycleConfiguration lcc = getOmLifecycleConfiguration("volume",
"bucket", Arrays.asList(
+ getOmLCRuleBuilder("late", "", true, 10, null).build(),
Review Comment:
Could we put the earliest-expiring rule between two later-expiring rules?
That way the test would catch implementations that simply pick the first or
last match.
##########
hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmLifeCycleConfiguration.java:
##########
@@ -307,4 +311,53 @@ private OmLifecycleConfiguration.Builder
configurationWithFilter(OmLCFilter filt
.build();
return getOmLifecycleConfiguration("volume", "bucket",
Collections.singletonList(rule));
}
+
+ @Test
+ public void testGetExpiration() throws OMException {
+ long modificationTime =
Instant.parse("2026-11-25T10:30:00Z").toEpochMilli();
+ OmLifecycleConfiguration lcc = getOmLifecycleConfiguration("volume",
"bucket", Arrays.asList(
+ getOmLCRuleBuilder("late", "", true, 10, null).build(),
+ getOmLCRuleBuilder("logs", "logs/", true, 2, null).build(),
+ getOmLCRuleBuilder("disabled", "", false, 1, null).build(),
+ getOmLCRuleBuilder("tag", null, true, 5,
+ getOmLCFilterBuilder(null, new Tag("k", "v"),
null).build()).build(),
+ getOmLCRuleBuilder("and", null, true, 3, getOmLCFilterBuilder(null,
null,
+ getOmLCAndOperatorBuilder("data/", ImmutableMap.of("k",
"v")).build()).build()).build()))
+ .build();
+
+ // Earliest matching enabled rule wins; the disabled rule is ignored.
+ assertExpiration("logs", "2026-11-28T00:00:00Z", lcc, "logs/a",
Collections.emptyMap(), modificationTime);
+ assertExpiration("late", "2026-12-06T00:00:00Z", lcc, "other/a",
Collections.emptyMap(), modificationTime);
+ assertExpiration("tag", "2026-12-01T00:00:00Z", lcc, "other/a",
ImmutableMap.of("k", "v"), modificationTime);
+ assertExpiration("and", "2026-11-29T00:00:00Z", lcc, "data/a",
ImmutableMap.of("k", "v"), modificationTime);
+ assertExpiration("late", "2026-12-06T00:00:00Z", lcc, "data/a",
ImmutableMap.of("k", "x"), modificationTime);
+
+ OmLifecycleConfiguration noMatch = getOmLifecycleConfiguration("volume",
"bucket", Arrays.asList(
Review Comment:
Could we add a rule with only `AbortIncompleteMultipartUpload`? The
`getExpiration() == null` check isn't covered yet.
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmLCRule.java:
##########
@@ -289,6 +289,23 @@ public boolean match(OmDirectoryInfo dirInfo, String
keyPath) {
return matched;
}
+ /**
+ * Whether this rule is enabled, has an Expiration action, and its prefix or
filter applies to the key,
+ * regardless of whether the key has already expired.
+ *
+ * @param omKeyInfo detail Key info to evaluate against this rule
+ * @param keyPath path include key name and all its parent, except bucket
and volume
+ */
+ public boolean appliesForExpiration(OmKeyInfo omKeyInfo, String keyPath) {
Review Comment:
nit: Would it make sense to share the prefix and filter check with
`match(OmKeyInfo, String)`? The selection logic now lives in two places and
could drift.
##########
hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmLCExpiration.java:
##########
@@ -72,6 +73,31 @@ public boolean isExpired(long timestamp) {
}
}
+ /**
+ * Returns when an object last modified at the given time expires under this
action, as AWS S3 reports it in the
+ * x-amz-expiration header: for Days, the modification time plus the days,
rounded up to the next midnight UTC;
+ * for Date, the configured date.
+ *
+ * @param modificationTime modification time of the object in milliseconds
since epoch
+ * @return the expiry time, or null if neither a positive Days nor a
parsable Date is set
+ */
+ @Nullable
+ public Instant getExpiryTime(long modificationTime) {
+ if (days != null && days > 0) {
+ ZonedDateTime expiry =
Instant.ofEpochMilli(modificationTime).atZone(ZoneOffset.UTC).plusDays(days);
+ ZonedDateTime midnight = expiry.truncatedTo(ChronoUnit.DAYS);
+ return (midnight.equals(expiry) ? midnight :
midnight.plusDays(1)).toInstant();
Review Comment:
Should `isExpired()` share this computation? It doesn't round up, so a key
may be deleted before the date in this header.
AWS [rounds
up](https://docs.aws.amazon.com/AmazonS3/latest/userguide/intro-lifecycle-rules.html)
for the actual expiry too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]