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


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/SnapshotChainManager.java:
##########
@@ -92,20 +114,38 @@ private void addSnapshotGlobal(UUID snapshotID,
   /**
    * Add snapshot to bucket snapshot chain(path based).
    */
-  private void addSnapshotPath(String snapshotPath,
-                               UUID snapshotID,
-                               UUID prevPathID) throws IOException {
+  private void addSnapshotPath(String snapshotPath, UUID snapshotID,
+                               UUID prevPathID) {
     // On add snapshot, set previous snapshot entry nextSnapshotId = snapshotId
     if (prevPathID != null &&
         ((!snapshotChainByPath.containsKey(snapshotPath)) ||
             (!snapshotChainByPath.get(snapshotPath).containsKey(prevPathID)))) 
{
-      throw new IOException(String.format("Snapshot chain corruption. " +
-              "Previous snapshotId: %s is set for snapshotId: %s but no " +
-              "associated snapshot found in snapshot chain.", prevPathID,
-          snapshotID));
+      throw new IllegalStateException(String.format(
+          "Path Snapshot chain corruption. Previous snapshotId: %s is set " +
+              "for snapshotId: %s but no associated snapshot found in " +
+              "snapshot chain.", prevPathID, snapshotID));
+    }
+
+    if (prevPathID == null && snapshotChainByPath.containsKey(snapshotPath) &&
+        !snapshotChainByPath.get(snapshotPath).isEmpty()) {
+      throw new IllegalStateException(String.format(
+          "Path Snapshot chain corruption. Error while adding snapshot with " +
+              "snapshotId %s with as the first snapshot in snapshot path: " +
+              "%s which already %d snapshots.", snapshotID, snapshotPath,
+          snapshotChainByPath.get(snapshotPath).size()));
     }
 
     if (prevPathID != null && snapshotChainByPath.containsKey(snapshotPath)) {
+      if (snapshotChainByPath.get(snapshotPath).get(prevPathID)
+          .hasNextSnapshotId()) {
+        throw new IllegalStateException(String.format(
+            "Path Snapshot chain corruption. Next snapshotId: %s is already " +
+                "set for snapshotId: %s. Adding snapshot with %s with " +

Review Comment:
   ```suggestion
                   "set for snapshotId: %s. Adding snapshotId: %s with " +
   ```



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