SaketaChalamchala commented on code in PR #9079:
URL: https://github.com/apache/ozone/pull/9079#discussion_r2558399573


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/snapshot/SnapshotDiffManager.java:
##########
@@ -1223,6 +1273,81 @@ Set<String> getDeltaFiles(OmSnapshot fromSnapshot,
             toSnapshot.getSnapshotTableKey()));
   }
 
+  /**
+   * Resolve the VersionMeta of the ancestor snapshot (fromSnapshotId)
+   * that the given snapshot (toSnapshot) was built on.
+   * Traverses the snapshot chain backwards using prevSnapId.
+   *
+   * @param toSnapshot the target snapshot.
+   * @param fromSnapshotId UUID of the source snapshot.
+   * @return the resolved VersionMeta of the source that was used to build the 
target.
+   */
+  private OmSnapshotLocalData.VersionMeta resolveBaseVersionMeta(
+      OmSnapshotLocalData toSnapshot,
+      UUID fromSnapshotId) throws IOException {
+    OmMetadataManagerImpl metadataManager =
+        (OmMetadataManagerImpl) ozoneManager.getMetadataManager();
+    // Start walking back from the child snapshot
+    OmSnapshotLocalData child = toSnapshot;
+    int numSnapshotsTraversed = 0;
+    while (numSnapshotsTraversed <= maxSnapshotLimit && 
!child.getPreviousSnapshotId().equals(fromSnapshotId)) {
+      UUID parentId = child.getPreviousSnapshotId();
+      // Load the parent snapshot in the chain
+      child = getSnapshotLocalData(
+          getSnapshotInfo(ozoneManager,
+              metadataManager.getSnapshotChainManager(),
+              parentId));
+      numSnapshotsTraversed++;
+    }
+    if (numSnapshotsTraversed > maxSnapshotLimit) {
+      LOG.error("Exceeded the traversal limit of {} while finding the 
VersionMeta of the fromSnapshot : {}" +
+          " that the toSnapshot was built on.", maxSnapshotLimit, 
fromSnapshotId);
+      return null;
+    }
+    SnapshotInfo snapshotInfo =
+        getSnapshotInfo(ozoneManager, 
metadataManager.getSnapshotChainManager(), fromSnapshotId);
+    OmSnapshotLocalData fromSnapshot = getSnapshotLocalData(snapshotInfo);
+    // Get the version that the child was built from
+    OmSnapshotLocalData.VersionMeta childVersionMeta = 
child.getVersionSstFileInfos().get(child.getVersion());
+    int versionUsedWhenBuildingChild = 
childVersionMeta.getPreviousSnapshotVersion();
+    return 
fromSnapshot.getVersionSstFileInfos().get(versionUsedWhenBuildingChild);
+  }
+
+  /**
+   * Calculates the symmetric difference of SST files between two version 
metadata.
+   * Returns a list of SST file names that are present in one snapshot but not 
in the other,
+   * i.e., the symmetric difference between the two sets of SST files.
+   *
+   * @param fromSnapVersionMeta Version metadata from the first snapshot; 
provides the set of SST files for comparison.
+   * @param toSnapVersionMeta Version metadata from the second snapshot; 
provides the set of SST files for comparison.
+   * @return List of SST file names that are present in only one of the two 
snapshots (symmetric difference).
+   */
+  private List<String> calculateDiffFiles(OmSnapshotLocalData.VersionMeta 
fromSnapVersionMeta,
+                                          OmSnapshotLocalData.VersionMeta 
toSnapVersionMeta) {
+    // Extract SST file names from both snapshots
+    Set<String> fromSnapSstFileNames = 
fromSnapVersionMeta.getSstFiles().stream()
+        .map(SstFileInfo::getFileName)
+        .collect(Collectors.toSet());
+    
+    Set<String> toSnapSstFileNames = toSnapVersionMeta.getSstFiles().stream()
+        .map(SstFileInfo::getFileName)
+        .collect(Collectors.toSet());
+
+    List<String> diffFiles = new ArrayList<>();
+    
+    // Files in fromSnapshot but NOT in toSnapshot
+    diffFiles.addAll(fromSnapSstFileNames.stream()
+        .filter(file -> !toSnapSstFileNames.contains(file))
+        .collect(Collectors.toList()));

Review Comment:
   Why would we need this filter if `toSnap` is always built from `fromSnap`. 
Wouldn't `toSnap = fromSnap + diff`. In that case, `fromSnap` should never 
contain SST files that are not in `toSNap` making this filter unnecessary?



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