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
5dd3abee75
commit
f3eac52831
|
|
@ -443,7 +443,7 @@ public class AlertManagerImpl implements AlertManager {
|
|||
newCapacities.add(newPrivateIPCapacity);
|
||||
// _capacityDao.persist(newPrivateIPCapacity);
|
||||
}
|
||||
|
||||
|
||||
if (m_capacityCheckLock.lock(5)) { // 5 second timeout
|
||||
try {
|
||||
// delete the old records
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ import com.cloud.storage.StoragePoolVO;
|
|||
import com.cloud.storage.StorageStats;
|
||||
import com.cloud.storage.VolumeStats;
|
||||
import com.cloud.storage.VolumeVO;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
import com.cloud.storage.dao.StoragePoolDao;
|
||||
import com.cloud.storage.dao.StoragePoolHostDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
|
|
@ -296,8 +295,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");
|
||||
}
|
||||
|
|
@ -308,54 +349,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