jojochuang commented on code in PR #9141:
URL: https://github.com/apache/ozone/pull/9141#discussion_r2430431161


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OmSnapshotLocalDataManager.java:
##########
@@ -113,4 +229,73 @@ public void close() {
       }
     }
   }
+
+  static final class LocalDataVersionNode {
+    private UUID snapshotId;
+    private int version;
+    private UUID previousSnapshotId;
+    private int previousSnapshotVersion;

Review Comment:
   all of these can be made final



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OmSnapshotLocalDataManager.java:
##########
@@ -95,14 +123,102 @@ public void createNewOmSnapshotLocalDataFile(RDBStore 
snapshotStore, SnapshotInf
   }
 
   public OmSnapshotLocalData getOmSnapshotLocalData(SnapshotInfo snapshotInfo) 
throws IOException {
-    Path snapshotLocalDataPath = 
Paths.get(getSnapshotLocalPropertyYamlPath(snapshotInfo));
-    return snapshotLocalDataSerializer.load(snapshotLocalDataPath.toFile());
+    return getOmSnapshotLocalData(snapshotInfo.getSnapshotId());
+  }
+
+  public OmSnapshotLocalData getOmSnapshotLocalData(UUID snapshotId) throws 
IOException {
+    Path snapshotLocalDataPath = 
Paths.get(getSnapshotLocalPropertyYamlPath(snapshotId));
+    OmSnapshotLocalData snapshotLocalData = 
snapshotLocalDataSerializer.load(snapshotLocalDataPath.toFile());
+    if (!Objects.equals(snapshotLocalData.getSnapshotId(), snapshotId)) {
+      throw new IOException("SnapshotId in path : " + snapshotLocalDataPath + 
" contains snapshotLocalData " +
+          "corresponding to snapshotId " + snapshotLocalData.getSnapshotId() + 
". Expected snapshotId " + snapshotId);
+    }
+    return snapshotLocalData;
   }
 
   public OmSnapshotLocalData getOmSnapshotLocalData(File snapshotDataPath) 
throws IOException {
     return snapshotLocalDataSerializer.load(snapshotDataPath);
   }
 
+  private LocalDataVersionNode getVersionNode(UUID snapshotId, int version) {
+    if (!versionNodeMap.containsKey(snapshotId)) {
+      return null;
+    }
+    return versionNodeMap.get(snapshotId).getVersionNode(version);
+  }
+
+  private boolean addSnapshotVersionMeta(UUID snapshotId, SnapshotVersionsMeta 
snapshotVersionsMeta)

Review Comment:
   return value not used.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/OmSnapshotLocalDataYaml.java:
##########
@@ -165,7 +165,8 @@ public Object construct(Node node) {
         MappingNode mnode = (MappingNode) node;
         Map<Object, Object> nodes = constructMapping(mnode);
         UUID snapId = UUID.fromString((String) 
nodes.get(OzoneConsts.OM_SLD_SNAP_ID));
-        UUID prevSnapId = UUID.fromString((String) 
nodes.get(OzoneConsts.OM_SLD_PREV_SNAP_ID));
+        String prevNodeStr = (String) 
nodes.get(OzoneConsts.OM_SLD_PREV_SNAP_ID);
+        UUID prevSnapId = prevNodeStr == null ? null : 
UUID.fromString(prevNodeStr);

Review Comment:
   when would previousSnapshotId not defined? When it's the latest?



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OmSnapshotLocalDataManager.java:
##########
@@ -113,4 +229,73 @@ public void close() {
       }
     }
   }
+
+  static final class LocalDataVersionNode {
+    private UUID snapshotId;
+    private int version;
+    private UUID previousSnapshotId;
+    private int previousSnapshotVersion;
+
+    private LocalDataVersionNode(UUID snapshotId, int version, UUID 
previousSnapshotId, int previousSnapshotVersion) {
+      this.previousSnapshotId = previousSnapshotId;
+      this.previousSnapshotVersion = previousSnapshotVersion;
+      this.snapshotId = snapshotId;
+      this.version = version;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      if (!(o instanceof LocalDataVersionNode)) {
+        return false;
+      }
+
+      LocalDataVersionNode that = (LocalDataVersionNode) o;
+      return version == that.version && previousSnapshotVersion == 
that.previousSnapshotVersion &&
+          snapshotId.equals(that.snapshotId) && 
Objects.equals(previousSnapshotId, that.previousSnapshotId);
+    }
+
+    @Override
+    public int hashCode() {
+      return Objects.hash(snapshotId, version, previousSnapshotId, 
previousSnapshotVersion);
+    }
+  }
+
+  static final class SnapshotVersionsMeta {
+    private final UUID previousSnapshotId;
+    private final Map<Integer, LocalDataVersionNode> snapshotVersions;
+    private int version;

Review Comment:
   version's not used anywhere.



##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/OmSnapshotLocalDataManager.java:
##########
@@ -95,14 +123,102 @@ public void createNewOmSnapshotLocalDataFile(RDBStore 
snapshotStore, SnapshotInf
   }
 
   public OmSnapshotLocalData getOmSnapshotLocalData(SnapshotInfo snapshotInfo) 
throws IOException {
-    Path snapshotLocalDataPath = 
Paths.get(getSnapshotLocalPropertyYamlPath(snapshotInfo));
-    return snapshotLocalDataSerializer.load(snapshotLocalDataPath.toFile());
+    return getOmSnapshotLocalData(snapshotInfo.getSnapshotId());
+  }
+
+  public OmSnapshotLocalData getOmSnapshotLocalData(UUID snapshotId) throws 
IOException {
+    Path snapshotLocalDataPath = 
Paths.get(getSnapshotLocalPropertyYamlPath(snapshotId));
+    OmSnapshotLocalData snapshotLocalData = 
snapshotLocalDataSerializer.load(snapshotLocalDataPath.toFile());
+    if (!Objects.equals(snapshotLocalData.getSnapshotId(), snapshotId)) {
+      throw new IOException("SnapshotId in path : " + snapshotLocalDataPath + 
" contains snapshotLocalData " +
+          "corresponding to snapshotId " + snapshotLocalData.getSnapshotId() + 
". Expected snapshotId " + snapshotId);
+    }
+    return snapshotLocalData;
   }
 
   public OmSnapshotLocalData getOmSnapshotLocalData(File snapshotDataPath) 
throws IOException {
     return snapshotLocalDataSerializer.load(snapshotDataPath);
   }
 
+  private LocalDataVersionNode getVersionNode(UUID snapshotId, int version) {
+    if (!versionNodeMap.containsKey(snapshotId)) {
+      return null;
+    }
+    return versionNodeMap.get(snapshotId).getVersionNode(version);
+  }
+
+  private boolean addSnapshotVersionMeta(UUID snapshotId, SnapshotVersionsMeta 
snapshotVersionsMeta)
+      throws IOException {
+    if (!versionNodeMap.containsKey(snapshotId)) {

Review Comment:
   if the map doesn't contain the snapshot, isn't it an error?



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