Skip to content

Commit b16ccc9

Browse files
committed
CLOUDSTACK-2036 - Adding storage storage.overprovisioning.factor configurable at zone level.
1 parent 817c46d commit b16ccc9

5 files changed

Lines changed: 29 additions & 17 deletions

File tree

‎server/src/com/cloud/capacity/CapacityManagerImpl.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
142142

143143
_executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("HostCapacity-Checker"));
144144
VirtualMachine.State.getStateMachine().registerListener(this);
145-
_agentManager.registerForHostEvents(new StorageCapacityListener(_capacityDao, _storageOverProvisioningFactor), true, false, false);
145+
_agentManager.registerForHostEvents(new StorageCapacityListener(_capacityDao, _storageMgr), true, false, false);
146146
_agentManager.registerForHostEvents(new ComputeCapacityListener(_capacityDao, this), true, false, false);
147147

148148
return true;

‎server/src/com/cloud/capacity/StorageCapacityListener.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
// under the License.
1717
package com.cloud.capacity;
1818

19+
import java.math.BigDecimal;
1920
import java.util.List;
2021

22+
import com.cloud.storage.StorageManager;
2123
import org.apache.log4j.Logger;
2224

2325
import com.cloud.agent.Listener;
@@ -39,14 +41,11 @@
3941
public class StorageCapacityListener implements Listener {
4042

4143
CapacityDao _capacityDao;
42-
float _overProvisioningFactor = 1.0f;
44+
StorageManager _storageMgr;
4345

44-
45-
public StorageCapacityListener(CapacityDao _capacityDao,
46-
float _overProvisioningFactor) {
47-
super();
48-
this._capacityDao = _capacityDao;
49-
this._overProvisioningFactor = _overProvisioningFactor;
46+
public StorageCapacityListener(CapacityDao capacityDao, StorageManager storageMgr) {
47+
this._capacityDao = capacityDao;
48+
this._storageMgr = storageMgr;
5049
}
5150

5251

@@ -79,9 +78,10 @@ public void processConnect(HostVO server, StartupCommand startup, boolean forReb
7978

8079
StartupStorageCommand ssCmd = (StartupStorageCommand) startup;
8180
if (ssCmd.getResourceType() == Storage.StorageResourceType.STORAGE_HOST) {
81+
BigDecimal overProvFactor = _storageMgr.getStorageOverProvisioningFactor(server.getDataCenterId());
8282
CapacityVO capacity = new CapacityVO(server.getId(),
8383
server.getDataCenterId(), server.getPodId(), server.getClusterId(), 0L,
84-
(long) (server.getTotalSize() * _overProvisioningFactor),
84+
(overProvFactor.multiply(new BigDecimal(server.getTotalSize()))).longValue(),
8585
CapacityVO.CAPACITY_TYPE_STORAGE_ALLOCATED);
8686
_capacityDao.persist(capacity);
8787
}

‎server/src/com/cloud/configuration/Config.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public enum Config {
6969

7070
// Storage
7171

72-
StorageOverprovisioningFactor("Storage", StoragePoolAllocator.class, String.class, "storage.overprovisioning.factor", "2", "Used for storage overprovisioning calculation; available storage will be (actualStorageSize * storage.overprovisioning.factor)", null),
72+
StorageOverprovisioningFactor("Storage", StoragePoolAllocator.class, String.class, "storage.overprovisioning.factor", "2", "Used for storage overprovisioning calculation; available storage will be (actualStorageSize * storage.overprovisioning.factor)", null, ConfigurationParameterScope.zone.toString()),
7373
StorageStatsInterval("Storage", ManagementServer.class, String.class, "storage.stats.interval", "60000", "The interval (in milliseconds) when storage stats (per host) are retrieved from agents.", null),
7474
MaxVolumeSize("Storage", ManagementServer.class, Integer.class, "storage.max.volume.size", "2000", "The maximum size for a volume (in GB).", null),
7575
MaxUploadVolumeSize("Storage", ManagementServer.class, Integer.class, "storage.max.volume.upload.size", "500", "The maximum size for a uploaded volume(in GB).", null),

‎server/src/com/cloud/storage/StorageManager.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// under the License.
1717
package com.cloud.storage;
1818

19+
import java.math.BigDecimal;
1920
import java.util.List;
2021
import java.util.Set;
2122

@@ -120,4 +121,5 @@ void connectHostToSharedPool(long hostId, long poolId)
120121

121122
DataStore createLocalStorage(Host host, StoragePoolInfo poolInfo) throws ConnectionException;
122123

124+
BigDecimal getStorageOverProvisioningFactor(Long dcId);
123125
}

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import javax.inject.Inject;
4141
import javax.naming.ConfigurationException;
4242

43+
import com.cloud.server.ConfigurationServer;
4344
import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd;
4445
import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
4546
import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd;
@@ -292,6 +293,8 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C
292293
SnapshotDataFactory snapshotFactory;
293294
@Inject
294295
protected HypervisorCapabilitiesDao _hypervisorCapabilitiesDao;
296+
@Inject
297+
ConfigurationServer _configServer;
295298

296299
@Inject protected ResourceTagDao _resourceTagDao;
297300

@@ -327,15 +330,15 @@ public void setDiscoverers(List<StoragePoolDiscoverer> _discoverers) {
327330
protected int _retry = 2;
328331
protected int _pingInterval = 60; // seconds
329332
protected int _hostRetry;
330-
protected BigDecimal _overProvisioningFactor = new BigDecimal(1);
333+
//protected BigDecimal _overProvisioningFactor = new BigDecimal(1);
331334
private long _maxVolumeSizeInGb;
332335
private long _serverId;
333336

334337
private int _customDiskOfferingMinSize = 1;
335338
private int _customDiskOfferingMaxSize = 1024;
336339
private double _storageUsedThreshold = 1.0d;
337340
private double _storageAllocatedThreshold = 1.0d;
338-
protected BigDecimal _storageOverprovisioningFactor = new BigDecimal(1);
341+
//protected BigDecimal _storageOverprovisioningFactor = new BigDecimal(1);
339342
private Map<String, HypervisorHostListener> hostListeners = new HashMap<String, HypervisorHostListener>();
340343

341344
private boolean _recreateSystemVmEnabled;
@@ -535,11 +538,11 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
535538
Map<String, String> configs = _configDao.getConfiguration(
536539
"management-server", params);
537540

538-
String overProvisioningFactorStr = configs
541+
/*String overProvisioningFactorStr = configs
539542
.get("storage.overprovisioning.factor");
540543
if (overProvisioningFactorStr != null) {
541544
_overProvisioningFactor = new BigDecimal(overProvisioningFactorStr);
542-
}
545+
}*/
543546

544547
_retry = NumbersUtil.parseInt(configs.get(Config.StartRetry.key()), 10);
545548
_pingInterval = NumbersUtil.parseInt(configs.get("ping.interval"), 60);
@@ -589,10 +592,11 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
589592
.parseDouble(storageAllocatedThreshold);
590593
}
591594

592-
String globalStorageOverprovisioningFactor = configs
595+
/*String globalStorageOverprovisioningFactor = configs
593596
.get("storage.overprovisioning.factor");
594597
_storageOverprovisioningFactor = new BigDecimal(NumbersUtil.parseFloat(
595598
globalStorageOverprovisioningFactor, 2.0f));
599+
*/
596600

597601
s_logger.info("Storage cleanup enabled: " + _storageCleanupEnabled
598602
+ ", interval: " + _storageCleanupInterval
@@ -979,6 +983,11 @@ public void connectHostToSharedPool(long hostId, long poolId)
979983
listener.hostConnect(hostId, pool.getId());
980984
}
981985

986+
@Override
987+
public BigDecimal getStorageOverProvisioningFactor(Long dcId){
988+
return new BigDecimal(_configServer.getConfigValue(Config.StorageOverprovisioningFactor.key(), Config.ConfigurationParameterScope.zone.toString(), dcId));
989+
}
990+
982991
@Override
983992
public void createCapacityEntry(StoragePoolVO storagePool, short capacityType, long allocated) {
984993
SearchCriteria<CapacityVO> capacitySC = _capacityDao.createSearchCriteria();
@@ -990,7 +999,8 @@ public void createCapacityEntry(StoragePoolVO storagePool, short capacityType, l
990999

9911000
long totalOverProvCapacity;
9921001
if (storagePool.getPoolType() == StoragePoolType.NetworkFilesystem) {
993-
totalOverProvCapacity = _overProvisioningFactor.multiply(new BigDecimal(storagePool.getCapacityBytes())).longValue();// All this for the inaccuracy of floats for big number multiplication.
1002+
BigDecimal overProvFactor = getStorageOverProvisioningFactor(storagePool.getDataCenterId());
1003+
totalOverProvCapacity = overProvFactor.multiply(new BigDecimal(storagePool.getCapacityBytes())).longValue();// All this for the inaccuracy of floats for big number multiplication.
9941004
} else {
9951005
totalOverProvCapacity = storagePool.getCapacityBytes();
9961006
}
@@ -1793,7 +1803,7 @@ public boolean storagePoolHasEnoughSpace(List<Volume> volumes,
17931803

17941804
long totalOverProvCapacity;
17951805
if (pool.getPoolType() == StoragePoolType.NetworkFilesystem) {
1796-
totalOverProvCapacity = _storageOverprovisioningFactor.multiply(
1806+
totalOverProvCapacity = getStorageOverProvisioningFactor(pool.getDataCenterId()).multiply(
17971807
new BigDecimal(pool.getCapacityBytes())).longValue();
17981808
} else {
17991809
totalOverProvCapacity = pool.getCapacityBytes();

0 commit comments

Comments
 (0)