Skip to content

Snapshot state normalization for failure due to malformed secondary storage heuristic - #13411

Open
erikbocks wants to merge 2 commits into
apache:4.22from
scclouds:normalize-snapshot-after-faulty-heuristic
Open

erikbocks wants to merge 2 commits into
apache:4.22from
scclouds:normalize-snapshot-after-faulty-heuristic

Conversation

@erikbocks

Copy link
Copy Markdown
Contributor

Description

If the environment has a malformed (wrong logic, syntax error, etc.) secondary storage selector heuristic rule, an exception is thrown during its interpretation. The snapshot creation process gets the environment's SNAPSHOT type secondary storage selectors and interprets its heuristic rule, if any was returned. However, this validation does not handle exceptions thrown by the interpreter.

With that, the snapshot record that was created in the Allocated state is never normalized, even though the creation process was finished prematurely due to the interpretation error. Therefore, changes were made to normalize the snapshot state to Error in these cases.

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

First, I created a malformed secondary storage selector:

Secondary storage selector creation command
create secondarystorageselector name=a description=a type=SNAPSHOT zoneid=a9a3fc15-008f-48b1-8964-d946104b4b17 heuristicrule="if"

Then, I tried to create a volume snapshot, and validated that it was set to the Allocated state. After applying the changes, I repeated the process and validated that the snapshot was set to the Error state.

@codecov

codecov Bot commented Jun 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.32%. Comparing base (8e933b7) to head (519e072).
⚠️ Report is 229 commits behind head on 4.22.

Files with missing lines Patch % Lines
...om/cloud/storage/snapshot/SnapshotManagerImpl.java 0.00% 15 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               4.22   #13411      +/-   ##
============================================
+ Coverage     17.67%   18.32%   +0.64%     
- Complexity    15792    16642     +850     
============================================
  Files          5922     5939      +17     
  Lines        533167   537798    +4631     
  Branches      65210    65932     +722     
============================================
+ Hits          94246    98527    +4281     
+ Misses       428276   428062     -214     
- Partials      10645    11209     +564     
Flag Coverage Δ
uitests 4.08% <ø> (+0.38%) ⬆️
unittests 19.41% <0.00%> (+0.65%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@winterhazel

Copy link
Copy Markdown
Member

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@winterhazel a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✖️ debian ✔️ suse15. SL-JID 18243

@winterhazel

Copy link
Copy Markdown
Member

Looks good, but I did not test.

@nvazquez nvazquez modified the milestones: 4.22.2, 4.22.3 Nov 9, 2026
@erikbocks erikbocks changed the title Snapshot state normalization for failure due to malformed secondary s… Snapshot state normalization for failure due to malformed secondary storage heuristic rules Nov 13, 2026
@erikbocks erikbocks changed the title Snapshot state normalization for failure due to malformed secondary storage heuristic rules Snapshot state normalization for failure due to malformed secondary storage heuristic Nov 13, 2026
@erikbocks

Copy link
Copy Markdown
Contributor Author

Hello, @Damans227 and @winterhazel

I moved the storage selection to the try block. Now, limits are decremented by the catch block. Could you review this approach?

@Damans227

Copy link
Copy Markdown
Contributor

I moved the storage selection to the try block. Now, limits are decremented by the catch block. Could you review this approach?

@erikbocks that covers it. a broken rule now marks the snapshot as error and gives back the snapshot and storage counts.

@Damans227 Damans227 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLGTM. @erikbocks can you get it tested on a KVM lab with file-based primary storage and a broken snapshot heuristic rule, and post the snapshot state and the account's snapshot counts after?

@JoaoJandre

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@JoaoJandre a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 20219

@erikbocks

Copy link
Copy Markdown
Contributor Author

Hello, @Damans227

Here follows the test requested on #13411 (review):

1. Details about VM, existing snapshots and user account limits

VM details image
Snapshots list image
User limits image

2. Malformed secondary storage selector creation

(all-in-one) 🐋 > create secondarystorageselector name=malformed description=malformed type=SNAPSHOT zoneid=3b42d247-1d78-47a1-b6de-c797398661c8 heuristicrule="invalid"
{
  "heuristics": {
    "created": "2026-11-30T13:22:57-0300",
    "description": "malformed",
    "heuristicrule": "invalid",
    "id": "fd86d831-4f4d-420b-a90a-f74986c11531",
    "name": "malformed",
    "type": "SNAPSHOT",
    "zoneid": "3b42d247-1d78-47a1-b6de-c797398661c8"
  }
}

3. Snapshot failure, user account limits and logs

Snapshot failure image
User limits after snapshot failure image
Management Server's failure logs
2026-11-30 13:29:06,673 ERROR [c.c.s.s.SnapshotManagerImpl] (Work-Job-Executor-2:[ctx-e9721d39, job-51/job-52, ctx-86b324d4]) (logid:b69ac203) There was an error while selecting image store for snapshot: Unable to execute script [invalid] due to [Script error: ReferenceError: "invalid" is not defined in <eval> at line number 1 in <eval> at line number 1]
2026-11-30 13:29:06,677 DEBUG [c.c.s.s.SnapshotManagerImpl] (Work-Job-Executor-2:[ctx-e9721d39, job-51/job-52, ctx-86b324d4]) (logid:b69ac203) Failed to create snapshotUnable to execute script [invalid] due to [Script error: ReferenceError: "invalid" is not defined in <eval> at line number 1 in <eval> at line number 1]
2026-11-30 13:29:06,677 DEBUG [c.c.r.ResourceLimitManagerImpl] (Work-Job-Executor-2:[ctx-e9721d39, job-51/job-52, ctx-86b324d4]) (logid:b69ac203) Updating resource Type = snapshot count for Account with id = 4 Operation = decreasing Amount = 1
2026-11-30 13:29:06,678 DEBUG [c.c.r.ResourceLimitManagerImpl] (Work-Job-Executor-2:[ctx-e9721d39, job-51/job-52, ctx-86b324d4]) (logid:b69ac203) Updating resource Type = secondary_storage count for Account with id = 4 Operation = decreasing Amount = (50.00 MB) 52428800

@Damans227

Copy link
Copy Markdown
Contributor

Here follows the test requested on #13411 (review)

@erikbocks thanks, that shows it. the snapshot ends up in error and the snapshot and storage counts go back to where they were.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Ready

Development

Successfully merging this pull request may close these issues.

6 participants