This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch 4.20
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/4.20 by this push:
new c91e84c6d8b Avoid double counting primary storage allocated capacity
for storage pools having a parent (#12181)
c91e84c6d8b is described below
commit c91e84c6d8b1b440d8c6af49f7b8f728c406e701
Author: Abhisar Sinha <[email protected]>
AuthorDate: Fri Jan 9 18:00:24 2026 +0530
Avoid double counting primary storage allocated capacity for storage pools
having a parent (#12181)
---
.../src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git
a/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java
b/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java
index 5e7eee4566c..7bd3df103b1 100644
--- a/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java
+++ b/engine/schema/src/main/java/com/cloud/capacity/dao/CapacityDaoImpl.java
@@ -213,6 +213,8 @@ public class CapacityDaoImpl extends
GenericDaoBase<CapacityVO, Long> implements
private static final String LEFT_JOIN_VM_TEMPLATE = "LEFT JOIN vm_template
ON vm_template.id = vi.vm_template_id ";
+ private static final String STORAGE_POOLS_WITH_CHILDREN = "SELECT DISTINCT
parent FROM storage_pool WHERE parent != 0 AND removed IS NULL";
+
public CapacityDaoImpl() {
_hostIdTypeSearch = createSearchBuilder();
_hostIdTypeSearch.and("hostId",
_hostIdTypeSearch.entity().getHostOrPoolId(), SearchCriteria.Op.EQ);
@@ -379,6 +381,11 @@ public class CapacityDaoImpl extends
GenericDaoBase<CapacityVO, Long> implements
finalQuery.append(" AND capacity_type = ?");
resourceIdList.add(capacityType.longValue());
}
+
+ // Exclude storage pools with children from capacity calculations to
avoid double counting
+ finalQuery.append(" AND NOT (capacity.capacity_type =
").append(Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED)
+ .append(" AND capacity.host_id IN
(").append(STORAGE_POOLS_WITH_CHILDREN).append("))");
+
if (CollectionUtils.isNotEmpty(hostIds)) {
finalQuery.append(String.format(" AND capacity.host_id IN (%s)",
StringUtils.join(hostIds, ",")));
if (capacityType == null) {
@@ -541,6 +548,10 @@ public class CapacityDaoImpl extends
GenericDaoBase<CapacityVO, Long> implements
StringBuilder sql = new
StringBuilder(LIST_CAPACITY_GROUP_BY_CAPACITY_PART1);
List<Long> resourceIdList = new ArrayList<Long>();
+ // Exclude storage pools with children from capacity calculations to
avoid double counting
+ sql.append(" AND NOT (capacity.capacity_type =
").append(Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED)
+ .append(" AND capacity.host_id IN
(").append(STORAGE_POOLS_WITH_CHILDREN).append("))");
+
if (zoneId != null) {
sql.append(" AND capacity.data_center_id = ?");
resourceIdList.add(zoneId);