Skip to content

Commit 6cf39e1

Browse files
author
waterWang
committed
fix: correct VM snapshot usage attribution (two defects)
Fixes #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>
1 parent d45d481 commit 6cf39e1

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

usage/src/main/java/com/cloud/usage/parser/VMSnapshotUsageParser.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected boolean parse(AccountVO account, Date startDate, Date endDate) {
6565
long zoneId = usageRec.getZoneId();
6666
Long volId = usageRec.getVolumeId();
6767
long vmId = usageRec.getVmId();
68-
String key = vmId + ":" + volId;
68+
String key = vmId + ":" + volId + ":" + usageRec.getVmSnapshotId();
6969
if (usageRec.getCreated().before(startDate)) {
7070
unprocessedUsage.put(key, usageRec);
7171
continue;
@@ -85,7 +85,7 @@ protected boolean parse(AccountVO account, Date startDate, Date endDate) {
8585
long duration = (createDate.getTime() - previousCreated.getTime()) + 1;
8686

8787
createUsageRecord(UsageTypes.VM_SNAPSHOT, duration, previousCreated, createDate, account, volId, zoneId, previousEvent.getDiskOfferingId(), vmId,
88-
previousEvent.getSize(), usageRec.getVmSnapshotId());
88+
previousEvent.getSize(), previousEvent.getVmSnapshotId());
8989
previousEvent.setProcessed(new Date());
9090
usageVMSnapshotDao.update(previousEvent);
9191

0 commit comments

Comments
 (0)