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

aswinshakil 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 ad2414697e HDDS-9636. Fix NoSuchElement in OMSnapshotPurgeRequest and 
exit loop early in SnapshotDeletingService (#5554)
ad2414697e is described below

commit ad2414697e5073c8a76434c28b3d5d09fd6dab84
Author: Aswin Shakil Balasubramanian <[email protected]>
AuthorDate: Tue Nov 14 10:12:38 2023 -0800

    HDDS-9636. Fix NoSuchElement in OMSnapshotPurgeRequest and exit loop early 
in SnapshotDeletingService (#5554)
---
 .../ozone/om/service/SnapshotDeletingService.java  |  6 ++++
 .../hadoop/ozone/om/snapshot/SnapshotUtils.java    | 37 ++++++++++++++--------
 2 files changed, 30 insertions(+), 13 deletions(-)

diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/SnapshotDeletingService.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/SnapshotDeletingService.java
index 5aa2fc78a0..cc275b4e8e 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/SnapshotDeletingService.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/SnapshotDeletingService.java
@@ -405,6 +405,12 @@ public class SnapshotDeletingService extends 
AbstractKeyDeletingService {
         while (deletedDirIterator.hasNext()) {
           Table.KeyValue<String, OmKeyInfo> deletedDir =
               deletedDirIterator.next();
+          String deletedDirKey = deletedDir.getKey();
+
+          // Exit for dirs out of snapshot scope.
+          if (!deletedDirKey.startsWith(dbBucketKeyForDir)) {
+            break;
+          }
 
           if (isDirReclaimable(deletedDir, previousDirTable,
               renamedTable, renamedList)) {
diff --git 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotUtils.java
 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotUtils.java
index e9b0aa30fd..89823995d0 100644
--- 
a/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotUtils.java
+++ 
b/hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotUtils.java
@@ -34,6 +34,7 @@ import org.slf4j.LoggerFactory;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.NoSuchElementException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
@@ -143,23 +144,33 @@ public final class SnapshotUtils {
   public static SnapshotInfo getNextActiveSnapshot(SnapshotInfo snapInfo,
       SnapshotChainManager chainManager, OmSnapshotManager omSnapshotManager)
       throws IOException {
-    while (chainManager.hasNextPathSnapshot(snapInfo.getSnapshotPath(),
-        snapInfo.getSnapshotId())) {
 
-      UUID nextPathSnapshot =
-          chainManager.nextPathSnapshot(
-              snapInfo.getSnapshotPath(), snapInfo.getSnapshotId());
+    // If the snapshot is deleted in the previous run, then the in-memory
+    // SnapshotChainManager might throw NoSuchElementException as the snapshot
+    // is removed in-memory but OMDoubleBuffer has not flushed yet.
+    try {
+      while (chainManager.hasNextPathSnapshot(snapInfo.getSnapshotPath(),
+          snapInfo.getSnapshotId())) {
 
-      String tableKey = chainManager.getTableKey(nextPathSnapshot);
-      SnapshotInfo nextSnapshotInfo =
-          omSnapshotManager.getSnapshotInfo(tableKey);
+        UUID nextPathSnapshot =
+            chainManager.nextPathSnapshot(
+                snapInfo.getSnapshotPath(), snapInfo.getSnapshotId());
 
-      if (nextSnapshotInfo.getSnapshotStatus().equals(
-          SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE)) {
-        return nextSnapshotInfo;
-      }
+        String tableKey = chainManager.getTableKey(nextPathSnapshot);
+        SnapshotInfo nextSnapshotInfo =
+            omSnapshotManager.getSnapshotInfo(tableKey);
 
-      snapInfo = nextSnapshotInfo;
+        if (nextSnapshotInfo.getSnapshotStatus().equals(
+            SnapshotInfo.SnapshotStatus.SNAPSHOT_ACTIVE)) {
+          return nextSnapshotInfo;
+        }
+
+        snapInfo = nextSnapshotInfo;
+      }
+    } catch (NoSuchElementException ex) {
+      LOG.error("The snapshot {} is not longer in snapshot chain, It " +
+              "maybe removed in the previous Snapshot purge request.",
+          snapInfo.getTableKey());
     }
     return null;
   }


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

Reply via email to