Repository navigation
deal with excessive attempts on failing snapshots - #13743
DaanHoogland wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #13743 +/- ##
============================================
+ Coverage 3.86% 21.11% +17.24%
- Complexity 0 21320 +21320
============================================
Files 494 6058 +5564
Lines 42890 549997 +507107
Branches 8142 73554 +65412
============================================
+ Hits 1657 116109 +114452
- Misses 41001 420250 +379249
- Partials 232 13638 +13406
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
This PR adds logic to reduce excessive retry attempts for failing recurring snapshots by tracking outcomes via event history, applying configurable retry/backoff behavior for dispatch failures, and optionally skipping snapshots when a VM hasn’t been running since the last snapshot.
Changes:
- Add configurable max-failure and retry-interval handling for recurring snapshot dispatch failures (and log outcomes as events for consecutive-failure counting).
- Introduce optional “skip snapshot if VM not running since last snapshot” behavior plus a new
SNAPSHOT.SKIPPEDevent type. - Add DAO support to query recent events per resource, and add unit tests covering the new behaviors.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| server/src/main/java/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java | Adds failure counting, scoped config resolution, dispatch failure handling with backoff/give-up, and unchanged-volume skip logic. |
| server/src/test/java/com/cloud/storage/snapshot/SnapshotSchedulerImplTest.java | Adds unit tests for consecutive failure counting, scoped config fallback, dispatch failure behavior, and skip logic. |
| server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java | Registers new snapshot-related config keys. |
| server/src/main/java/com/cloud/storage/snapshot/SnapshotManager.java | Defines new scoped config keys for recurring snapshot failure handling and skip behavior. |
| engine/schema/src/main/java/com/cloud/event/dao/EventDaoImpl.java | Implements querying latest events per resource for failure counting. |
| engine/schema/src/main/java/com/cloud/event/dao/EventDao.java | Adds DAO API for latest-events-by-resource lookup. |
| api/src/main/java/com/cloud/event/EventTypes.java | Adds EVENT_SNAPSHOT_SKIPPED constant and registers it for entity-event details. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
🔴 Test Coverage Grade:
|
| Metric | Value |
|---|---|
| Line coverage | 24.52% |
| Branch coverage | 18.68% |
Grade Scale
| Grade | Line Coverage | Meaning |
|---|---|---|
| 🟢 A | ≥ 80% | Excellent - this code sleeps well at night 😴 |
| 🟡 B | 60-79% | Good - almost there, don't stop now 😉 |
| 🟠 C | 40-59% | Acceptable - your code is wearing a seatbelt, but no airbags 😬 |
| 🔴 D | 20-39% | Marginal - boldly shipping where no test has gone before 🖖 |
| ⛔ F | < 20% | Failing - tests? what tests? 🔥 |
Branch coverage is shown as a secondary signal. Grade is determined by line coverage.
View full Actions run
- Use a distinct event type (SNAPSHOT.RECURRING.FAILURE.LIMIT.REACHED) for the "gave up" WARN notification instead of EVENT_SNAPSHOT_CREATE, since that event became the latest EVENT_SNAPSHOT_CREATE entry and silently reset countConsecutiveFailedAttempts on the next scan. - Filter out archived events in EventDao#listLatestEventsByResource so stale archived events can't be counted as the latest failure history, matching the archived=false filtering already used by sibling searches in EventDaoImpl. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
server/src/main/java/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java:253
- The WARN notification emitted when the consecutive-failure threshold is reached uses
EventTypes.EVENT_SNAPSHOT_CREATE. BecausecountConsecutiveFailedAttemptsscans the latestEVENT_SNAPSHOT_CREATEevents and stops at the first non-ERROR level, this WARN event becomes part of the scanned stream and can unintentionally break/reset the consecutive-failure sequence. The PR already introduces a dedicated event type for this purpose; use it here as well.
if (maxFailures > 0 && totalFailures >= maxFailures) {
logger.warn("Snapshot schedule [{}] for volume [{}] has failed [{}] consecutive times.", snapshotSchedule, volume, totalFailures);
ActionEventUtils.onCreatedActionEvent(User.UID_SYSTEM, volume.getAccountId(), EventVO.LEVEL_WARN, EventTypes.EVENT_SNAPSHOT_CREATE, true,
String.format("Recurring snapshot for volume [%s] has failed %d consecutive times.", volume, totalFailures),
volume.getId(), ApiCommandResourceType.Volume.toString());
|
🔴 Test Coverage Grade:
|
| Metric | Value |
|---|---|
| Line coverage | 24.52% |
| Branch coverage | 18.68% |
Grade Scale
| Grade | Line Coverage | Meaning |
|---|---|---|
| 🟢 A | ≥ 80% | Excellent - this code sleeps well at night 😴 |
| 🟡 B | 60-79% | Good - almost there, don't stop now 😉 |
| 🟠 C | 40-59% | Acceptable - your code is wearing a seatbelt, but no airbags 😬 |
| 🔴 D | 20-39% | Marginal - boldly shipping where no test has gone before 🖖 |
| ⛔ F | < 20% | Failing - tests? what tests? 🔥 |
Branch coverage is shown as a secondary signal. Grade is determined by line coverage.
View full Actions run
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (2)
server/src/main/java/com/cloud/storage/snapshot/SnapshotSchedulerImpl.java:229
- New behavior is introduced in
recordSnapshotAttemptOutcome(event emission + consecutive-failure logic), but there’s no targeted unit test coverage validating (a) the correct event types/levels emitted for success/failure/limit-reached and (b) that consecutive-failure counting behaves correctly across the WARN notification boundary. Adding focused tests here would help prevent regressions (especially given the event stream is used as the ‘counter’ source of truth).
/**
* Logs an event for the outcome of a recurring snapshot job (keyed by the volume, since a fresh snapshot entity
* ID is minted on every attempt) so that consecutive failures can be counted from event history, and raises a
* WARN notification once {@link SnapshotManager#SnapshotRecurringMaxFailures} consecutive failures are reached.
*/
protected void recordSnapshotAttemptOutcome(final SnapshotScheduleVO snapshotSchedule, final boolean succeeded, final String failureResult) {
final VolumeVO volume = _volsDao.findByIdIncludingRemoved(snapshotSchedule.getVolumeId());
server/src/test/java/com/cloud/storage/snapshot/SnapshotSchedulerImplTest.java:340
- Test name uses ‘Depot’, which doesn’t match the concept under test (scoped config resolution across account/domain/zone/global). Consider renaming to something clearer like ‘WhenNoScopedOverrideConfigured’ or similar to reflect the actual behavior being verified.
public void getScopedConfigValueTestFallsBackToGlobalDefaultWhenNoDepotConfigured() {
|
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch. |
|
@blueorangutan package |
|
@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19969 |
|
@nvazquez , should be ready (testing needed) |
|
@blueorangutan test |
|
@RosiKyu a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian Build Failed (tid-17572) |
|
@blueorangutan test |
|
@RosiKyu a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch. |
|
[SF] Trillian test result (tid-17585)
|
|
Tested on 4.22.1.1, KVM (Ubuntu 24.04), NFS primary and secondary. The PR's main code was built on the 4.22.1.1 tag; the only change I made is that the new setting is read at global scope, because the scoped lookup helper is not on 4.22. Setup: one stopped instance, an HOURLY snapshot policy on its ROOT volume, schedule moved forward by hand so each run comes after about 10 minutes.
So the issue reproduces on 4.22.1.1, but in this lab the PR never skipped: no "Skipped scheduled snapshot" log line and no SNAPSHOT.SKIP event. Cause as far as I can see: shouldSkipUnchangedVolumeSnapshot only skips when the instance's power state is PowerOff. In this lab an instance stopped through CloudStack never had that value. Its row showed state Stopped with power state PowerOn (power state update time = the time of the stop) for the 30 minutes of one run, and Stopped with PowerReportMissing in another run. So the condition is false for the normal "user stopped the instance" case, which is the case the issue describes. I also tried a small variant that accepts Stopped together with PowerReportMissing. It did not skip either, because in that run the row stayed at Stopped / PowerOn:
Suggestion: do not rely on the power state for this. Use the instance state (Stopped) and the time it entered that state, compared with the creation time of the last backed up snapshot. I have not tested a version built that way. Could you say on which hypervisor and how the instance was stopped when you saw PowerOff in your test? If it is reachable on another setup I am happy to rerun. |
51db06b to
eb76208
Compare
Thanks James, KVM undefines a stopped domain, so the power state never becomes PowerOff. The skip now uses the instance's Stopped state and the time it was stopped (vm_instance.update_time, set on each state change) compared with the last backed-up snapshot, as you suggested. Could you rerun your scenario on the new head? |
There was a problem hiding this comment.
🟡 Changes recommended
Snapshot skipping can leave a policy’s target zone without backups, while purged or archived outcomes cause incorrect failure-streak and retry counts.
3 open issues
6 resolved since last review
UsingvalueInScope(..., inherit=true)for Account/Domain can return a Global value before the… Filter out unsuccessful snapshots before limiting results Don't skip backups for volumes attached after the snapshot Require confirmed powered-off state before skipping snapshots Index snapshot event lookups by resource and type The ordering field"createDate"looks inconsistent with the comment (“created”) and the expected…
Review effort: Balanced
| return false; | ||
| } | ||
|
|
||
| final SnapshotVO lastSnapshot = findLastSnapshot(volume.getId()); |
| sc.setParameters(FIELD_RESOURCE_TYPE, resourceType); | ||
| sc.setParameters("type", type); | ||
| sc.setParameters("state", State.Created, State.Completed); | ||
| sc.setParameters("archived", false); |
| final List<EventVO> recentEvents = eventDao.listLatestOutcomeEventsByResource(volumeId, ApiCommandResourceType.Volume.toString(), | ||
| EventTypes.EVENT_SNAPSHOT_CREATE, limit); |
| LastStartEventSearch.and("resourceId", LastStartEventSearch.entity().getResourceId(), Op.EQ); | ||
| LastStartEventSearch.and("resourceType", LastStartEventSearch.entity().getResourceType(), Op.EQ); | ||
| LastStartEventSearch.and(FIELD_RESOURCE_ID, LastStartEventSearch.entity().getResourceId(), Op.EQ); | ||
| LastStartEventSearch.and(FIELD_RESOURCE_TYPE, LastStartEventSearch.entity().getResourceType(), Op.EQ); |
There was a problem hiding this comment.
can reuse the same builder, for one or multiple values (with state check op.IN).
There was a problem hiding this comment.
I don't get your comment; two different fields are being checked (id and type)
|
|
||
| ConfigKey<Boolean> SnapshotSkipIfVmNotRunning = new ConfigKey<>(Boolean.class, "snapshot.skip.if.vm.not.running", "Snapshots", "false", | ||
| "For recurring snapshots, skip taking a new snapshot of a volume (and log a skipped event instead) when the VM it is attached to has not been running since the last snapshot was taken, since nothing on the volume could have changed.", | ||
| true, List.of(ConfigKey.Scope.Account, ConfigKey.Scope.Domain, ConfigKey.Scope.Zone), null); |
There was a problem hiding this comment.
@DaanHoogland are these configs applicable for vmware / xen as well?
There was a problem hiding this comment.
seems so, pls confirm
There was a problem hiding this comment.
these are for snapshots, not for any particular hypervisor. Should this matter?
|
|
Retested on the current head of this PR (eb76208, backported onto 4.22.1.1), on a KVM lab with NFS primary storage, with an hourly-style recurring snapshot policy on the ROOT volume of a stopped VM:
So the skip now behaves correctly in all four cases, including the first snapshot of an already stopped VM and the snapshot after a start/stop cycle. LGTM from the testing side. |





Description
This PR stops recurring snapshots from retrying forever when they keep failing, and can skip recurring snapshots that would be redundant.
Failed recurring snapshots (#13454)
CreateSnapshotCmdfailed synchronously (for example an allocation error), the schedule's timestamp never moved forward, so the snapshot was retried on everysnapshot.poll.interval.SNAPSHOT.CREATEevent on the volume. The number of consecutive failures is worked out from that event history (only outcome events, Created or Completed, count; no new counter column).snapshot.recurring.retry.intervalseconds (default 300). Oncesnapshot.recurring.max.failuresconsecutive failures are reached (default 3, 0 = retry forever), the snapshot isn't tried again until its next regular run, and a WARNSNAPSHOT.RECURRING.FAILURE.LIMIT.REACHEDevent is raised.Skipping redundant snapshots (#6827)
snapshot.skip.if.vm.not.running(defaultfalse). When it's enabled, a recurring snapshot is skipped if the volume's VM hasn't been running since the last snapshot was taken. The schedule moves on to its next regular run and an INFOSNAPSHOT.SKIPPEDevent is logged.All three settings can be set per account, domain or zone, or globally. The most specific value is used.
Fixes: #13454
Fixes: #6827
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
How Has This Been Tested?
SnapshotSchedulerImplTest(40 tests) andEventDaoImplTest.🤖 Generated with Claude Code