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

ChenSammi 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 c4343421fe2 HDDS-17785. Skip evaluate hsync key in lifecycle task 
(#12028)
c4343421fe2 is described below

commit c4343421fe2fd46d7c63f52b7cda486d853ccc33
Author: Sammi Chen <[email protected]>
AuthorDate: Thu Nov 12 17:01:34 2026 +0800

    HDDS-17785. Skip evaluate hsync key in lifecycle task (#12028)
---
 .../ozone/om/service/KeyLifecycleService.java      | 15 +++++-
 .../ozone/om/service/TestKeyLifecycleService.java  | 54 ++++++++++++++++++++++
 2 files changed, 68 insertions(+), 1 deletion(-)

diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyLifecycleService.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyLifecycleService.java
index 174110ffd6c..efcd54b4e7a 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyLifecycleService.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/KeyLifecycleService.java
@@ -845,6 +845,10 @@ private void evaluateKeyAndDirTable(OmBucketInfo bucket, 
long volumeObjId, Table
             keySetInCache.add(entry.getKey().getCacheKey());
             String keyPath = currentDirPath.isEmpty() ? key.getKeyName() :
                 currentDirPath + OM_KEY_PREFIX + key.getKeyName();
+            // skip hsync'ed keys that are still open for write
+            if (key.isHsync()) {
+              continue;
+            }
             for (OmLCRule rule : ruleList) {
               if (rule.match(key, keyPath)) {
                 // mark key as expired, check next key
@@ -887,8 +891,13 @@ private void evaluateKeyAndDirTable(OmBucketInfo bucket, 
long volumeObjId, Table
             }
             numKeyIterated++;
             numKeysUnderDir++;
+            // skip if not directory's child or a hsync object
+            if (key.getParentObjectID() != currentDirObjID || key.isHsync()) {
+              lastScannedKey = keyValue.getKey();
+              continue;
+            }
             for (OmLCRule rule : ruleList) {
-              if (key.getParentObjectID() == currentDirObjID && 
rule.match(key, keyPath)) {
+              if (rule.match(key, keyPath)) {
                 // mark key as expired, check next key
                 if (keyList.isFull()) {
                   // if keyList is full, send delete request for pending 
deletion keys
@@ -1069,6 +1078,10 @@ private void processKey(OmBucketInfo bucketInfo, 
OmKeyInfo key, List<OmLCRule> r
           key.getKeyName().startsWith(TRASH_PREFIX + 
OzoneConsts.OM_KEY_PREFIX)) {
         return;
       }
+      // skip hsync'ed keys that are still open for write
+      if (key.isHsync()) {
+        return;
+      }
       for (OmLCRule rule : ruleList) {
         if (rule.match(key)) {
           // mark key as expired, check next key
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 4e8a5e40221..21b93ebade8 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
@@ -30,6 +30,7 @@
 import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ADMINISTRATORS;
 import static 
org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_ADMINISTRATORS_WILDCARD;
 import static org.apache.hadoop.ozone.OzoneConsts.ETAG;
+import static org.apache.hadoop.ozone.OzoneConsts.HSYNC_CLIENT_ID;
 import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
 import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_DB_DIRS;
 import static org.apache.hadoop.ozone.om.OmConfig.Keys.ENABLE_FILESYSTEM_PATHS;
@@ -1815,6 +1816,59 @@ void testExpireKeysUnderDirectory(BucketLayout 
bucketLayout) throws IOException,
       deleteLifecyclePolicy(volumeName, bucketName);
     }
 
+    public Stream<Arguments> hsyncKeyParameters() {
+      return Stream.of(
+          arguments(FILE_SYSTEM_OPTIMIZED, false),
+          arguments(OBJECT_STORE, false),
+          arguments(FILE_SYSTEM_OPTIMIZED, true));
+    }
+
+    @ParameterizedTest
+    @MethodSource("hsyncKeyParameters")
+    void testHsyncKeyNotExpired(BucketLayout bucketLayout, boolean 
hsyncInCache) throws Exception {
+      final String volumeName = getTestName();
+      final String bucketName = uniqueObjectName("bucket");
+      // keys are under dir1/dir2, so dir2 is not the rule's prefix directory 
and can expire by itself
+      String keyPrefix = "dir1/dir2/key";
+      long initialDeletedKeyCount = getDeletedKeyCount();
+      long initialKeyCount = getKeyCount(bucketLayout);
+      createKeys(volumeName, bucketName, bucketLayout, KEY_COUNT, 1, 
keyPrefix, null);
+      awaitKeyCacheDrained(bucketLayout, volumeName, bucketName);
+
+      // mark one key as hsync'ed, still open for write
+      Table<String, OmKeyInfo> keyTable = 
metadataManager.getKeyTable(bucketLayout);
+      String hsyncKey = null;
+      try (TableIterator<String, ? extends Table.KeyValue<String, OmKeyInfo>> 
iter = keyTable.iterator()) {
+        while (iter.hasNext() && hsyncKey == null) {
+          Table.KeyValue<String, OmKeyInfo> kv = iter.next();
+          OmKeyInfo keyInfo = kv.getValue();
+          if (volumeName.equals(keyInfo.getVolumeName()) && 
bucketName.equals(keyInfo.getBucketName())) {
+            hsyncKey = kv.getKey();
+            OmKeyInfo hsyncKeyInfo = 
keyInfo.toBuilder().addMetadata(HSYNC_CLIENT_ID, "1").build();
+            if (hsyncInCache) {
+              // The max epoch keeps the double buffer from evicting the cache 
entry before the scan.
+              keyTable.addCacheEntry(new CacheKey<>(hsyncKey), 
CacheValue.get(Long.MAX_VALUE, hsyncKeyInfo));
+            } else {
+              keyTable.put(hsyncKey, hsyncKeyInfo);
+            }
+          }
+        }
+      }
+      assertNotNull(hsyncKey);
+
+      ZonedDateTime date = 
ZonedDateTime.now(ZoneOffset.UTC).plusSeconds(EXPIRE_SECONDS);
+      createLifecyclePolicy(volumeName, bucketName, bucketLayout, "dir1/", 
null, date.toString(), true);
+
+      GenericTestUtils.waitFor(() ->
+          (getDeletedKeyCount() - initialDeletedKeyCount) == KEY_COUNT - 1, 
WAIT_CHECK_INTERVAL, 10000);
+      assertEquals(1, getKeyCount(bucketLayout) - initialKeyCount);
+      assertTrue(keyTable.get(hsyncKey).isHsync());
+      if (bucketLayout == FILE_SYSTEM_OPTIMIZED) {
+        assertFalse(getDirectory(volumeName, bucketName, 
"dir1/dir2").getKeyInfo().isFile());
+      }
+      deleteLifecyclePolicy(volumeName, bucketName);
+    }
+
     public Stream<Arguments> parameters3() {
       return Stream.of(
           arguments("dir1/dir2/dir3/key", "dir1/dir2/dir3/", "dir1/dir2/dir3"),


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

Reply via email to