Skip to content

Commit 0a88e71

Browse files
sureshanapartiyadvrGutoVeronezi
authored
Check the pool used space from the bytes used in the storage pool stats collector, for non-default primary storage pools that cannot provide stats. (#5586)
* Check the pool used space from the bytes used in the storage pool stats collector, for non-default primary storage pools that cannot provide stats. Also, Update the used bytes from the pool stats answer for non-default primary storage pools if the pool can provide stats. * Update server/src/main/java/com/cloud/storage/StorageManagerImpl.java Co-authored-by: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com> * space fix Co-authored-by: Rohit Yadav <rohit.yadav@shapeblue.com> Co-authored-by: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com>
1 parent ac75fac commit 0a88e71

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
lines changed

engine/components-api/src/main/java/com/cloud/storage/StorageManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ public interface StorageManager extends StorageService {
180180

181181
public Answer getVolumeStats(StoragePool pool, Command cmd);
182182

183+
boolean canPoolProvideStorageStats(StoragePool pool);
184+
183185
/**
184186
* Checks if a host has running VMs that are using its local storage pool.
185187
* @return true if local storage is active on the host

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ protected void runInContext() {
10351035
s_logger.warn("Not setting capacity bytes, received " + ((StorageStats)answer).getCapacityBytes() + " capacity for pool ID " + poolId);
10361036
}
10371037
}
1038-
if (pool.getUsedBytes() != ((StorageStats)answer).getByteUsed() && pool.getStorageProviderName().equalsIgnoreCase(DataStoreProvider.DEFAULT_PRIMARY)) {
1038+
if (pool.getUsedBytes() != ((StorageStats)answer).getByteUsed() && (pool.getStorageProviderName().equalsIgnoreCase(DataStoreProvider.DEFAULT_PRIMARY) || _storageManager.canPoolProvideStorageStats(pool))) {
10391039
pool.setUsedBytes(((StorageStats) answer).getByteUsed());
10401040
poolNeedsUpdating = true;
10411041
}
@@ -1055,7 +1055,6 @@ protected void runInContext() {
10551055
s_logger.error("Error trying to retrieve storage stats", t);
10561056
}
10571057
}
1058-
10591058
}
10601059

10611060
class AutoScaleMonitor extends ManagedContextRunnable {

server/src/main/java/com/cloud/storage/StorageManagerImpl.java

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer;
4949
import com.cloud.agent.api.GetStoragePoolCapabilitiesCommand;
5050
import com.cloud.network.router.VirtualNetworkApplianceManager;
51+
import com.cloud.server.StatsCollector;
5152
import com.cloud.upgrade.SystemVmTemplateRegistration;
5253
import org.apache.cloudstack.annotation.AnnotationService;
5354
import org.apache.cloudstack.annotation.dao.AnnotationDao;
@@ -469,13 +470,9 @@ public Answer sendToPool(StoragePool pool, long[] hostIdsToTryFirst, Command cmd
469470

470471
@Override
471472
public Answer sendToPool(StoragePool pool, Command cmd) throws StorageUnavailableException {
472-
if (cmd instanceof GetStorageStatsCommand) {
473-
DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
474-
DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
475-
if (storeDriver instanceof PrimaryDataStoreDriver && ((PrimaryDataStoreDriver)storeDriver).canProvideStorageStats()) {
476-
// Get stats from the pool directly instead of sending cmd to host
477-
return getStoragePoolStats(pool, (GetStorageStatsCommand) cmd);
478-
}
473+
if (cmd instanceof GetStorageStatsCommand && canPoolProvideStorageStats(pool)) {
474+
// Get stats from the pool directly instead of sending cmd to host
475+
return getStoragePoolStats(pool, (GetStorageStatsCommand) cmd);
479476
}
480477

481478
Answer[] answers = sendToPool(pool, new Commands(cmd));
@@ -501,6 +498,13 @@ private GetStorageStatsAnswer getStoragePoolStats(StoragePool pool, GetStorageSt
501498
return answer;
502499
}
503500

501+
@Override
502+
public boolean canPoolProvideStorageStats(StoragePool pool) {
503+
DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
504+
DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
505+
return storeDriver instanceof PrimaryDataStoreDriver && ((PrimaryDataStoreDriver)storeDriver).canProvideStorageStats();
506+
}
507+
504508
@Override
505509
public Answer getVolumeStats(StoragePool pool, Command cmd) {
506510
DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
@@ -2265,14 +2269,14 @@ public HypervisorType getHypervisorTypeFromFormat(ImageFormat format) {
22652269

22662270
private boolean checkUsagedSpace(StoragePool pool) {
22672271
// Managed storage does not currently deal with accounting for physically used space (only provisioned space). Just return true if "pool" is managed.
2268-
// StatsCollector gets the storage stats from the ScaleIO/PowerFlex pool directly, limit the usage based on the capacity disable threshold
2269-
if (pool.isManaged() && pool.getPoolType() != StoragePoolType.PowerFlex) {
2272+
if (pool.isManaged() && !canPoolProvideStorageStats(pool)) {
22702273
return true;
22712274
}
22722275

2273-
double storageUsedThreshold = CapacityManager.StorageCapacityDisableThreshold.valueIn(pool.getDataCenterId());
22742276
long totalSize = pool.getCapacityBytes();
2275-
double usedPercentage = ((double)pool.getUsedBytes() / (double)totalSize);
2277+
long usedSize = getUsedSize(pool);
2278+
double usedPercentage = ((double)usedSize / (double)totalSize);
2279+
double storageUsedThreshold = CapacityManager.StorageCapacityDisableThreshold.valueIn(pool.getDataCenterId());
22762280
if (s_logger.isDebugEnabled()) {
22772281
s_logger.debug("Checking pool " + pool.getId() + " for storage, totalSize: " + pool.getCapacityBytes() + ", usedBytes: " + pool.getUsedBytes() +
22782282
", usedPct: " + usedPercentage + ", disable threshold: " + storageUsedThreshold);
@@ -2287,6 +2291,25 @@ private boolean checkUsagedSpace(StoragePool pool) {
22872291
return true;
22882292
}
22892293

2294+
private long getUsedSize(StoragePool pool) {
2295+
if (pool.getStorageProviderName().equalsIgnoreCase(DataStoreProvider.DEFAULT_PRIMARY) || canPoolProvideStorageStats(pool)) {
2296+
return (pool.getUsedBytes());
2297+
}
2298+
2299+
StatsCollector sc = StatsCollector.getInstance();
2300+
if (sc != null) {
2301+
StorageStats stats = sc.getStoragePoolStats(pool.getId());
2302+
if (stats == null) {
2303+
stats = sc.getStorageStats(pool.getId());
2304+
}
2305+
if (stats != null) {
2306+
return (stats.getByteUsed());
2307+
}
2308+
}
2309+
2310+
return 0;
2311+
}
2312+
22902313
@Override
22912314
public boolean storagePoolHasEnoughIops(List<Volume> requestedVolumes, StoragePool pool) {
22922315
if (requestedVolumes == null || requestedVolumes.isEmpty() || pool == null) {

0 commit comments

Comments
 (0)