mirror of https://github.com/apache/cloudstack.git
bug 5781: also reduce the scope of the global lock when updating storage capacity.
This commit is contained in:
parent
adce18b2c0
commit
d2ffa6b68d
|
|
@ -433,7 +433,7 @@ public class AlertManagerImpl implements AlertManager {
|
|||
CapacityVO newPrivateIPCapacity = new CapacityVO(null, dcId, podId, allocatedPrivateIPs, totalPrivateIPs, CapacityVO.CAPACITY_TYPE_PRIVATE_IP);
|
||||
newCapacities.add(newPrivateIPCapacity);
|
||||
}
|
||||
|
||||
|
||||
if (m_capacityCheckLock.lock(5)) { // 5 second timeout
|
||||
try {
|
||||
// delete the old records
|
||||
|
|
|
|||
|
|
@ -292,8 +292,50 @@ public class StatsCollector {
|
|||
}
|
||||
}
|
||||
_storagePoolStats = storagePoolStats;
|
||||
|
||||
// a list to store the new capacity entries that will be committed once everything is calculated
|
||||
List<CapacityVO> newCapacities = new ArrayList<CapacityVO>();
|
||||
|
||||
if (m_capacityCheckLock.lock(5)) { // 5 second timeout
|
||||
// create new entries
|
||||
for (Long hostId : storageStats.keySet()) {
|
||||
StorageStats stats = storageStats.get(hostId);
|
||||
HostVO host = _hostDao.findById(hostId);
|
||||
host.setTotalSize(stats.getCapacityBytes());
|
||||
_hostDao.update(host.getId(), host);
|
||||
|
||||
if (Host.Type.SecondaryStorage.equals(host.getType())) {
|
||||
CapacityVO capacity = new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), stats.getByteUsed(), stats.getCapacityBytes(), CapacityVO.CAPACITY_TYPE_SECONDARY_STORAGE);
|
||||
newCapacities.add(capacity);
|
||||
// _capacityDao.persist(capacity);
|
||||
} else if (Host.Type.Storage.equals(host.getType())) {
|
||||
CapacityVO capacity = new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), stats.getByteUsed(), stats.getCapacityBytes(), CapacityVO.CAPACITY_TYPE_STORAGE);
|
||||
newCapacities.add(capacity);
|
||||
// _capacityDao.persist(capacity);
|
||||
}
|
||||
}
|
||||
|
||||
for (Long poolId : storagePoolStats.keySet()) {
|
||||
StorageStats stats = storagePoolStats.get(poolId);
|
||||
StoragePoolVO pool = _storagePoolDao.findById(poolId);
|
||||
|
||||
if (pool == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pool.setCapacityBytes(stats.getCapacityBytes());
|
||||
long available = stats.getCapacityBytes() - stats.getByteUsed();
|
||||
if( available < 0 ) {
|
||||
available = 0;
|
||||
}
|
||||
pool.setAvailableBytes(available);
|
||||
_storagePoolDao.update(pool.getId(), pool);
|
||||
|
||||
CapacityVO capacity = new CapacityVO(poolId, pool.getDataCenterId(), pool.getPodId(), stats.getByteUsed(), stats.getCapacityBytes(), CapacityVO.CAPACITY_TYPE_STORAGE);
|
||||
newCapacities.add(capacity);
|
||||
// _capacityDao.persist(capacity);
|
||||
}
|
||||
|
||||
if (m_capacityCheckLock.lock(5)) { // 5 second timeout
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("recalculating system storage capacity");
|
||||
}
|
||||
|
|
@ -304,54 +346,22 @@ public class StatsCollector {
|
|||
// to collect the stats from an agent and update the database as needed. The
|
||||
// listener model has connects/disconnects to keep things in sync much better
|
||||
// than this model right now
|
||||
_capacityDao.clearStorageCapacities();
|
||||
|
||||
// create new entries
|
||||
for (Long hostId : storageStats.keySet()) {
|
||||
StorageStats stats = storageStats.get(hostId);
|
||||
HostVO host = _hostDao.findById(hostId);
|
||||
host.setTotalSize(stats.getCapacityBytes());
|
||||
_hostDao.update(host.getId(), host);
|
||||
|
||||
if (Host.Type.SecondaryStorage.equals(host.getType())) {
|
||||
CapacityVO capacity = new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), stats.getByteUsed(), stats.getCapacityBytes(), CapacityVO.CAPACITY_TYPE_SECONDARY_STORAGE);
|
||||
_capacityDao.persist(capacity);
|
||||
} else if (Host.Type.Storage.equals(host.getType())) {
|
||||
CapacityVO capacity = new CapacityVO(host.getId(), host.getDataCenterId(), host.getPodId(), stats.getByteUsed(), stats.getCapacityBytes(), CapacityVO.CAPACITY_TYPE_STORAGE);
|
||||
_capacityDao.persist(capacity);
|
||||
}
|
||||
}
|
||||
|
||||
for (Long poolId : storagePoolStats.keySet()) {
|
||||
StorageStats stats = storagePoolStats.get(poolId);
|
||||
StoragePoolVO pool = _storagePoolDao.findById(poolId);
|
||||
|
||||
if (pool == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pool.setCapacityBytes(stats.getCapacityBytes());
|
||||
long available = stats.getCapacityBytes() - stats.getByteUsed();
|
||||
if( available < 0 ) {
|
||||
available = 0;
|
||||
}
|
||||
pool.setAvailableBytes(available);
|
||||
_storagePoolDao.update(pool.getId(), pool);
|
||||
|
||||
CapacityVO capacity = new CapacityVO(poolId, pool.getDataCenterId(), pool.getPodId(), stats.getByteUsed(), stats.getCapacityBytes(), CapacityVO.CAPACITY_TYPE_STORAGE);
|
||||
_capacityDao.persist(capacity);
|
||||
}
|
||||
} finally {
|
||||
m_capacityCheckLock.unlock();
|
||||
_capacityDao.clearStorageCapacities();
|
||||
|
||||
for (CapacityVO newCapacity : newCapacities) {
|
||||
_capacityDao.persist(newCapacity);
|
||||
}
|
||||
} finally {
|
||||
m_capacityCheckLock.unlock();
|
||||
}
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("done recalculating system storage capacity");
|
||||
}
|
||||
} else {
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("not recalculating system storage capacity, unable to lock capacity table");
|
||||
}
|
||||
}
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("done recalculating system storage capacity");
|
||||
}
|
||||
} else {
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("not recalculating system storage capacity, unable to lock capacity table");
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
s_logger.error("Error trying to retrieve storage stats", t);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue