Skip to content

Commit f843c53

Browse files
authored
Fix snapshots garbage collection (#4188)
* Cleanup orphan entries from snapshot store ref for primary storage * Add debug message
1 parent affd010 commit f843c53

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,8 +1393,11 @@ 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) {
1398+
if (s_logger.isDebugEnabled()) {
1399+
s_logger.debug("Deleting snapshot on primary store reference DB entry: " + snapshotOnPrimary);
1400+
}
13981401
_snapshotStoreDao.remove(snapshotOnPrimary.getId());
13991402
}
14001403
_snapshotStoreDao.remove(destroyedSnapshotStoreVO.getId());

0 commit comments

Comments
 (0)