SaketaChalamchala commented on code in PR #9079:
URL: https://github.com/apache/ozone/pull/9079#discussion_r2558384961
##########
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();
Review Comment:
In this chain `fromSnapshot -> fs-1 -> .... -> toSnapshot` doesn't this
logic still return the VersionMeta of `fs-1`? Is there a test case covering
this?
Would it be possible to make the naming conventions in this loop more clear
for readability? And would a `do..while` loop make more sense here? for ex.,
```
parent = child = toSnapshotData
parentVer = childVer = toSnapshotData.getVersion()
numSnapshotsTraversed = 0
do {
if (numSnapshotsTraversed >= maxSnapshotLimit) { // log error and return
null}
child = parent;
childVer = parentVer;
parent = getSnapshotLocalData(...child.getPreviousSnapID());
parentVer = child.getVersionMeta(childVer).getPreviousSnapVersion();
numSnapshotsTraversed++;
} while (parent.getSnapshotId() != fromSnapshotId);
return parent.getVersionMeta(parentVer);
```
--
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]