This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new f0b10e0fd1e HDDS-17913. Lifecycle Expiration rule checks key 
modification time instead of current time (#12149)
f0b10e0fd1e is described below

commit f0b10e0fd1e58800b15f28c7dde276be899482df
Author: Chung En Lee <[email protected]>
AuthorDate: Wed Nov 25 15:26:20 2026 +0800

    HDDS-17913. Lifecycle Expiration rule checks key modification time instead 
of current time (#12149)
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 .../hadoop/ozone/om/helpers/OmLCExpiration.java    |   6 +-
 .../ozone/om/helpers/TestOmLCExpiration.java       |  21 +++
 .../ozone/om/service/TestKeyLifecycleService.java  | 142 ++++++++++-----------
 3 files changed, 90 insertions(+), 79 deletions(-)

diff --git 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmLCExpiration.java
 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmLCExpiration.java
index 69db359efa6..9fc2e5bec93 100644
--- 
a/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmLCExpiration.java
+++ 
b/hadoop-ozone/common/src/main/java/org/apache/hadoop/ozone/om/helpers/OmLCExpiration.java
@@ -62,12 +62,10 @@ public String getDate() {
   }
 
   public boolean isExpired(long timestamp) {
+    ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
     if (zonedDateTime != null) {
-      Instant instant = Instant.ofEpochMilli(timestamp);
-      ZonedDateTime objectTime = instant.atZone(ZoneOffset.UTC);
-      return objectTime.isBefore(zonedDateTime);
+      return now.isAfter(zonedDateTime);
     } else {
-      ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
       ZonedDateTime dateTime =
           ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp + 
daysInMilli), ZoneOffset.UTC);
       return now.isAfter(dateTime);
diff --git 
a/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmLCExpiration.java
 
b/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmLCExpiration.java
index 1aa3e2b5011..a35f33d01f0 100644
--- 
a/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmLCExpiration.java
+++ 
b/hadoop-ozone/common/src/test/java/org/apache/hadoop/ozone/om/helpers/TestOmLCExpiration.java
@@ -22,8 +22,11 @@
 import static org.apache.hadoop.ozone.om.helpers.OMLCUtils.getFutureDateString;
 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
+import java.time.Instant;
 import org.apache.hadoop.ozone.om.exceptions.OMException;
 import 
org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.LifecycleAction;
 import org.junit.jupiter.api.Test;
@@ -172,6 +175,24 @@ public void testDateMustBeAtMidnightUTC() {
     assertOMException(() -> exp5.build().valid(currentTime), INVALID_REQUEST, 
"'Date' must represent midnight UTC");
   }
 
+  @Test
+  public void testIsExpiredWithDate() throws OMException {
+    long now = System.currentTimeMillis();
+    long beforeDate = Instant.parse("2019-12-31T00:00:00Z").toEpochMilli();
+
+    // The date has not arrived yet, so no key is expired, no matter when it 
was modified.
+    OmLCExpiration futureDate = new 
OmLCExpiration.Builder().setDate("2099-10-10T00:00:00Z").build();
+    futureDate.valid(now);
+    assertFalse(futureDate.isExpired(beforeDate));
+    assertFalse(futureDate.isExpired(now));
+
+    // The date has passed, so every key is expired, including keys modified 
after the date.
+    OmLCExpiration pastDate = new 
OmLCExpiration.Builder().setDate("2020-01-01T00:00:00Z").build();
+    pastDate.valid(beforeDate);
+    assertTrue(pastDate.isExpired(beforeDate));
+    assertTrue(pastDate.isExpired(now));
+  }
+
   @Test
   public void testProtobufConversion() throws OMException {
     // Only Days
diff --git 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyLifecycleService.java
 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyLifecycleService.java
index a95f4545cab..11adad06dab 100644
--- 
a/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyLifecycleService.java
+++ 
b/hadoop-ozone/ozone-manager/src/test/java/org/apache/hadoop/ozone/om/service/TestKeyLifecycleService.java
@@ -188,9 +188,6 @@ class TestKeyLifecycleService extends OzoneTestBase {
   private static final AtomicInteger OBJECT_ID_COUNTER = new AtomicInteger();
   private static final int KEY_COUNT = 2;
   private static final int EXPIRE_SECONDS = 2;
-  // Date-based expiration compares the key's modificationTime against the 
date, so tests that rename or
-  // update a key after it was scanned need a date that stays in the future 
for the whole test.
-  private static final int LONG_EXPIRE_SECONDS = 600;
   private static final int SERVICE_INTERVAL = 300;
   private static final int WAIT_CHECK_INTERVAL = 50;
 
@@ -362,7 +359,7 @@ void testAllKeyExpired(BucketLayout bucketLayout, boolean 
createPrefix) throws I
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       if (createPrefix) {
         createLifecyclePolicy(volumeName, bucketName, bucketLayout, 
rulePrefix, null, date.toString(), true);
       } else {
@@ -395,7 +392,7 @@ void testScanStatePiggybackedOnDelete(BucketLayout 
bucketLayout, boolean createP
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       
       if (createPrefix) {
         createLifecyclePolicy(volumeName, bucketName, bucketLayout, 
rulePrefix, null, date.toString(), true);
@@ -458,7 +455,7 @@ void testPeriodicStateSave(BucketLayout bucketLayout) 
throws Exception {
       try {
         // create Lifecycle configuration
         ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-        ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+        ZonedDateTime date = now;
         createLifecyclePolicy(volumeName, bucketName, bucketLayout, 
rulePrefix, null, date.toString(), true);
 
         // Resume the service
@@ -535,7 +532,7 @@ void testBucketScanResume(BucketLayout bucketLayout, 
boolean createPrefix) throw
 
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       if (createPrefix) {
         createLifecyclePolicy(volumeName, bucketName, bucketLayout, 
rulePrefix, null, date.toString(), true);
       } else {
@@ -588,7 +585,7 @@ void testInFlightClearedWhenTaskSkipsRun() throws Exception 
{
       keyLifecycleService.suspend();
       createVolumeAndBucket(volumeName, bucketName, BucketLayout.OBJECT_STORE,
           UserGroupInformation.getCurrentUser().getShortUserName());
-      ZonedDateTime date = 
ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = ZonedDateTime.now(ZoneOffset.UTC);
       createLifecyclePolicy(volumeName, bucketName, BucketLayout.OBJECT_STORE, 
"key", null, date.toString(), true);
       String bucketKey = metadataManager.getBucketKey(volumeName, bucketName);
 
@@ -637,7 +634,7 @@ void testAbortedScanDoesNotMarkScanComplete(BucketLayout 
bucketLayout, boolean c
       assertEquals(testKeyCount, keyList.size());
 
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       if (createPrefix) {
         createLifecyclePolicy(volumeName, bucketName, bucketLayout, 
rulePrefix, null, date.toString(), true);
       } else {
@@ -684,7 +681,7 @@ void testPolicyChangedDuringScan(boolean deletePolicy) 
throws Exception {
       assertEquals(KEY_COUNT, keyList.size());
       GenericTestUtils.waitFor(() -> getKeyCount(OBJECT_STORE) - 
initialKeyCount == KEY_COUNT,
           WAIT_CHECK_INTERVAL, 1000);
-      ZonedDateTime date = 
ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(LONG_EXPIRE_SECONDS);
+      ZonedDateTime date = ZonedDateTime.now(ZoneOffset.UTC);
       createLifecyclePolicy(volumeName, bucketName, OBJECT_STORE, "key", null, 
date.toString(), true);
 
       GenericTestUtils.LogCapturer logCapturer = 
GenericTestUtils.LogCapturer.captureLogs(
@@ -772,7 +769,7 @@ void testBucketScanWithScanEndTime(BucketLayout 
bucketLayout, boolean createPref
 
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       if (createPrefix) {
         createLifecyclePolicy(volumeName, bucketName, bucketLayout, 
rulePrefix, null, date.toString(), true);
       } else {
@@ -831,7 +828,7 @@ void testScanEmptyBucket(BucketLayout bucketLayout, boolean 
moveToTrash) throws
           
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       OmLCFilter.Builder filter = bucketLayout == FILE_SYSTEM_OPTIMIZED ? 
getOmLCFilterBuilder("", null, null) :
           getOmLCFilterBuilder("key", null, null);
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, null, 
filter.build(), date.toString(), true);
@@ -881,7 +878,7 @@ void testScanStateFailureDoesNotImpactScan(BucketLayout 
bucketLayout, boolean cr
       try {
         // create Lifecycle configuration
         ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-        ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+        ZonedDateTime date = now;
         if (createPrefix) {
           createLifecyclePolicy(volumeName, bucketName, bucketLayout, 
rulePrefix, null, date.toString(), true);
         } else {
@@ -965,7 +962,7 @@ void testNestedFSODirectoryScanResume(BucketLayout 
bucketLayout, int maxSize) th
 
       // Create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, prefix, 
null, date.toString(), true);
 
       // Inject to cause resume case for FSO with nested directory
@@ -1095,7 +1092,7 @@ void 
testFSOScanSkipsDirectoriesWhenCachedDirectoryMaxCountExceeded(long cachedD
       awaitKeyCacheDrained(FILE_SYSTEM_OPTIMIZED, volumeName, bucketName);
       awaitDirCacheDrained(volumeName, bucketName);
 
-      ZonedDateTime date = 
ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(LONG_EXPIRE_SECONDS);
+      ZonedDateTime date = ZonedDateTime.now(ZoneOffset.UTC);
       OmLCFilter.Builder filter = getOmLCFilterBuilder("", null, null);
       createLifecyclePolicy(volumeName, bucketName, FILE_SYSTEM_OPTIMIZED, 
null, filter.build(), date.toString(), true);
 
@@ -1165,7 +1162,7 @@ void testExpiredDirectoryChangedBeforeDeletion(boolean 
addChildKey, String expec
       createDirectory(volumeName, bucketName, dirName);
       awaitDirCacheDrained(volumeName, bucketName);
 
-      ZonedDateTime date = 
ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(LONG_EXPIRE_SECONDS);
+      ZonedDateTime date = ZonedDateTime.now(ZoneOffset.UTC);
       OmLCFilter.Builder filter = getOmLCFilterBuilder("", null, null);
       createLifecyclePolicy(volumeName, bucketName, FILE_SYSTEM_OPTIMIZED, 
null, filter.build(), date.toString(), true);
 
@@ -1221,7 +1218,7 @@ void testOneKeyExpired(BucketLayout bucketLayout, boolean 
createPrefix) throws I
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       int keyIndex = ThreadLocalRandom.current().nextInt(KEY_COUNT - 1);
       String rulePrefix = bucketLayout == FILE_SYSTEM_OPTIMIZED ? "" : 
keyList.get(keyIndex).getKeyName();
       if (createPrefix) {
@@ -1290,7 +1287,7 @@ void testDirectorySkippedAfterResume(String 
lastScannedDir, String[] skippedDir,
 
       // Create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       createLifecyclePolicy(volumeName, bucketName, 
BucketLayout.FILE_SYSTEM_OPTIMIZED, prefix,
           null, date.toString(), true);
 
@@ -1369,7 +1366,7 @@ void testLastScannedKeySeek(boolean keyBelongToDir) 
throws Exception {
       String key3DbKey = metadataManager.getOzonePathKey(volumeId, bucketId, 
dir2Id, "key3");
 
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       OmLCFilter.Builder filter = getOmLCFilterBuilder(prefix, null, null);
       createLifecyclePolicy(volumeName, bucketName, 
BucketLayout.FILE_SYSTEM_OPTIMIZED, null,
           filter.build(), date.toString(), true);
@@ -1448,7 +1445,7 @@ void testCacheOnlyKeyNotSavedAsLastScannedKey() throws 
Exception {
       String cacheOnlyDbKey = metadataManager.getOzonePathKey(volumeId, 
bucketId, dir1Id, "key9");
       keyTable.addCacheEntry(new CacheKey<>(cacheOnlyDbKey), 
CacheValue.get(Long.MAX_VALUE, cacheOnlyKey));
 
-      ZonedDateTime date = 
ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = ZonedDateTime.now(ZoneOffset.UTC);
       createLifecyclePolicy(volumeName, bucketName, FILE_SYSTEM_OPTIMIZED, "", 
null, date.toString(), true);
 
       Field tableField = 
OmMetadataManagerImpl.class.getDeclaredField("lifecycleScanStateTable");
@@ -1509,7 +1506,7 @@ void testBucketRootScannedDirResume(BucketLayout layout) 
throws Exception {
           metadataManager.getOzoneKey(volumeName, bucketName, "key2");
 
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       OmLCFilter.Builder filter = getOmLCFilterBuilder(prefix, null, null);
       createLifecyclePolicy(volumeName, bucketName, layout, null,
           filter.build(), date.toString(), true);
@@ -1561,7 +1558,7 @@ void testOnlyKeyExpired(BucketLayout bucketLayout, 
boolean createPrefix) throws
 
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       String rulePrefix = bucketLayout == FILE_SYSTEM_OPTIMIZED ? "" : 
keyArg.getKeyName();
       if (createPrefix) {
         createLifecyclePolicy(volumeName, bucketName, bucketLayout, 
rulePrefix, null, date.toString(), true);
@@ -1595,7 +1592,7 @@ void testAllKeyExpiredWithTag(BucketLayout bucketLayout) 
throws IOException,
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       OmLCFilter.Builder filter = getOmLCFilterBuilder(null, tag, null);
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, null, 
filter.build(), date.toString(), true);
 
@@ -1633,7 +1630,7 @@ void testOneKeyExpiredWithTag(BucketLayout bucketLayout) 
throws IOException,
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       OmLCFilter.Builder filter = getOmLCFilterBuilder(null, tag, null);
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, null, 
filter.build(), date.toString(), true);
 
@@ -1661,7 +1658,7 @@ void testAllKeyExpiredWithAndOperator(BucketLayout 
bucketLayout) throws IOExcept
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       String rulePrefix = bucketLayout == FILE_SYSTEM_OPTIMIZED ? "" : 
keyPrefix;
       OmLifecycleRuleAndOperator andOperator = 
getOmLCAndOperatorBuilder(rulePrefix, tags).build();
       OmLCFilter.Builder filter = getOmLCFilterBuilder(null, null, 
andOperator);
@@ -1700,7 +1697,7 @@ void testOneKeyExpiredWithAndOperator(BucketLayout 
bucketLayout) throws IOExcept
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       String rulePrefix = bucketLayout == FILE_SYSTEM_OPTIMIZED ? "" : 
keyPrefix;
       OmLifecycleRuleAndOperator andOperator = 
getOmLCAndOperatorBuilder(rulePrefix, tags).build();
       OmLCFilter.Builder filter = getOmLCFilterBuilder(null, null, 
andOperator);
@@ -1728,7 +1725,7 @@ void testEmptyPrefix(BucketLayout bucketLayout) throws 
IOException, TimeoutExcep
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, "", null, 
date.toString(), true);
 
       GenericTestUtils.waitFor(() ->
@@ -1755,7 +1752,7 @@ void testEmptyFilter(BucketLayout bucketLayout) throws 
IOException,
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       OmLCFilter.Builder filter = getOmLCFilterBuilder(null, null, null);
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, null, 
filter.build(), date.toString(), true);
 
@@ -1790,7 +1787,7 @@ void testRootSlashPrefix(BucketLayout bucketLayout, 
String prefix)
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, prefix, 
null, date.toString(), true);
 
       if (bucketLayout == FILE_SYSTEM_OPTIMIZED) {
@@ -1826,7 +1823,7 @@ void testSlashPrefix(BucketLayout bucketLayout, boolean 
createPrefix)
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       if (createPrefix) {
         createLifecyclePolicy(volumeName, bucketName, bucketLayout, 
rulePrefix, null, date.toString(), true);
       } else {
@@ -1866,7 +1863,7 @@ void testSlashKey(BucketLayout bucketLayout, boolean 
createPrefix)
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       if (createPrefix) {
         createLifecyclePolicy(volumeName, bucketName, bucketLayout, keyPrefix, 
null, date.toString(), true);
       } else {
@@ -1901,7 +1898,7 @@ void testSlashKeyWithAndOperator(BucketLayout 
bucketLayout)
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       OmLifecycleRuleAndOperator andOperator = 
getOmLCAndOperatorBuilder(keyPrefix, tags).build();
       OmLCFilter.Builder filter = getOmLCFilterBuilder(null, null, 
andOperator);
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, null, 
filter.build(), date.toString(), true);
@@ -1933,7 +1930,7 @@ void testSlashPrefixWithAndOperator(BucketLayout 
bucketLayout)
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       OmLifecycleRuleAndOperator andOperator = getOmLCAndOperatorBuilder("/" + 
keyPrefix, tags).build();
       OmLCFilter.Builder filter = getOmLCFilterBuilder(null, null, 
andOperator);
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, null, 
filter.build(), date.toString(), true);
@@ -1964,7 +1961,7 @@ void testComplexPrefix(BucketLayout bucketLayout) throws 
IOException,
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       String rulePrefix = bucketLayout == FILE_SYSTEM_OPTIMIZED ? 
"dir1/dir2/dir3/" : keyPrefix;
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, rulePrefix, 
null, date.toString(), true);
 
@@ -1995,7 +1992,7 @@ void testPrefixNotMatch(BucketLayout bucketLayout) throws 
IOException, Interrupt
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       OmLCFilter.Builder filter = getOmLCFilterBuilder(filterPrefix, null, 
null);
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, null, 
filter.build(), date.toString(), true);
 
@@ -2029,7 +2026,7 @@ void testExpireKeysUnderDirectory(BucketLayout 
bucketLayout) throws IOException,
 
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       String rulePrefix = bucketLayout == FILE_SYSTEM_OPTIMIZED ? 
"dir1/dir2/dir3/" : keyPrefix;
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, rulePrefix, 
null, date.toString(), true);
 
@@ -2079,7 +2076,7 @@ void testHsyncKeyNotExpired(BucketLayout bucketLayout, 
boolean hsyncInCache) thr
       }
       assertNotNull(hsyncKey);
 
-      ZonedDateTime date = 
ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = ZonedDateTime.now(ZoneOffset.UTC);
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, "dir1/", 
null, date.toString(), true);
 
       GenericTestUtils.waitFor(() ->
@@ -2181,7 +2178,7 @@ void testPrefixDirectoryNotExpired(String dirName, String 
prefix, boolean create
 
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       if (createPrefix) {
         createLifecyclePolicy(volumeName, bucketName, FILE_SYSTEM_OPTIMIZED,
             prefix, null, date.toString(), true);
@@ -2223,7 +2220,7 @@ void testConsolidatedPrefixNotHappen() throws 
IOException, TimeoutException, Int
 
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       List<OmLCRule> ruleList = new ArrayList<>();
       String ruleID1 = String.valueOf(OBJECT_ID_COUNTER.getAndIncrement());
       String ruleID2 = String.valueOf(OBJECT_ID_COUNTER.getAndIncrement());
@@ -2299,7 +2296,7 @@ void testConsolidatedPrefixDirectoryNotExpired(String 
dir1, String dir2, String
 
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       List<OmLCRule> ruleList = new ArrayList<>();
       String ruleID1 = String.valueOf(OBJECT_ID_COUNTER.getAndIncrement());
       String ruleID2 = String.valueOf(OBJECT_ID_COUNTER.getAndIncrement());
@@ -2383,7 +2380,7 @@ void testExpireNonExistDirectory(BucketLayout 
bucketLayout)
 
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, 
"dir1/dir2/dir4/", null, date.toString(), true);
 
       Thread.sleep(EXPIRE_SECONDS);
@@ -2415,7 +2412,7 @@ void testRuleDisabled(BucketLayout bucketLayout) throws 
IOException, Interrupted
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, "", null, 
date.toString(), false);
       Thread.sleep(EXPIRE_SECONDS);
       assertEquals(initialDeletedKeyCount, getDeletedKeyCount());
@@ -2441,7 +2438,7 @@ void testOneRuleDisabledOneRuleEnabled(BucketLayout 
bucketLayout)
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       List<OmLCRule> ruleList = new ArrayList<>();
       String rulePrefix = bucketLayout == FILE_SYSTEM_OPTIMIZED ? "" : 
keyPrefix;
       ruleList.add(new 
OmLCRule.Builder().setId(String.valueOf(OBJECT_ID_COUNTER.getAndIncrement()))
@@ -2485,7 +2482,7 @@ void testKeyUpdatedShouldNotGetDeleted(BucketLayout 
bucketLayout)
 
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(LONG_EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, rulePrefix, 
null, date.toString(), true);
       Thread.sleep(SERVICE_INTERVAL);
       KeyLifecycleService.getInjector(0).resume();
@@ -2568,7 +2565,7 @@ void testPerformanceWithExpiredKeys(BucketLayout 
bucketLayout)
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       List<OmLCRule> ruleList = new ArrayList<>();
       String rulePrefix = bucketLayout == FILE_SYSTEM_OPTIMIZED ? "" : 
keyPrefix;
       ruleList.add(new 
OmLCRule.Builder().setId(String.valueOf(OBJECT_ID_COUNTER.getAndIncrement()))
@@ -2656,7 +2653,7 @@ void testPerformanceWithNestedDir(BucketLayout 
bucketLayout, String prefix)
           WAIT_CHECK_INTERVAL, 1000);
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       List<OmLCRule> ruleList = new ArrayList<>();
       ruleList.add(new 
OmLCRule.Builder().setId(String.valueOf(OBJECT_ID_COUNTER.getAndIncrement()))
           .setEnabled(false).setPrefix(prefix)
@@ -2726,7 +2723,7 @@ void testListMaxSize(BucketLayout bucketLayout, boolean 
enableTrash) throws IOEx
               LoggerFactory.getLogger(KeyLifecycleService.class));
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       String rulePrefix = bucketLayout == FILE_SYSTEM_OPTIMIZED ? "" : 
keyPrefix;
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, rulePrefix, 
null, date.toString(), true);
 
@@ -2786,7 +2783,7 @@ void testMoveToTrash(BucketLayout bucketLayout, String 
prefix) throws IOExceptio
 
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, "", null, 
date.toString(), true);
 
       try {
@@ -2864,7 +2861,7 @@ void testMoveToTrashWithTrashPrefix(BucketLayout 
bucketLayout, String prefix) th
 
       // create a new policy to test rule with prefix ".Trash/" is ignored 
during lifecycle evaluation
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      final String expiredDate = now.plusSeconds(EXPIRE_SECONDS).toString();
+      final String expiredDate = now.toString();
       assertThrowsExactly(OMException.class, () -> createLifecyclePolicy(
           volumeName, bucketName, bucketLayout, TRASH_PREFIX + OM_KEY_PREFIX, 
null, expiredDate, true));
 
@@ -2875,7 +2872,7 @@ void testMoveToTrashWithTrashPrefix(BucketLayout 
bucketLayout, String prefix) th
 
       // create a new policy to test rule with prefix ".Tras/" is ignored 
during lifecycle evaluation
       now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       createLifecyclePolicy(volumeName, bucketName, FILE_SYSTEM_OPTIMIZED, 
".Tras/", null, date.toString(), true);
 
       GenericTestUtils.LogCapturer log =
@@ -2888,7 +2885,7 @@ void testMoveToTrashWithTrashPrefix(BucketLayout 
bucketLayout, String prefix) th
 
       // create new policy to test trash directory is skipped during lifecycle 
evaluation
       now = ZonedDateTime.now(ZoneOffset.UTC);
-      date = now.plusSeconds(EXPIRE_SECONDS);
+      date = now;
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, "", null, 
date.toString(), true);
 
       GenericTestUtils.waitFor(
@@ -2900,25 +2897,25 @@ public Stream<Arguments> parameters8() {
       return Stream.of(
           // dir3 and keys under dir3 deleted
           arguments("dir1/dir2/dir3/key", null, "dir1/dir2/", 
"dir1/dir2/dir3/", KEY_COUNT, 1, false),
-          // no dir, but keys under dir3 deleted
-          arguments("dir1/dir2/dir3/key", null, "dir1/dir2/", 
"dir1/dir2/dir3/", KEY_COUNT, 0, true),
+          // dir3 and keys under dir3 deleted, even though dir3 is modified 
after the date
+          arguments("dir1/dir2/dir3/key", null, "dir1/dir2/", 
"dir1/dir2/dir3/", KEY_COUNT, 1, true),
           // dir3 dir5, and all keys under dir3 and dir5 deleted
           arguments("dir1/dir2/dir3/key", "dir1/dir2/dir5/key", "dir1/dir2/", 
"dir1/dir2/dir3",
               KEY_COUNT * 2, 2, false),
-          // dir5, and all keys under dir3 and dir5 deleted
-          arguments("dir1/dir2/dir3/key", "dir1/dir2/dir5/key", "dir1/dir2/", 
"dir1/dir2/dir3", KEY_COUNT * 2, 1, true),
+          // dir3 dir5, and all keys under dir3 and dir5 deleted, even though 
dir3 is modified after the date
+          arguments("dir1/dir2/dir3/key", "dir1/dir2/dir5/key", "dir1/dir2/", 
"dir1/dir2/dir3", KEY_COUNT * 2, 2, true),
           // dir2 dir3 dir4 dir5, and all keys under dir3 and dir5 deleted
           arguments("dir1/dir2/dir3/key", "dir1/dir4/dir5/key", "dir1/", 
"dir1/dir2/dir3", KEY_COUNT * 2, 4, false),
-          // dir4 dir5, and all keys under dir3 and dir5 deleted
-          arguments("dir1/dir2/dir3/key", "dir1/dir4/dir5/key", "dir1/", 
"dir1/dir2/dir3", KEY_COUNT * 2, 2, true),
+          // dir2 dir3 dir4 dir5, and all keys under dir3 and dir5 deleted, 
even though dir3 is modified after the date
+          arguments("dir1/dir2/dir3/key", "dir1/dir4/dir5/key", "dir1/", 
"dir1/dir2/dir3", KEY_COUNT * 2, 4, true),
           // dir1 - dir5, and all keys deleted
           arguments("dir1/dir2/dir3/key", "dir1/dir4/dir5/key", "", 
"dir1/dir2/dir3", KEY_COUNT * 2, 5, false),
-          // dir4 dir5, and all keys deleted
-          arguments("dir1/dir2/dir3/key", "dir1/dir4/dir5/key", "", 
"dir1/dir2/dir3", KEY_COUNT * 2, 2, true),
+          // dir1 - dir5, and all keys deleted, even though dir3 is modified 
after the date
+          arguments("dir1/dir2/dir3/key", "dir1/dir4/dir5/key", "", 
"dir1/dir2/dir3", KEY_COUNT * 2, 5, true),
           // dir4 dir5, and all keys under dir5 deleted
           arguments("dir11/dir4/dir5/key", "dir1/dir2/dir3/key", "dir11/", 
"dir11/dir4/dir5", KEY_COUNT, 2, false),
-          // no dir, but all keys under dir11 deleted
-          arguments("dir11/dir4/dir5/key", "dir1/dir2/dir3/key", "dir11/", 
"dir11/dir4/dir5", KEY_COUNT, 0, true));
+          // dir4 dir5, and all keys under dir5 deleted, even though dir5 is 
modified after the date
+          arguments("dir11/dir4/dir5/key", "dir1/dir2/dir3/key", "dir11/", 
"dir11/dir4/dir5", KEY_COUNT, 2, true));
     }
 
     @ParameterizedTest
@@ -2990,12 +2987,7 @@ void testMultipleDirectoriesMatched(String keyPrefix1, 
String keyPrefix2, String
       }
       GenericTestUtils.waitFor(() -> getDeletedDirectoryCount() - 
initialDeletedDirCount == expectedDeletedDirCount,
           WAIT_CHECK_INTERVAL, 10000);
-      if (updateDirModificationTime) {
-        KeyInfoWithVolumeContext directory = getDirectory(volumeName, 
bucketName, dirName);
-        assertNotNull(directory);
-      } else {
-        assertThrows(OMException.class, () -> getDirectory(volumeName, 
bucketName, dirName));
-      }
+      assertThrows(OMException.class, () -> getDirectory(volumeName, 
bucketName, dirName));
       deleteLifecyclePolicy(volumeName, bucketName);
     }
 
@@ -3013,7 +3005,7 @@ void testGetLifecycleServiceStatus() throws Exception {
       
       // Create and inject for test
       createKeys(volumeName, bucketName, FILE_SYSTEM_OPTIMIZED, KEY_COUNT, 1, 
prefix, null);
-      ZonedDateTime date = 
ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = ZonedDateTime.now(ZoneOffset.UTC);
       installInjectors(new FaultInjectorImpl(), new FaultInjectorImpl());
       createLifecyclePolicy(volumeName, bucketName, FILE_SYSTEM_OPTIMIZED, "", 
null, date.toString(), true);
       Thread.sleep(SERVICE_INTERVAL + 100);
@@ -3062,7 +3054,7 @@ void testDisableMoveToTrashDeletesDirectly() throws 
Exception {
       keyLifecycleService.setOzoneTrash(new OzoneTrash(fs, conf, om));
 
       // Expire keys
-      ZonedDateTime date = 
ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = ZonedDateTime.now(ZoneOffset.UTC);
       createLifecyclePolicy(volumeName, bucketName, FILE_SYSTEM_OPTIMIZED, "", 
null, date.toString(), true);
 
       // With move.to.trash disabled, keys should be deleted directly (not 
renamed).
@@ -3100,7 +3092,7 @@ void testMoveToTrashAbortTaskWhenTrashRootPrepareFails() 
throws Exception {
           .setId(String.valueOf(OBJECT_ID_COUNTER.getAndIncrement()))
           .setPrefix("")
           .setAction(new OmLCExpiration.Builder()
-              
.setDate(ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(EXPIRE_SECONDS).toString())
+              .setDate(ZonedDateTime.now(ZoneOffset.UTC).toString())
               .build());
       OmLifecycleConfiguration policy = new OmLifecycleConfiguration.Builder()
           .setVolume(volumeName)
@@ -3673,7 +3665,7 @@ void testBucketDeleted(BucketLayout bucketLayout) throws 
IOException, Interrupte
 
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
 
       FaultInjectorImpl injector = new FaultInjectorImpl();
       installInjectors(injector);
@@ -3729,7 +3721,7 @@ void testKeyDeletedOrRenamed(BucketLayout bucketLayout, 
boolean deleted)
 
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(LONG_EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       createLifecyclePolicy(volumeName, bucketName, bucketLayout, rulePrefix, 
null, date.toString(), true);
       Thread.sleep(SERVICE_INTERVAL);
       KeyLifecycleService.getInjector(0).resume();
@@ -3790,7 +3782,7 @@ void testUnsupportedPrefixForFSO(String prefix, boolean 
createPrefix) {
 
       // create Lifecycle configuration
       ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
-      ZonedDateTime date = now.plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = now;
       OMException omException;
       if (createPrefix) {
         omException = assertThrows(
@@ -4383,7 +4375,7 @@ void testLifecycleDeleteSucceedsWithAclsEnabled()
           () -> getKeyCount(OBJECT_STORE) - initialKeyCount == KEY_COUNT,
           WAIT_CHECK_INTERVAL, 1000);
 
-      ZonedDateTime date = 
ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = ZonedDateTime.now(ZoneOffset.UTC);
       createLifecyclePolicy(volumeName, bucketName, OBJECT_STORE, "key", null, 
date.toString(), true);
 
       GenericTestUtils.waitFor(
@@ -4410,7 +4402,7 @@ void testMoveToTrashWithAclsEnabled()
       FileSystem fs = SecurityUtil.doAsLoginUser(
           (PrivilegedExceptionAction<FileSystem>) () -> new 
TrashOzoneFileSystem(om));
       keyLifecycleService.setOzoneTrash(new OzoneTrash(fs, conf, om));
-      ZonedDateTime date = 
ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(EXPIRE_SECONDS);
+      ZonedDateTime date = ZonedDateTime.now(ZoneOffset.UTC);
       createLifecyclePolicy(volumeName, bucketName, FILE_SYSTEM_OPTIMIZED, "", 
null, date.toString(), true);
       GenericTestUtils.waitFor(
           () -> (metrics.getNumKeyRenamed().value() - initialRenamedKeyCount) 
== KEY_COUNT,


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to