Skip to content

Commit 3a44deb

Browse files
sureshanapartidhslove
authored andcommitted
Sync the pool stats in DB with the actual stats from stats collector (apache#8686)
1 parent ace7564 commit 3a44deb

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

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

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

18811881
boolean poolNeedsUpdating = false;
1882+
long capacityBytes = ((StorageStats)answer).getCapacityBytes();
1883+
long usedBytes = ((StorageStats)answer).getByteUsed();
18821884
// Seems like we have dynamically updated the pool size since the prev. size and the current do not match
1883-
if (_storagePoolStats.get(poolId) != null && _storagePoolStats.get(poolId).getCapacityBytes() != ((StorageStats)answer).getCapacityBytes()) {
1884-
if (((StorageStats)answer).getCapacityBytes() > 0) {
1885-
pool.setCapacityBytes(((StorageStats)answer).getCapacityBytes());
1885+
if ((_storagePoolStats.get(poolId) != null && _storagePoolStats.get(poolId).getCapacityBytes() != capacityBytes)
1886+
|| pool.getCapacityBytes() != capacityBytes) {
1887+
if (capacityBytes > 0) {
1888+
pool.setCapacityBytes(capacityBytes);
18861889
poolNeedsUpdating = true;
18871890
} else {
18881891
logger.warn("Not setting capacity bytes, received " + ((StorageStats)answer).getCapacityBytes() + " capacity for pool ID " + poolId);
18891892
}
18901893
}
1891-
if (pool.getUsedBytes() != ((StorageStats)answer).getByteUsed() && (pool.getStorageProviderName().equalsIgnoreCase(DataStoreProvider.DEFAULT_PRIMARY) || _storageManager.canPoolProvideStorageStats(pool))) {
1892-
pool.setUsedBytes(((StorageStats) answer).getByteUsed());
1894+
if (((_storagePoolStats.get(poolId) != null && _storagePoolStats.get(poolId).getByteUsed() != usedBytes)
1895+
|| pool.getUsedBytes() != usedBytes) && (pool.getStorageProviderName().equalsIgnoreCase(DataStoreProvider.DEFAULT_PRIMARY) || _storageManager.canPoolProvideStorageStats(pool))) {
1896+
pool.setUsedBytes(usedBytes);
18931897
poolNeedsUpdating = true;
18941898
}
18951899
if (poolNeedsUpdating) {

0 commit comments

Comments
 (0)