niteshsarda commented on a change in pull request #2188: CLOUDSTACK-10004 : On 
deletion, Vmware volume snapshots are left behind with message 'the snapshot 
has child, can't delete it on the storage'
URL: https://github.com/apache/cloudstack/pull/2188#discussion_r136009249
 
 

 ##########
 File path: 
engine/storage/src/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java
 ##########
 @@ -272,22 +294,18 @@ public SnapshotDataStoreVO 
findOldestSnapshotForVolume(Long volumeId, DataStoreR
     @Override
     @DB
     public SnapshotDataStoreVO findParent(DataStoreRole role, Long storeId, 
Long volumeId) {
-        TransactionLegacy txn = TransactionLegacy.currentTxn();
-        try (
-                PreparedStatement pstmt = txn.prepareStatement(parentSearch);
-            ){
-            pstmt.setLong(1, storeId);
-            pstmt.setString(2, role.toString());
-            pstmt.setLong(3, volumeId);
-            try (ResultSet rs = pstmt.executeQuery();) {
-                while (rs.next()) {
-                    long sid = rs.getLong(1);
-                    long snid = rs.getLong(3);
-                    return findByStoreSnapshot(role, sid, snid);
-                }
-            }
-        } catch (SQLException e) {
-            s_logger.debug("Failed to find parent snapshot: " + e.toString());
+
+        SearchCriteria<SnapshotDataStoreVO> sc = parentSnapshotSearch.create();
+        sc.setParameters("volume_id", volumeId);
+        sc.setParameters("store_role", role.toString());
+        sc.setParameters("state", 
ObjectInDataStoreStateMachine.State.Ready.name());
+        sc.setParameters("store_id", storeId);
+        sc.setJoinParameters("snapshotVOSearch", "hypervisorType", 
Hypervisor.HypervisorType.XenServer);
 
 Review comment:
   @sateesh-chodapuneedi : Verified that parent snapshot ID is only required in 
case of XenServer.
   Also, as per your suggestion changed the code to fetch hypervisor type 
categorically.
   
   Please review latest code.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to