This is an automated email from the ASF dual-hosted git repository.
dahn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
The following commit(s) were added to refs/heads/master by this push:
new 71c5dbc server: Update use_bytes of storage pools (#4360)
71c5dbc is described below
commit 71c5dbcf492a023dbea5f8c34f8fd883c3ad653f
Author: Rakesh <[email protected]>
AuthorDate: Wed Oct 21 19:18:03 2020 +0200
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
---
.../storage/datastore/db/StoragePoolVO.java | 4 +++
.../main/java/com/cloud/server/StatsCollector.java | 8 ++++-
.../java/com/cloud/storage/StorageManagerImpl.java | 35 ++++++++--------------
3 files changed, 23 insertions(+), 24 deletions(-)
diff --git
a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
index 24fcaa0..b30b33d 100644
---
a/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
+++
b/engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
@@ -195,6 +195,10 @@ public class StoragePoolVO implements StoragePool {
return updateTime;
}
+ public void setUpdateTime(Date updateTime) {
+ this.updateTime = updateTime;
+ }
+
@Override
public long getDataCenterId() {
return dataCenterId;
diff --git a/server/src/main/java/com/cloud/server/StatsCollector.java
b/server/src/main/java/com/cloud/server/StatsCollector.java
index 43784da..fc1f39b 100644
--- a/server/src/main/java/com/cloud/server/StatsCollector.java
+++ b/server/src/main/java/com/cloud/server/StatsCollector.java
@@ -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.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.EndPointSelector;
import org.apache.cloudstack.framework.config.ConfigKey;
@@ -1027,8 +1028,13 @@ public class StatsCollector extends ManagerBase
implements ComponentMethodInterc
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
- 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());
+ if
(pool.getStorageProviderName().equalsIgnoreCase(DataStoreProvider.DEFAULT_PRIMARY))
{
+ pool.setUsedBytes(((StorageStats)
answer).getByteUsed());
+ pool.setUpdateTime(new Date());
+ }
_storagePoolDao.update(pool.getId(), pool);
}
}
diff --git a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java
b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java
index c59a26d..3c707c3 100644
--- a/server/src/main/java/com/cloud/storage/StorageManagerImpl.java
+++ b/server/src/main/java/com/cloud/storage/StorageManagerImpl.java
@@ -151,7 +151,6 @@ import com.cloud.org.Grouping.AllocationState;
import com.cloud.resource.ResourceState;
import com.cloud.server.ConfigurationServer;
import com.cloud.server.ManagementServer;
-import com.cloud.server.StatsCollector;
import com.cloud.storage.Storage.ImageFormat;
import com.cloud.storage.Storage.StoragePoolType;
import com.cloud.storage.Volume.Type;
@@ -1730,31 +1729,21 @@ public class StorageManagerImpl extends ManagerBase
implements StorageManager, C
return true;
}
- StatsCollector sc = StatsCollector.getInstance();
double storageUsedThreshold =
CapacityManager.StorageCapacityDisableThreshold.valueIn(pool.getDataCenterId());
- if (sc != null) {
- long totalSize = pool.getCapacityBytes();
- StorageStats stats = sc.getStoragePoolStats(pool.getId());
- if (stats == null) {
- stats = sc.getStorageStats(pool.getId());
- }
- 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;
- }
+ long totalSize = pool.getCapacityBytes();
+ double usedPercentage = ((double)pool.getUsedBytes() /
(double)totalSize);
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Checking pool " + pool.getId() + " for storage,
totalSize: " + pool.getCapacityBytes() + ", usedBytes: " + pool.getUsedBytes() +
+ ", 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 true;
+ return false;
}
- return false;
+ return true;
}
@Override