Bug 9666 - hostId and spoolId overlap in op_host_capacity table

Changes:
- When a host connects, we check if it has a CPU and RAM entry in capacity table. If the entry is found, the values are updated if possible. If the entry is not found a new one is inserted.
- The searchCriteria used to check if CPU entry is present was wrong. We were passing in a criteria which did not specify capacityType. So for hostId >= 200, the serach would return capacity entries of storage pools also since poolIDs start from 200 onwards.
- Since an entry was found (although the wrong one), we tried to update it. But update does not happen since the capacity ranges dont match.
And a new insert for CPU also does not happen since an entry is found.
- So as a result CPU entries are never inserted in the table for hostIds >=200

- As a fix, corrected the search criteria.
- During VM deployment, when the entry is not found, we get a NPE. Added a null check to avoid that.
This commit is contained in:
prachi 2011-05-02 15:17:11 -07:00
parent c6965f06cc
commit 1d4a59ce73
2 changed files with 151 additions and 139 deletions

View File

@ -74,7 +74,6 @@ import com.cloud.agent.manager.allocator.PodAllocator;
import com.cloud.agent.transport.Request;
import com.cloud.agent.transport.Response;
import com.cloud.alert.AlertManager;
import com.cloud.api.ApiConstants;
import com.cloud.api.commands.AddClusterCmd;
import com.cloud.api.commands.AddHostCmd;
import com.cloud.api.commands.AddSecondaryStorageCmd;
@ -2735,7 +2734,7 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, ResourceS
capacityCPU.addAnd("dataCenterId", SearchCriteria.Op.EQ, server.getDataCenterId());
capacityCPU.addAnd("podId", SearchCriteria.Op.EQ, server.getPodId());
capacityCPU.addAnd("capacityType", SearchCriteria.Op.EQ, CapacityVO.CAPACITY_TYPE_CPU);
List<CapacityVO> capacityVOCpus = _capacityDao.search(capacitySC, null);
List<CapacityVO> capacityVOCpus = _capacityDao.search(capacityCPU, null);
if (capacityVOCpus != null && !capacityVOCpus.isEmpty()) {
CapacityVO CapacityVOCpu = capacityVOCpus.get(0);

View File

@ -34,7 +34,6 @@ import com.cloud.configuration.Config;
import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.Status;
import com.cloud.host.dao.HostDao;
import com.cloud.offering.ServiceOffering;
import com.cloud.service.ServiceOfferingVO;
@ -44,7 +43,6 @@ import com.cloud.utils.NumbersUtil;
import com.cloud.utils.component.Inject;
import com.cloud.utils.concurrency.NamedThreadFactory;
import com.cloud.utils.db.DB;
import com.cloud.utils.db.SearchCriteria;
import com.cloud.utils.db.Transaction;
import com.cloud.utils.fsm.StateListener;
import com.cloud.vm.VMInstanceVO;
@ -277,6 +275,21 @@ public class CapacityManagerImpl implements CapacityManager , StateListener<Stat
CapacityVO capacityCpu = _capacityDao.findByHostIdType(hostId, CapacityVO.CAPACITY_TYPE_CPU);
CapacityVO capacityMem = _capacityDao.findByHostIdType(hostId, CapacityVO.CAPACITY_TYPE_MEMORY);
if (capacityCpu == null || capacityMem == null) {
if(capacityCpu == null){
if (s_logger.isDebugEnabled()) {
s_logger.debug("Cannot checkIfHostHasCapacity, Capacity entry for CPU not found in Db, for hostId: "+ hostId);
}
}
if(capacityMem == null){
if (s_logger.isDebugEnabled()) {
s_logger.debug("Cannot checkIfHostHasCapacity, Capacity entry for RAM not found in Db, for hostId: "+ hostId);
}
}
return false;
}
long usedCpu = capacityCpu.getUsedCapacity();
long usedMem = capacityMem.getUsedCapacity();
long reservedCpu = capacityCpu.getReservedCapacity();