hemantk-12 commented on code in PR #7193:
URL: https://github.com/apache/ozone/pull/7193#discussion_r1773837757


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotUtils.java:
##########
@@ -178,6 +179,43 @@ public static SnapshotInfo getNextSnapshot(OzoneManager 
ozoneManager,
     return null;
   }
 
+  /**
+   * Get the previous in the snapshot chain.
+   */
+  public static SnapshotInfo getPreviousSnapshot(OzoneManager ozoneManager,
+                                                 SnapshotChainManager 
chainManager,
+                                                 SnapshotInfo snapInfo)
+      throws IOException {
+    UUID previousSnapshotId = getPreviousSnapshotId(snapInfo, chainManager);
+    return previousSnapshotId == null ? null : getSnapshotInfo(ozoneManager, 
chainManager, previousSnapshotId);
+  }
+
+  /**
+   * Get the previous in the snapshot chain.
+   */
+  public static UUID getPreviousSnapshotId(SnapshotInfo snapInfo,
+                                           SnapshotChainManager chainManager)
+      throws IOException {
+    // 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.
+    if (snapInfo == null) {
+      throw new OMException("Snapshot Info is null. Cannot get the next 
snapshot", INVALID_SNAPSHOT_ERROR);

Review Comment:
   The exception message still says `... next snapshot ...` while it should be 
`... previous snapshot ...`, if I'm not wrong.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotUtils.java:
##########
@@ -282,4 +318,34 @@ private static boolean 
isSameAsLatestOmKeyInfo(List<OmKeyInfo> omKeyInfos,
     }
     return false;
   }
+
+  public static SnapshotInfo getLatestSnapshotInfo(String volumeName, String 
bucketName,
+                                                   OzoneManager ozoneManager,
+                                                   SnapshotChainManager 
snapshotChainManager) throws IOException {
+    Optional<UUID> latestPathSnapshot = Optional.ofNullable(
+        getLatestSnapshotId(volumeName, bucketName, snapshotChainManager));
+    return latestPathSnapshot.isPresent() ?
+        getSnapshotInfo(ozoneManager, snapshotChainManager, 
latestPathSnapshot.get()) : null;
+  }
+
+  public static UUID getLatestSnapshotId(String volumeName, String bucketName,
+                                         SnapshotChainManager 
snapshotChainManager) throws IOException {
+    String snapshotPath = volumeName + OM_KEY_PREFIX + bucketName;
+    return snapshotChainManager.getLatestPathSnapshotId(snapshotPath);
+  }
+
+  // Validates previous snapshotId given a snapshotInfo or volumeName & 
bucketName. Incase snapshotInfo is null, this

Review Comment:
   nit:
   ```suggestion
     // Validates the previous snapshotId for a given snapshotInfo. Incase 
snapshotInfo is null, this
   ```



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotUtils.java:
##########
@@ -178,6 +180,40 @@ public static SnapshotInfo getNextSnapshot(OzoneManager 
ozoneManager,
     return null;
   }
 
+  /**
+   * Get the previous snapshot in the snapshot chain.
+   */
+  public static SnapshotInfo getPreviousSnapshot(OzoneManager ozoneManager,
+                                                 SnapshotChainManager 
chainManager,
+                                                 SnapshotInfo snapInfo)
+      throws IOException {
+    UUID previousSnapshotId = getPreviousSnapshotId(snapInfo, chainManager);
+    return previousSnapshotId == null ? null : getSnapshotInfo(ozoneManager, 
chainManager, previousSnapshotId);
+  }
+
+  /**
+   * Get the previous snapshot in the snapshot chain.
+   */
+  private static UUID getPreviousSnapshotId(SnapshotInfo snapInfo, 
SnapshotChainManager chainManager)
+      throws IOException {
+    // 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.
+    if (snapInfo == null) {
+      throw new OMException("Snapshot Info is null. Cannot get the next 
snapshot", INVALID_SNAPSHOT_ERROR);
+    }
+    try {
+      if (chainManager.hasPreviousPathSnapshot(snapInfo.getSnapshotPath(),
+          snapInfo.getSnapshotId())) {
+        return chainManager.previousPathSnapshot(snapInfo.getSnapshotPath(),
+            snapInfo.getSnapshotId());
+      }
+    } catch (NoSuchElementException ignored) {
+

Review Comment:
   nit: maybe move `return null;` inside the catch.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/DirectoryDeletingService.java:
##########
@@ -265,8 +287,13 @@ private boolean previousSnapshotHasDir(
           String prevDbKey = prevDirTableDBKey == null ?
               metadataManager.getOzoneDeletePathDirKey(key) : 
prevDirTableDBKey;
           OmDirectoryInfo prevDirInfo = prevDirTable.get(prevDbKey);
-          return prevDirInfo != null &&
-              prevDirInfo.getObjectID() == deletedDirInfo.getObjectID();
+          //Check the snapshot chain hasn't changed while the checking the 
previous snapshot for the presence of the
+          // deleted directory in the previous snapshot.

Review Comment:
   nit: Please rephase 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: [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]

Reply via email to