shwstppr commented on code in PR #7873: URL: https://github.com/apache/cloudstack/pull/7873#discussion_r1356094997
########## plugins/storage/volume/storpool/src/main/java/org/apache/cloudstack/storage/snapshot/StorPoolSnapshotStrategy.java: ########## @@ -233,46 +314,26 @@ private boolean deleteSnapshotFromDb(Long snapshotId) { if (!Snapshot.State.BackedUp.equals(snapshotVO.getState()) && !Snapshot.State.Error.equals(snapshotVO.getState()) && !Snapshot.State.Destroying.equals(snapshotVO.getState())) { - throw new InvalidParameterValueException("Can't delete snapshotshot " + snapshotId + " due to it is in " + snapshotVO.getState() + " Status"); - } - - SnapshotInfo snapshotOnImage = snapshotDataFactory.getSnapshot(snapshotId, DataStoreRole.Image); - if (snapshotOnImage == null) { - log.debug("Can't find snapshot on backup storage, delete it in db"); - _snapshotDao.remove(snapshotId); - return true; + throw new InvalidParameterValueException("Can't delete snapshot " + snapshotId + " due to it is in " + snapshotVO.getState() + " Status"); } - - SnapshotObject obj = (SnapshotObject)snapshotOnImage; - try { - obj.processEvent(Snapshot.Event.DestroyRequested); - } catch (NoTransitionException e) { - log.debug("Failed to set the state to destroying: ", e); - return false; + List<SnapshotDataStoreVO> storeRefs = _snapshotStoreDao.listReadyBySnapshot(snapshotId, DataStoreRole.Image); + if (zoneId != null) { + storeRefs.removeIf(ref -> !zoneId.equals(dataStoreMgr.getStoreZoneId(ref.getDataStoreId(), ref.getRole()))); } - - try { - boolean result = deleteSnapshotChain(snapshotOnImage); - obj.processEvent(Snapshot.Event.OperationSucceeded); - if (result) { - SnapshotDataStoreVO snapshotOnPrimary = _snapshotStoreDao.findBySnapshot(snapshotId, DataStoreRole.Primary); - if (snapshotOnPrimary != null) { - snapshotOnPrimary.setState(State.Destroyed); - _snapshotStoreDao.update(snapshotOnPrimary.getId(), snapshotOnPrimary); - } + for (SnapshotDataStoreVO ref : storeRefs) { + if (!deleteSnapshotOnImageAndPrimary(snapshotId, dataStoreMgr.getDataStore(ref.getId(), ref.getRole()))) { Review Comment: Thanks @slavkap -- 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: commits-unsubscr...@cloudstack.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org