aswinshakil commented on code in PR #7193:
URL: https://github.com/apache/ozone/pull/7193#discussion_r1772710862


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/AbstractKeyDeletingService.java:
##########
@@ -203,6 +202,15 @@ private int 
submitPurgeKeysRequest(List<DeleteBlockGroupResult> results,
     if (snapTableKey != null) {
       purgeKeysRequest.setSnapshotTableKey(snapTableKey);
     }
+    OzoneManagerProtocolProtos.NullableUUID.Builder 
expectedPreviousSnapshotNullableUUID =
+        OzoneManagerProtocolProtos.NullableUUID.newBuilder();
+    if (expectedPreviousSnapshotId != null) {
+      
expectedPreviousSnapshotNullableUUID.setUuid(HddsUtils.toProtobuf(expectedPreviousSnapshotId));
+    }
+
+    if (expectedPreviousSnapshotId != null) {

Review Comment:
   This can be in the same if statement as above.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/service/SnapshotDirectoryCleaningService.java:
##########
@@ -143,11 +144,11 @@ public BackgroundTaskResult call() {
           <String, SnapshotInfo>> iterator = snapshotInfoTable.iterator()) {
 
         while (iterator.hasNext()) {
-          SnapshotInfo currSnapInfo = iterator.next().getValue();
+          SnapshotInfo currSnapInfo = 
snapshotInfoTable.get(iterator.next().getKey());

Review Comment:
   We are already initiating an iterator, why do we need to do this? 



##########
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,

Review Comment:
   ```suggestion
     public static UUID getLatestPathSnapshotId(String volumeName, String 
bucketName,
   ```



##########
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:
   We need to log an error here similar to `getNextSnapshot()`



-- 
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