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


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotUtils.java:
##########
@@ -242,4 +275,47 @@ public static String 
getOzonePathKeyForFso(OMMetadataManager metadataManager,
     final long bucketId = metadataManager.getBucketId(volumeName, bucketName);
     return OM_KEY_PREFIX + volumeId + OM_KEY_PREFIX + bucketId + OM_KEY_PREFIX;
   }
+
+  public static SnapshotInfo getLatestGlobalSnapshotInfo(OzoneManager 
ozoneManager,
+                                                         SnapshotChainManager 
snapshotChainManager) throws IOException {
+    Optional<UUID> latestGlobalSnapshot  = 
Optional.ofNullable(snapshotChainManager.getLatestGlobalSnapshotId());
+    return latestGlobalSnapshot.isPresent() ? getSnapshotInfo(ozoneManager, 
snapshotChainManager,
+        latestGlobalSnapshot.get()) : null;
+  }
+
+  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
+  // would be considered as AOS and previous snapshot becomes the latest 
snapshot in the global snapshot chain.
+  // Would throw OMException if validation fails otherwise function would pass.
+  public static void validatePreviousSnapshotId(SnapshotInfo snapshotInfo,
+                                                SnapshotChainManager 
snapshotChainManager,
+                                                UUID 
expectedPreviousSnapshotId) throws IOException {
+    try {
+      UUID previousSnapshotId = snapshotInfo == null ? 
snapshotChainManager.getLatestGlobalSnapshotId() :

Review Comment:
   Yeah for AOS expectedPreviousSnapshotId would be null. So the validation 
would succeed. 



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