Skip to content

Commit 4729311

Browse files
author
Daman Arora
committed
add cleanup for orphan snapshot policies
1 parent a32e7bc commit 4729311

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,9 +1890,24 @@ public boolean start() {
18901890
logger.debug("Failed to delete snapshot in destroying state: {}", snapshotVO);
18911891
}
18921892
}
1893+
cleanupOrphanSnapshotPolicies();
1894+
18931895
return true;
18941896
}
18951897

1898+
private void cleanupOrphanSnapshotPolicies() {
1899+
List<SnapshotPolicyVO> policies = _snapshotPolicyDao.listActivePolicies();
1900+
if (CollectionUtils.isEmpty(policies)) {
1901+
return;
1902+
}
1903+
for (SnapshotPolicyVO policy : policies) {
1904+
if (_volsDao.findByIdIncludingRemoved(policy.getVolumeId()) == null) {
1905+
logger.info("Removing orphan snapshot policy {} for non-existent volume {}", policy.getId(), policy.getVolumeId());
1906+
deletePolicy(policy.getId());
1907+
}
1908+
}
1909+
}
1910+
18961911
@Override
18971912
public boolean stop() {
18981913
backupSnapshotExecutor.shutdown();

0 commit comments

Comments
 (0)