server: count hosts than get all hosts in capacity scans

This refactors hotspot code to fetch just the count of hosts than
all the host VOs for a zone, during capacity scans for systemvms.
This reduces CPU and DB load, in really large (10k+ hosts) env.

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2024-05-03 18:26:44 +05:30
parent 2a48d71909
commit c01aad6ba8
4 changed files with 15 additions and 4 deletions

View File

@ -41,6 +41,8 @@ public interface HostDao extends GenericDao<HostVO, Long>, StateDao<Status, Stat
Integer countAllByTypeInZone(long zoneId, final Host.Type type);
Integer countUpAndEnabledHostsInZone(long zoneId);
/**
* Mark all hosts associated with a certain management server
* as disconnected.

View File

@ -481,6 +481,15 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
return getCount(sc);
}
@Override
public Integer countUpAndEnabledHostsInZone(long zoneId) {
SearchCriteria<HostVO> sc = HostTypeCountSearch.create();
sc.setParameters("type", Type.Routing);
sc.setParameters("resourceState", ResourceState.Enabled);
sc.setParameters("dc", zoneId);
return getCount(sc);
}
@Override
public List<HostVO> listByDataCenterId(long id) {
return listByDataCenterIdAndState(id, ResourceState.Enabled);

View File

@ -864,8 +864,8 @@ public class ConsoleProxyManagerImpl extends ManagerBase implements ConsoleProxy
}
public boolean isZoneReady(Map<Long, ZoneHostInfo> zoneHostInfoMap, long dataCenterId) {
List <HostVO> hosts = hostDao.listByDataCenterId(dataCenterId);
if (CollectionUtils.isEmpty(hosts)) {
Integer totalUpAndEnabledHosts = hostDao.countUpAndEnabledHostsInZone(dataCenterId);
if (totalUpAndEnabledHosts != null && totalUpAndEnabledHosts < 1) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Zone " + dataCenterId + " has no host available which is enabled and in Up state");
}

View File

@ -796,8 +796,8 @@ public class SecondaryStorageManagerImpl extends ManagerBase implements Secondar
}
public boolean isZoneReady(Map<Long, ZoneHostInfo> zoneHostInfoMap, long dataCenterId) {
List <HostVO> hosts = _hostDao.listByDataCenterId(dataCenterId);
if (CollectionUtils.isEmpty(hosts)) {
Integer totalUpAndEnabledHosts = _hostDao.countUpAndEnabledHostsInZone(dataCenterId);
if (totalUpAndEnabledHosts != null && totalUpAndEnabledHosts < 1) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Zone " + dataCenterId + " has no host available which is enabled and in Up state");
}