From 6cf39e16ad88b71ee9d62c187f4728f79336b522 Mon Sep 17 00:00:00 2001 From: waterWang Date: Thu, 20 Aug 2026 13:14:46 +0800 Subject: [PATCH] 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 --- .../java/com/cloud/usage/parser/VMSnapshotUsageParser.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/usage/src/main/java/com/cloud/usage/parser/VMSnapshotUsageParser.java b/usage/src/main/java/com/cloud/usage/parser/VMSnapshotUsageParser.java index 3ea5ee10166f..9127df8be988 100644 --- a/usage/src/main/java/com/cloud/usage/parser/VMSnapshotUsageParser.java +++ b/usage/src/main/java/com/cloud/usage/parser/VMSnapshotUsageParser.java @@ -65,7 +65,7 @@ protected boolean parse(AccountVO account, Date startDate, Date endDate) { long zoneId = usageRec.getZoneId(); Long volId = usageRec.getVolumeId(); long vmId = usageRec.getVmId(); - String key = vmId + ":" + volId; + String key = vmId + ":" + volId + ":" + usageRec.getVmSnapshotId(); if (usageRec.getCreated().before(startDate)) { unprocessedUsage.put(key, usageRec); continue; @@ -85,7 +85,7 @@ protected boolean parse(AccountVO account, Date startDate, Date endDate) { long duration = (createDate.getTime() - previousCreated.getTime()) + 1; createUsageRecord(UsageTypes.VM_SNAPSHOT, duration, previousCreated, createDate, account, volId, zoneId, previousEvent.getDiskOfferingId(), vmId, - previousEvent.getSize(), usageRec.getVmSnapshotId()); + previousEvent.getSize(), previousEvent.getVmSnapshotId()); previousEvent.setProcessed(new Date()); usageVMSnapshotDao.update(previousEvent);