Fix snapshots garbage collection (#4188)

* Cleanup orphan entries from snapshot store ref for primary storage

* Add debug message
This commit is contained in:
Nicolas Vazquez 2020-07-18 14:12:53 -03:00 committed by GitHub
parent affd010418
commit f843c537f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View File

@ -71,4 +71,6 @@ StateDao<ObjectInDataStoreStateMachine.State, ObjectInDataStoreStateMachine.Even
List<SnapshotDataStoreVO> listAllByVolumeAndDataStore(long volumeId, DataStoreRole role);
List<SnapshotDataStoreVO> listByState(ObjectInDataStoreStateMachine.State... states);
SnapshotDataStoreVO findDestroyedReferenceBySnapshot(long snapshotId, DataStoreRole role);
}

View File

@ -461,6 +461,15 @@ public class SnapshotDataStoreDaoImpl extends GenericDaoBase<SnapshotDataStoreVO
return listBy(sc, null);
}
@Override
public SnapshotDataStoreVO findDestroyedReferenceBySnapshot(long snapshotId, DataStoreRole role) {
SearchCriteria<SnapshotDataStoreVO> sc = snapshotSearch.create();
sc.setParameters("snapshot_id", snapshotId);
sc.setParameters("store_role", role);
sc.setParameters("state", State.Destroyed);
return findOneBy(sc);
}
private boolean isSnapshotChainingRequired(long volumeId) {
hypervisorsSupportingSnapshotsChaining.add(Hypervisor.HypervisorType.XenServer);

View File

@ -1393,8 +1393,11 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
}
_snapshotDao.remove(destroyedSnapshotStoreVO.getSnapshotId());
SnapshotDataStoreVO snapshotOnPrimary = _snapshotStoreDao.findBySnapshot(destroyedSnapshotStoreVO.getSnapshotId(), DataStoreRole.Primary);
SnapshotDataStoreVO snapshotOnPrimary = _snapshotStoreDao.findDestroyedReferenceBySnapshot(destroyedSnapshotStoreVO.getSnapshotId(), DataStoreRole.Primary);
if (snapshotOnPrimary != null) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Deleting snapshot on primary store reference DB entry: " + snapshotOnPrimary);
}
_snapshotStoreDao.remove(snapshotOnPrimary.getId());
}
_snapshotStoreDao.remove(destroyedSnapshotStoreVO.getId());