You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ozone.apache.org by "smengcl (via GitHub)" <gi...@apache.org> on 2026/05/30 04:37:09 UTC

[PR] HDDS-15428. Remove purged snapshot YAMLs in one run [ozone]

smengcl opened a new pull request, #10387:
URL: https://github.com/apache/ozone/pull/10387

   Generated-by: Codex (GPT-5.4)
   
   ## What changes were proposed in this pull request?
   
   This is an optimization. OM orphan snapshot cleanup could start from an older queued snapshot before a newer descendant. In linear snapshot chains, that caused unnecessary early ancestor checks. The newest descendant could still make cleanup complete in the same drain, but older snapshots were revisited later in that drain after they became eligible.
   
   - order the initial orphan-cleanup list by snapshot creation time descending when snapshot metadata is available
   - keep the existing queue-based ancestor cascade for newly eligible snapshots discovered during the drain
   - add debug/info logging
   
   Before this change
   - queued seeds: S2, S3. snapshot created in the same bucket in order of S1 to S3
   - OM could check S2 first, find nothing removable yet
   - OM then checked S3, which made S2 eligible
   - S2 had to be revisited later in the same drain, or left queued for a later run depending on state
   
   After the change
   - initial seeds are ordered newest-first: S3, S2
   - OM checks S3 first and immediately cascades to S2 and then older ancestors as they become eligible
   - in a fully purged multiple snapshot chain, all YAMLs are removed in a single drain and each snapshot is checked once
   
   ## What is the link to the Apache JIRA
   
   https://issues.apache.org/jira/browse/HDDS-15428
   
   ## How was this patch tested?
   
   - Added regression coverage
   - Added six-snapshot chain test case to verify the optimization works


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-15428. Remove purged snapshot YAMLs in one run [ozone]

Posted by "SaketaChalamchala (via GitHub)" <gi...@apache.org>.
SaketaChalamchala commented on code in PR #10387:
URL: https://github.com/apache/ozone/pull/10387#discussion_r3583100892


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OmSnapshotLocalDataManager.java:
##########
@@ -392,25 +392,135 @@ private void init(OzoneConfiguration configuration, SnapshotChainManager chainMa
 
   }
 
-  private void checkOrphanSnapshotVersions(OMMetadataManager metadataManager, SnapshotChainManager chainManager)
+  /**
+   * Drains the snapshots currently queued in {@link #snapshotToBeCheckedForOrphans}.
+   * Each queued snapshot becomes a seed for a same-run ancestor cascade.
+   */
+  private void checkQueuedOrphanSnapshotVersions(OMMetadataManager metadataManager,
+      SnapshotChainManager chainManager)
       throws IOException {
-    for (Map.Entry<UUID, Integer> entry : snapshotToBeCheckedForOrphans.entrySet()) {
-      UUID snapshotId = entry.getKey();
-      int countBeforeCheck = entry.getValue();
-      checkOrphanSnapshotVersions(metadataManager, chainManager, snapshotId);
-      decrementOrphanCheckCount(snapshotId, countBeforeCheck);
+    Set<UUID> processedSnapshotIds = new HashSet<>();
+    List<UUID> queuedSnapshotIds = getQueuedSnapshotIdsByCreationTimeDesc(metadataManager, chainManager);

Review Comment:
   Using `creationTime` may be a good starting point. For purged snapshot it's most likely that `snapshotInfo` is removed from `snapshotInfoTable` by the time the YAML is processed for cleaning so `creationTime` will be null for those snapshots in that case. 
   Also in rare cases `creationTime` may be vulnerable to clock skew between OMs. 
   For ex, 
    - S1 `creationTime` is T3 
    - Leader change happens to an OM that is behind previous leader
    - S2 is created with `creationTime` T2. 
   
   What do you think about adding snapshot's `creationTxnInfo` at the time of YAML creation and using that to order the snapshots to check?



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-15428. Remove purged snapshot YAMLs in one run [ozone]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #10387: HDDS-15428. Remove purged snapshot YAMLs in one run
URL: https://github.com/apache/ozone/pull/10387


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-15428. Remove purged snapshot YAMLs in one run [ozone]

Posted by "swamirishi (via GitHub)" <gi...@apache.org>.
swamirishi commented on code in PR #10387:
URL: https://github.com/apache/ozone/pull/10387#discussion_r3386715651


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OmSnapshotLocalDataManager.java:
##########
@@ -392,25 +392,135 @@ private void init(OzoneConfiguration configuration, SnapshotChainManager chainMa
 
   }
 
-  private void checkOrphanSnapshotVersions(OMMetadataManager metadataManager, SnapshotChainManager chainManager)
+  /**
+   * Drains the snapshots currently queued in {@link #snapshotToBeCheckedForOrphans}.
+   * Each queued snapshot becomes a seed for a same-run ancestor cascade.
+   */
+  private void checkQueuedOrphanSnapshotVersions(OMMetadataManager metadataManager,
+      SnapshotChainManager chainManager)
       throws IOException {
-    for (Map.Entry<UUID, Integer> entry : snapshotToBeCheckedForOrphans.entrySet()) {
-      UUID snapshotId = entry.getKey();
-      int countBeforeCheck = entry.getValue();
-      checkOrphanSnapshotVersions(metadataManager, chainManager, snapshotId);
-      decrementOrphanCheckCount(snapshotId, countBeforeCheck);
+    Set<UUID> processedSnapshotIds = new HashSet<>();
+    List<UUID> queuedSnapshotIds = getQueuedSnapshotIdsByCreationTimeDesc(metadataManager, chainManager);

Review Comment:
   I would suggest we can directly use a stack here to order the UUIDs as the order of addition of potential orphans would be LIFO for the algo removing the need for this sort function making it more efficient. So we can have a separate linked list which maintains the order of UUID entered and we can directly iterate the linked list instead of snapshotToBeCheckedForOrphans.entrySet() reaping the same result making this patch much smaller. 



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-15428. Remove purged snapshot YAMLs in one run [ozone]

Posted by "SaketaChalamchala (via GitHub)" <gi...@apache.org>.
SaketaChalamchala commented on code in PR #10387:
URL: https://github.com/apache/ozone/pull/10387#discussion_r3583231678


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OmSnapshotLocalDataManager.java:
##########
@@ -392,25 +392,135 @@ private void init(OzoneConfiguration configuration, SnapshotChainManager chainMa
 
   }
 
-  private void checkOrphanSnapshotVersions(OMMetadataManager metadataManager, SnapshotChainManager chainManager)
+  /**
+   * Drains the snapshots currently queued in {@link #snapshotToBeCheckedForOrphans}.
+   * Each queued snapshot becomes a seed for a same-run ancestor cascade.
+   */
+  private void checkQueuedOrphanSnapshotVersions(OMMetadataManager metadataManager,
+      SnapshotChainManager chainManager)
       throws IOException {
-    for (Map.Entry<UUID, Integer> entry : snapshotToBeCheckedForOrphans.entrySet()) {
-      UUID snapshotId = entry.getKey();
-      int countBeforeCheck = entry.getValue();
-      checkOrphanSnapshotVersions(metadataManager, chainManager, snapshotId);
-      decrementOrphanCheckCount(snapshotId, countBeforeCheck);
+    Set<UUID> processedSnapshotIds = new HashSet<>();
+    List<UUID> queuedSnapshotIds = getQueuedSnapshotIdsByCreationTimeDesc(metadataManager, chainManager);
+    if (queuedSnapshotIds.isEmpty()) {
+      return;
+    }
+    LOG.info("Draining orphan snapshot cleanup queue with {} seed snapshots",
+        queuedSnapshotIds.size());
+    for (UUID snapshotId : queuedSnapshotIds) {
+      cascadeOrphanSnapshotChecksFrom(metadataManager, chainManager, snapshotId, processedSnapshotIds);
     }
+    LOG.debug("Finished orphan snapshot cleanup drain; {} snapshots remain queued for future runs",
+        snapshotToBeCheckedForOrphans.size());
   }
 
-  @VisibleForTesting
-  void checkOrphanSnapshotVersions(OMMetadataManager metadataManager, SnapshotChainManager chainManager,
-      UUID snapshotId) throws IOException {
+  /**
+   * Sorts the currently queued snapshot ids from newest to oldest using snapshot creation
+   * time when that metadata is available. This is only a seed-order optimization for the
+   * outer batch drain; the inner cascade still handles ancestors discovered during the run.
+   */
+  private List<UUID> getQueuedSnapshotIdsByCreationTimeDesc(OMMetadataManager metadataManager,
+      SnapshotChainManager chainManager) throws IOException {
+    List<UUID> snapshotIds = new ArrayList<>(snapshotToBeCheckedForOrphans.keySet());
+    if (chainManager == null) {
+      LOG.debug("Snapshot chain manager unavailable; using queued orphan snapshot iteration order for {} snapshots",
+          snapshotIds.size());
+      return snapshotIds;
+    }
+    Table<String, SnapshotInfo> snapshotInfoTable = metadataManager.getSnapshotInfoTable();
+    if (snapshotInfoTable == null) {
+      LOG.debug("Snapshot info table unavailable; using queued orphan snapshot iteration order for {} snapshots",
+          snapshotIds.size());
+      return snapshotIds;
+    }
+
+    Map<UUID, Long> creationTimeBySnapshotId = new HashMap<>();
+    for (UUID snapshotId : snapshotIds) {
+      String tableKey = chainManager.getTableKey(snapshotId);
+      if (tableKey == null) {
+        LOG.debug("Snapshot {} is queued for orphan cleanup but has no snapshot info table key; "
+                + "leaving it in fallback iteration order", snapshotId);
+        continue;
+      }
+      SnapshotInfo snapshotInfo = snapshotInfoTable.get(tableKey);
+      if (snapshotInfo != null) {
+        creationTimeBySnapshotId.put(snapshotId, snapshotInfo.getCreationTime());
+      } else {
+        LOG.debug("Snapshot {} is queued for orphan cleanup but snapshot info is missing for table key {};"
+                + " leaving it in fallback iteration order", snapshotId, tableKey);
+      }
+    }
+
+    // Prefer newer queued snapshots as seeds so descendants already waiting in the batch
+    // are more likely to run before their ancestors.
+    snapshotIds.sort(Comparator.comparingLong(
+        snapshotId -> creationTimeBySnapshotId.getOrDefault(snapshotId, Long.MIN_VALUE)).reversed());
+    LOG.debug("Ordered {} queued orphan snapshot seeds by creation time using metadata for {} snapshots",
+        snapshotIds.size(), creationTimeBySnapshotId.size());
+    return snapshotIds;
+  }
+
+  /**
+   * Runs orphan cleanup starting from {@code snapshotId} and cascades toward older snapshots
+   * in the same call whenever removing data from the current snapshot may have unblocked its
+   * {@code previousSnapshotId}.
+   *
+   * <p>Callers that want an isolated one-off check should pass a fresh empty
+   * {@code processedSnapshotIds} set. {@link #checkQueuedOrphanSnapshotVersions(
+   * OMMetadataManager, SnapshotChainManager)} passes a shared set for the whole scheduler drain
+   * so a snapshot re-queued for retry is deferred to the next run instead of being checked twice
+   * in the same batch.
+   *
+   * <p>For example, if the chain is {@code S3 -> S2 -> S1} and checking {@code S3} removes
+   * orphan versions that make {@code S2} eligible, a single call seeded with {@code S3}
+   * will check {@code S3}, then {@code S2}, then {@code S1} in that order.
+   */
+  void cascadeOrphanSnapshotChecksFrom(OMMetadataManager metadataManager,
+      SnapshotChainManager chainManager, UUID snapshotId, Set<UUID> processedSnapshotIds)
+      throws IOException {
+    for (UUID currentSnapshotId = snapshotId; currentSnapshotId != null;) {
+      // A descendant processed earlier in the same drain may already have checked
+      // this snapshot as an ancestor. If it re-queued itself for retry, leave that
+      // retry for the next scheduler iteration instead of checking it twice now.
+      if (!processedSnapshotIds.add(currentSnapshotId)) {
+        LOG.debug("Skipping snapshot {} because it was already processed earlier in this orphan cleanup pass",
+            currentSnapshotId);
+        return;

Review Comment:
   Consider this scenario: 
   1. this is the snapshot chain S3 -> S2 -> prev_chain and the dependency is 
      S3.v1 -> S2.v1, 
      S2.v1 -> prev_chain.v
   2. S2 is purged but YAML not deleted, prev_chain is changed and defrag runs. 
       Dependency chain is 
       S3.v1 -> S2.v1, 
       S2.v1 -> prev_chain.v, S2.v2 -> prev_chain.v'
   3. S4 is created and defragged and purged before YAMLs is cleaned. 
       Dependency chain is 
       S3.v1 -> S2.v1, 
       S2.v1 -> prev_chain.v, S2.v2 -> prev_chain.v'
       S4.v1 -> S2.v2
   
   The cleanup queue is now {S4, S3, S2, ...} if ordered by descending order of snapshot creation.
   When processing S4, S4 yaml is removed and the cascade reaches S2 and removes S2.v2. In this case, S2 is marked as processed.
   When S3 is processed and removes it's YAML. In the same run when cascading S2.v1(and other prev_chain versions) is eligible for removal but, the cleanup skips it and returns. 
   
   Would tracking processed versions for each snapshot be a better optimization?



-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-15428. Remove purged snapshot YAMLs in one run [ozone]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10387:
URL: https://github.com/apache/ozone/pull/10387#issuecomment-5186074565

   This PR has been marked as stale due to 21 days of inactivity. Please comment or remove the stale label to keep it open. Otherwise, it will be automatically closed in 7 days.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org


Re: [PR] HDDS-15428. Remove purged snapshot YAMLs in one run [ozone]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #10387:
URL: https://github.com/apache/ozone/pull/10387#issuecomment-5274289302

   Thank you for your contribution. This PR is being closed due to inactivity. Please contact a maintainer if you would like to reopen it.


-- 
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: issues-unsubscribe@ozone.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@ozone.apache.org
For additional commands, e-mail: issues-help@ozone.apache.org