JoaoJandre commented on code in PR #12086:
URL: https://github.com/apache/cloudstack/pull/12086#discussion_r3154004852


##########
engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/DataMigrationUtility.java:
##########
@@ -297,16 +311,30 @@ protected List<DataObject> 
getAllReadySnapshotsAndChains(DataStore srcDataStore,
                 logger.debug("Not migrating snapshot [{}] because its 
hypervisor type is simulator.", snapshot);
                 continue;
             }
-            if (snapshot.getParentSnapshotId() != 0) {
+            boolean isKvmIncrementalSnapshot = snapshot.getKvmCheckpointPath() 
!= null;
+            if (snapshot.getParentSnapshotId() != 0 && 
!isKvmIncrementalSnapshot) {
                 continue; // The child snapshot will be migrated in the for 
loop below.
             }
-            SnapshotInfo snap = 
snapshotFactory.getSnapshot(snapshotVO.getSnapshotId(), 
snapshot.getDataStoreId(), snapshot.getRole());
-            if (snap == null) {
-                logger.debug("Not migrating snapshot [{}] because we could not 
get its information.", snapshot);
+            if (snapshotIdsAlreadyInChain.contains(snapshotVO.getId())) {
+                logger.debug("Skipping snapshot {} since it is already in 
snapshot chain.", snapshot);
                 continue;
             }
-            files.add(snap);
-            idsForMigration.add(snapshotId);
+
+            if (isKvmIncrementalSnapshot) {
+                List<SnapshotInfo> kvmIncrementalSnapshotChain = 
createKvmIncrementalSnapshotChain(snapshot);
+                SnapshotInfo parent = kvmIncrementalSnapshotChain.get(0);
+                
snapshotIdsAlreadyInChain.addAll(kvmIncrementalSnapshotChain.stream().map(DataObject::getId).collect(Collectors.toSet()));
+                snapshotChains.put(parent, new 
Pair<>(kvmIncrementalSnapshotChain, 
getTotalChainSize(kvmIncrementalSnapshotChain.stream().filter(snapInfo -> 
snapshotIdsToMigrate.contains(snapInfo.getId())).collect(Collectors.toList()))));
+                files.add(parent);
+            } else {

Review Comment:
   I reread the code and we actually add the first snapshot in the chain. It 
may or may not be the parent, it may be the snapshot itself, if the chain only 
contains one snapshot.
   I would rename the variable to `firstSnapshotInTheChain` or something like 
that, just for clarity. Functionally its the same.



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

Reply via email to