server: Update use_bytes of storage pools (#4360)

Update the used_bytes for all default primary storage pools
Also get used_bytes of storage pool from database instead of
memory
This commit is contained in:
Rakesh 2020-10-21 19:18:03 +02:00 committed by GitHub
parent a5d4bd5f5a
commit 71c5dbcf49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 25 deletions

View File

@ -195,6 +195,10 @@ public class StoragePoolVO implements StoragePool {
return updateTime; return updateTime;
} }
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
@Override @Override
public long getDataCenterId() { public long getDataCenterId() {
return dataCenterId; return dataCenterId;

View File

@ -36,6 +36,7 @@ import javax.inject.Inject;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager; import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector; import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
import org.apache.cloudstack.framework.config.ConfigKey; import org.apache.cloudstack.framework.config.ConfigKey;
@ -1027,8 +1028,13 @@ public class StatsCollector extends ManagerBase implements ComponentMethodInterc
storagePoolStats.put(pool.getId(), (StorageStats)answer); storagePoolStats.put(pool.getId(), (StorageStats)answer);
// Seems like we have dynamically updated the pool size since the prev. size and the current do not match // Seems like we have dynamically updated the pool size since the prev. size and the current do not match
if (_storagePoolStats.get(poolId) != null && _storagePoolStats.get(poolId).getCapacityBytes() != ((StorageStats)answer).getCapacityBytes()) { if (pool.getCapacityBytes() != ((StorageStats)answer).getCapacityBytes() ||
pool.getUsedBytes() != ((StorageStats)answer).getByteUsed()) {
pool.setCapacityBytes(((StorageStats)answer).getCapacityBytes()); pool.setCapacityBytes(((StorageStats)answer).getCapacityBytes());
if (pool.getStorageProviderName().equalsIgnoreCase(DataStoreProvider.DEFAULT_PRIMARY)) {
pool.setUsedBytes(((StorageStats) answer).getByteUsed());
pool.setUpdateTime(new Date());
}
_storagePoolDao.update(pool.getId(), pool); _storagePoolDao.update(pool.getId(), pool);
} }
} }

View File

@ -151,7 +151,6 @@ import com.cloud.org.Grouping.AllocationState;
import com.cloud.resource.ResourceState; import com.cloud.resource.ResourceState;
import com.cloud.server.ConfigurationServer; import com.cloud.server.ConfigurationServer;
import com.cloud.server.ManagementServer; import com.cloud.server.ManagementServer;
import com.cloud.server.StatsCollector;
import com.cloud.storage.Storage.ImageFormat; import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Storage.StoragePoolType; import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.Volume.Type; import com.cloud.storage.Volume.Type;
@ -1730,31 +1729,21 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
return true; return true;
} }
StatsCollector sc = StatsCollector.getInstance();
double storageUsedThreshold = CapacityManager.StorageCapacityDisableThreshold.valueIn(pool.getDataCenterId()); double storageUsedThreshold = CapacityManager.StorageCapacityDisableThreshold.valueIn(pool.getDataCenterId());
if (sc != null) { long totalSize = pool.getCapacityBytes();
long totalSize = pool.getCapacityBytes(); double usedPercentage = ((double)pool.getUsedBytes() / (double)totalSize);
StorageStats stats = sc.getStoragePoolStats(pool.getId()); if (s_logger.isDebugEnabled()) {
if (stats == null) { s_logger.debug("Checking pool " + pool.getId() + " for storage, totalSize: " + pool.getCapacityBytes() + ", usedBytes: " + pool.getUsedBytes() +
stats = sc.getStorageStats(pool.getId()); ", usedPct: " + usedPercentage + ", disable threshold: " + storageUsedThreshold);
}
if (stats != null) {
double usedPercentage = ((double)stats.getByteUsed() / (double)totalSize);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Checking pool " + pool.getId() + " for storage, totalSize: " + toHumanReadableSize(pool.getCapacityBytes()) + ", usedBytes: " + toHumanReadableSize(stats.getByteUsed()) + ", usedPct: " + usedPercentage
+ ", disable threshold: " + storageUsedThreshold);
}
if (usedPercentage >= storageUsedThreshold) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Insufficient space on pool: " + pool.getId() + " since its usage percentage: " + usedPercentage + " has crossed the pool.storage.capacity.disablethreshold: "
+ storageUsedThreshold);
}
return false;
}
}
return true;
} }
return false; if (usedPercentage >= storageUsedThreshold) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Insufficient space on pool: " + pool.getId() + " since its usage percentage: " + usedPercentage +
" has crossed the pool.storage.capacity.disablethreshold: " + storageUsedThreshold);
}
return false;
}
return true;
} }
@Override @Override