Skip to content

fix: correct VM snapshot usage attribution (two defects) - #13924

Open
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix-vm-snapshot-usage-attribution
Open

fix: correct VM snapshot usage attribution (two defects)#13924
waterWang wants to merge 1 commit into
apache:mainfrom
waterWang:fix-vm-snapshot-usage-attribution

Conversation

@waterWang

Copy link
Copy Markdown

Fixes #13921

Two defects corrected in VMSnapshotUsageParser:

  1. Wrong snapshot ID label in usage record: createUsageRecord() used the current snapshot's ID (usageRec.getVmSnapshotId()) while duration, size, and disk offering came from the previous event. Changed to previousEvent.getVmSnapshotId().

  2. Concurrent snapshot key collision: The unprocessedUsage map keyed entries by vmId + ":" + volId only, so concurrent snapshots of the same volume overwrote each other. Added vmSnapshotId to the key to distinguish them.

Root cause

From the issue body:

Net effect: the first snapshot's usage is credited to the second snapshot, and the first snapshot stops accruing usage even though it still exists and is Ready.

@boring-cyborg

boring-cyborg Bot commented Aug 20, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

Fixes apache#13921

Defect 1: createUsageRecord used the current snapshot ID (usageRec)
for the usage label, while duration/size/diskOffering came from the
previous event. This caused the first snapshot's usage to be credited
to the second snapshot.

Defect 2: unprocessedUsage key was vmId + volId only, so concurrent
snapshots of the same volume overwrote each other. Added vmSnapshotId
to the key to distinguish them.

Signed-off-by: waterWang <waterwang@proton.me>
@waterWang
waterWang force-pushed the fix-vm-snapshot-usage-attribution branch from 3857686 to 6cf39e1 Compare August 20, 2026 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VM snapshot usage records are attributed to the wrong snapshot; older snapshots stop accruing usage entirely

1 participant