From 720407ba73796d1bbbd56b3f65a5567143036c3e Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Tue, 19 Mar 2024 17:31:58 +0530 Subject: [PATCH] snapshot: don't schedule next snapshot job for a removed volume (#8735) * snapshot: don't schedule next snapshot job for a removed volume When management server starts, it starts the snapshot scheduler. In case there is a volume snapshot policy which exists for a volume which does not exist, it can cause SQL constraint issue and cause the management server to break from starting its various components and cause HTTP 503 error. Signed-off-by: Rohit Yadav * remove schedule on missing volume --------- Signed-off-by: Rohit Yadav --- .../com/cloud/storage/snapshot/SnapshotSchedulerImpl.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/src/main/java/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java b/server/src/main/java/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java index a9c402c86be6..d4fe08397f9e 100644 --- a/server/src/main/java/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java +++ b/server/src/main/java/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java @@ -378,6 +378,13 @@ public Date scheduleNextSnapshotJob(final SnapshotPolicyVO policy) { if (policyId == Snapshot.MANUAL_POLICY_ID) { return null; } + + if (_volsDao.findById(policy.getVolumeId()) == null) { + s_logger.warn("Found snapshot policy ID: " + policyId + " for volume ID: " + policy.getVolumeId() + " that does not exist or has been removed"); + removeSchedule(policy.getVolumeId(), policy.getId()); + return null; + } + final Date nextSnapshotTimestamp = getNextScheduledTime(policyId, _currentTimestamp); SnapshotScheduleVO spstSchedVO = _snapshotScheduleDao.findOneByVolumePolicy(policy.getVolumeId(), policy.getId()); if (spstSchedVO == null) {