Skip to content

Commit 5454525

Browse files
committed
Cleanup orphan entries from snapshot store ref for primary storage
1 parent 139aa13 commit 5454525

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDao.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,6 @@ public interface SnapshotDataStoreDao extends GenericDao<SnapshotDataStoreVO, Lo
7171
List<SnapshotDataStoreVO> listAllByVolumeAndDataStore(long volumeId, DataStoreRole role);
7272

7373
List<SnapshotDataStoreVO> listByState(ObjectInDataStoreStateMachine.State... states);
74+
75+
SnapshotDataStoreVO findDestroyedReferenceBySnapshot(long snapshotId, DataStoreRole role);
7476
}

engine/storage/src/main/java/org/apache/cloudstack/storage/image/db/SnapshotDataStoreDaoImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,15 @@ public List<SnapshotDataStoreVO> listByState(ObjectInDataStoreStateMachine.State
461461
return listBy(sc, null);
462462
}
463463

464+
@Override
465+
public SnapshotDataStoreVO findDestroyedReferenceBySnapshot(long snapshotId, DataStoreRole role) {
466+
SearchCriteria<SnapshotDataStoreVO> sc = snapshotSearch.create();
467+
sc.setParameters("snapshot_id", snapshotId);
468+
sc.setParameters("store_role", role);
469+
sc.setParameters("state", State.Destroyed);
470+
return findOneBy(sc);
471+
}
472+
464473
private boolean isSnapshotChainingRequired(long volumeId) {
465474

466475
hypervisorsSupportingSnapshotsChaining.add(Hypervisor.HypervisorType.XenServer);

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ public void cleanupSecondaryStorage(boolean recurring) {
13931393
}
13941394

13951395
_snapshotDao.remove(destroyedSnapshotStoreVO.getSnapshotId());
1396-
SnapshotDataStoreVO snapshotOnPrimary = _snapshotStoreDao.findBySnapshot(destroyedSnapshotStoreVO.getSnapshotId(), DataStoreRole.Primary);
1396+
SnapshotDataStoreVO snapshotOnPrimary = _snapshotStoreDao.findDestroyedReferenceBySnapshot(destroyedSnapshotStoreVO.getSnapshotId(), DataStoreRole.Primary);
13971397
if (snapshotOnPrimary != null) {
13981398
_snapshotStoreDao.remove(snapshotOnPrimary.getId());
13991399
}

0 commit comments

Comments
 (0)