OlegChuev opened a new issue, #13908:
URL: https://github.com/apache/cloudstack/issues/13908
## Problem Description
Spotted in version `4.19.1`.
When changing a volume's disk offering without resizing (i.e., the size
stays the same but the disk offering changes), **no usage_event is created** in
the database.
This causes a **data inconsistency** between the `cloud` and `cloud_usage`
databases:
- **`cloud.volumes` table**: Contains the new `disk_offering_id` (correctly
updated)
- **`cloud_usage.usage_volume` table**: Still references the old
`disk_offering_id` (stale data)
## Current Behavior
In `VolumeApiServiceImpl.changeDiskOfferingForVolumeInternal()`, a usage
event is only published when the size changes:
```java
if (currentSize != newSize) {
UsageEventUtils.publishUsageEvent(EventTypes.EVENT_VOLUME_RESIZE,
volume.getAccountId(), volume.getDataCenterId(), volume.getId(),
volume.getName(), volume.getDiskOfferingId(),
volume.getTemplateId(),
volume.getSize(), Volume.class.getName(), volume.getUuid());
}
```
When only the disk offering changes without resize, the code updates the
database but does **not** publish any usage event:
```java
if (!volumeMigrateRequired && !volumeResizeRequired) {
_volsDao.updateDiskOffering(volume.getId(), newDiskOffering.getId());
volume = _volsDao.findById(volume.getId());
updateStorageWithTheNewDiskOffering(volume, newDiskOffering);
return volume; // No usage event published here
}
```
## Impact
1. **Usage Tracking Inconsistency**: The usage billing system (`cloud_usage`
database) will continue to charge based on the old disk offering
2. **Audit Trail Missing**: There is no record in `usage_event` table of
when/how the disk offering changed
3. **Reporting Inaccuracy**: Usage reports will show incorrect disk offering
information for the affected period
## Expected Behavior
When a volume's disk offering is changed (regardless of size change), a
`VOLUME_CHANGE_DISK_OFFERING` usage event should be created to:
1. Maintain consistency between `cloud` and `cloud_usage` databases
2. Create an audit trail of the change
3. Ensure accurate usage billing and reporting
## Affected Code
- **File**:
`server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java`
- **Method**: `changeDiskOfferingForVolumeInternal()`
- **Lines**: Around 2279-2292 (the code path when neither migration nor
resize is required)
## Suggested Fix
A `VOLUME_CHANGE_DISK_OFFERING` event should be published whenever the disk
offering is changed, even when no resize or migration occurs. This event should
be processed by the usage manager to update the `usage_volume` table with the
new offering ID and mark the old offering usage as ended.
## Reproduction Steps
1. Create a volume with disk offering A (e.g., SSD)
2. Change the volume's disk offering to offering B (e.g., HDD) WITHOUT
changing the size
3. Verify that `cloud.volumes.disk_offering_id` shows offering B
4. Check `cloud_usage.usage_volume` - it still shows offering A
5. Verify that no entry is created in `cloud_usage.usage_event`
## Additional Context
The issue was identified through code analysis of the
`changeDiskOfferingForVolumeInternal()` method and the
`UsageManagerImpl.createVolumeHelperEvent()` method which processes volume
usage events.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]