Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -180,6 +180,8 @@ public interface StorageManager extends StorageService {

public Answer getVolumeStats(StoragePool pool, Command cmd);

boolean canPoolProvideStorageStats(StoragePool pool);

/**
* Checks if a host has running VMs that are using its local storage pool.
* @return true if local storage is active on the host
Expand Down
3 changes: 1 addition & 2 deletions server/src/main/java/com/cloud/server/StatsCollector.java
Expand Up @@ -1035,7 +1035,7 @@ protected void runInContext() {
s_logger.warn("Not setting capacity bytes, received " + ((StorageStats)answer).getCapacityBytes() + " capacity for pool ID " + poolId);
}
}
if (pool.getUsedBytes() != ((StorageStats)answer).getByteUsed() && pool.getStorageProviderName().equalsIgnoreCase(DataStoreProvider.DEFAULT_PRIMARY)) {
if (pool.getUsedBytes() != ((StorageStats)answer).getByteUsed() && (pool.getStorageProviderName().equalsIgnoreCase(DataStoreProvider.DEFAULT_PRIMARY) || _storageManager.canPoolProvideStorageStats(pool))) {
pool.setUsedBytes(((StorageStats) answer).getByteUsed());
poolNeedsUpdating = true;
}
Expand All @@ -1055,7 +1055,6 @@ protected void runInContext() {
s_logger.error("Error trying to retrieve storage stats", t);
}
}

}

class AutoScaleMonitor extends ManagedContextRunnable {
Expand Down
49 changes: 38 additions & 11 deletions server/src/main/java/com/cloud/storage/StorageManagerImpl.java
Expand Up @@ -48,6 +48,7 @@
import com.cloud.agent.api.GetStoragePoolCapabilitiesAnswer;
import com.cloud.agent.api.GetStoragePoolCapabilitiesCommand;
import com.cloud.network.router.VirtualNetworkApplianceManager;
import com.cloud.server.StatsCollector;
import com.cloud.upgrade.SystemVmTemplateRegistration;
import org.apache.cloudstack.annotation.AnnotationService;
import org.apache.cloudstack.annotation.dao.AnnotationDao;
Expand Down Expand Up @@ -469,13 +470,9 @@ public Answer sendToPool(StoragePool pool, long[] hostIdsToTryFirst, Command cmd

@Override
public Answer sendToPool(StoragePool pool, Command cmd) throws StorageUnavailableException {
if (cmd instanceof GetStorageStatsCommand) {
DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
if (storeDriver instanceof PrimaryDataStoreDriver && ((PrimaryDataStoreDriver)storeDriver).canProvideStorageStats()) {
// Get stats from the pool directly instead of sending cmd to host
return getStoragePoolStats(pool, (GetStorageStatsCommand) cmd);
}
if (cmd instanceof GetStorageStatsCommand && canPoolProvideStorageStats(pool)) {
// Get stats from the pool directly instead of sending cmd to host
return getStoragePoolStats(pool, (GetStorageStatsCommand) cmd);
}

Answer[] answers = sendToPool(pool, new Commands(cmd));
Expand All @@ -501,6 +498,17 @@ private GetStorageStatsAnswer getStoragePoolStats(StoragePool pool, GetStorageSt
return answer;
}

@Override
public boolean canPoolProvideStorageStats(StoragePool pool) {
DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
DataStoreDriver storeDriver = storeProvider.getDataStoreDriver();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sureshanaparti do we need to do any defensive/null checks?

if (storeDriver instanceof PrimaryDataStoreDriver && ((PrimaryDataStoreDriver)storeDriver).canProvideStorageStats()) {
return true;
}

return false;
rohityadavcloud marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public Answer getVolumeStats(StoragePool pool, Command cmd) {
DataStoreProvider storeProvider = _dataStoreProviderMgr.getDataStoreProvider(pool.getStorageProviderName());
Expand Down Expand Up @@ -2265,14 +2273,14 @@ public HypervisorType getHypervisorTypeFromFormat(ImageFormat format) {

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

double storageUsedThreshold = CapacityManager.StorageCapacityDisableThreshold.valueIn(pool.getDataCenterId());
long totalSize = pool.getCapacityBytes();
double usedPercentage = ((double)pool.getUsedBytes() / (double)totalSize);
long usedSize = getUsedSize(pool);
double usedPercentage = ((double)usedSize / (double)totalSize);
double storageUsedThreshold = CapacityManager.StorageCapacityDisableThreshold.valueIn(pool.getDataCenterId());
if (s_logger.isDebugEnabled()) {
s_logger.debug("Checking pool " + pool.getId() + " for storage, totalSize: " + pool.getCapacityBytes() + ", usedBytes: " + pool.getUsedBytes() +
", usedPct: " + usedPercentage + ", disable threshold: " + storageUsedThreshold);
Expand All @@ -2287,6 +2295,25 @@ private boolean checkUsagedSpace(StoragePool pool) {
return true;
}

private long getUsedSize(StoragePool pool) {
if (pool.getStorageProviderName().equalsIgnoreCase(DataStoreProvider.DEFAULT_PRIMARY) || canPoolProvideStorageStats(pool)) {
return (pool.getUsedBytes());
}

StatsCollector sc = StatsCollector.getInstance();
if (sc != null) {
StorageStats stats = sc.getStoragePoolStats(pool.getId());
if (stats == null) {
stats = sc.getStorageStats(pool.getId());
}
if (stats != null) {
return (stats.getByteUsed());
}
}

return 0;
}

@Override
public boolean storagePoolHasEnoughIops(List<Volume> requestedVolumes, StoragePool pool) {
if (requestedVolumes == null || requestedVolumes.isEmpty() || pool == null) {
Expand Down