chihsuan commented on code in PR #12170:
URL: https://github.com/apache/ozone/pull/12170#discussion_r4798435815
##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmMetadataReader.java:
##########
@@ -236,6 +240,29 @@ 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 while the lifecycle service is disabled, since no key
would be expired, nor for a key read
+ * from a snapshot. A failed lookup only omits the expiration.
+ */
+ @Nullable
+ private LifecycleExpirationInfo getLifecycleExpiration(ResolvedBucket
bucket, String keyPath, OmKeyInfo keyInfo) {
+ OMMetadataManager metadataManager = keyManager.getMetadataManager();
+ if (!ozoneManager.getKeyLifecycleServiceConfig().isEnabled()
+ || metadataManager != ozoneManager.getMetadataManager()) {
+ return null;
+ }
+ try {
+ OmLifecycleConfiguration lifecycleConfiguration =
metadataManager.getLifecycleConfigurationTable()
+ .get(metadataManager.getBucketKey(bucket.realVolume(),
bucket.realBucket()));
+ return lifecycleConfiguration == null ? null :
lifecycleConfiguration.getExpiration(keyInfo, keyPath);
+ } catch (IOException ex) {
Review Comment:
Could we add a test where the lifecycle table lookup throws? It would keep a
failed lookup from ever failing the read.
##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/endpoint/ObjectEndpoint.java:
##########
@@ -534,6 +540,22 @@ static void addLastModifiedDate(
RFC1123Util.FORMAT.format(lastModificationTime));
}
+ /**
+ * Adds the {@code x-amz-expiration} header, e.g. {@code expiry-date="Fri,
27 Nov 2026 00:00:00 GMT",
+ * rule-id="rule1"}, if an enabled lifecycle Expiration rule of the bucket
applies to the key.
+ * As in AWS S3, the rule ID is URL-encoded.
+ */
+ static void addExpirationIfAny(ResponseBuilder responseBuilder,
S3KeyReadResult<?> readResult)
+ throws UnsupportedEncodingException {
+ LifecycleExpirationInfo expiration =
readResult.getLifecycleExpiration().orElse(null);
+ if (expiration == null) {
+ return;
+ }
+ ZonedDateTime expiryTime =
expiration.getExpiryTime().atZone(ZoneId.of(OzoneConsts.OZONE_TIME_ZONE));
+ responseBuilder.header(EXPIRATION_HEADER, "expiry-date=\"" +
RFC1123Util.FORMAT.format(expiryTime)
Review Comment:
Small edge case: should we skip the header when the expiry year is past
9999? A rule like `Days=9999999` passes validation, but `RFC1123Util.FORMAT`
only prints four-digit years, so HEAD/GET on matching keys would throw instead
of just omitting the header.
--
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]