Skip to content

Commit 813d53d

Browse files
Sync the pool stats in DB with the actual stats from stats collector (#8686)
1 parent c462be1 commit 813d53d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

server/src/main/java/com/cloud/server/StatsCollector.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,17 +1712,21 @@ protected void runInContext() {
17121712
storagePoolStats.put(pool.getId(), (StorageStats)answer);
17131713

17141714
boolean poolNeedsUpdating = false;
1715+
long capacityBytes = ((StorageStats)answer).getCapacityBytes();
1716+
long usedBytes = ((StorageStats)answer).getByteUsed();
17151717
// Seems like we have dynamically updated the pool size since the prev. size and the current do not match
1716-
if (_storagePoolStats.get(poolId) != null && _storagePoolStats.get(poolId).getCapacityBytes() != ((StorageStats)answer).getCapacityBytes()) {
1717-
if (((StorageStats)answer).getCapacityBytes() > 0) {
1718-
pool.setCapacityBytes(((StorageStats)answer).getCapacityBytes());
1718+
if ((_storagePoolStats.get(poolId) != null && _storagePoolStats.get(poolId).getCapacityBytes() != capacityBytes)
1719+
|| pool.getCapacityBytes() != capacityBytes) {
1720+
if (capacityBytes > 0) {
1721+
pool.setCapacityBytes(capacityBytes);
17191722
poolNeedsUpdating = true;
17201723
} else {
17211724
LOGGER.warn("Not setting capacity bytes, received " + ((StorageStats)answer).getCapacityBytes() + " capacity for pool ID " + poolId);
17221725
}
17231726
}
1724-
if (pool.getUsedBytes() != ((StorageStats)answer).getByteUsed() && (pool.getStorageProviderName().equalsIgnoreCase(DataStoreProvider.DEFAULT_PRIMARY) || _storageManager.canPoolProvideStorageStats(pool))) {
1725-
pool.setUsedBytes(((StorageStats) answer).getByteUsed());
1727+
if (((_storagePoolStats.get(poolId) != null && _storagePoolStats.get(poolId).getByteUsed() != usedBytes)
1728+
|| pool.getUsedBytes() != usedBytes) && (pool.getStorageProviderName().equalsIgnoreCase(DataStoreProvider.DEFAULT_PRIMARY) || _storageManager.canPoolProvideStorageStats(pool))) {
1729+
pool.setUsedBytes(usedBytes);
17261730
poolNeedsUpdating = true;
17271731
}
17281732
if (poolNeedsUpdating) {

0 commit comments

Comments
 (0)