Bug 9273 - Count' in resource_count table has negative values

Resolved Fixed
This commit is contained in:
Murali Reddy 2011-04-06 18:18:38 +05:30
parent 737b005f62
commit 4822fcae13
3 changed files with 9 additions and 4 deletions

View File

@ -229,14 +229,16 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
if (m_resourceCountLock.lock(120)) { // 2 minutes
try {
_resourceCountDao.updateAccountCount(accountId, type, false, numToDecrement);
assert ((_resourceCountDao.getAccountCount(accountId, type) - numToDecrement) >= 0) : "Resource counts can not be negative. Check where we skipped increment.";
_resourceCountDao.updateAccountCount(accountId, type, false, numToDecrement);
// on a per-domain basis, decrement the count
// FIXME: can this decrement be done on the database side in a custom update statement?
Account account = _accountDao.findByIdIncludingRemoved(accountId); // find all accounts, even removed accounts if this happens to be for an account that's being deleted
Long domainId = account.getDomainId();
while (domainId != null) {
_resourceCountDao.updateDomainCount(domainId, type, false, numToDecrement);
assert ((_resourceCountDao.getDomainCount(domainId, type) - numToDecrement) >= 0) : "Resource counts can not be negative. Check where we skipped increment.";
_resourceCountDao.updateDomainCount(domainId, type, false, numToDecrement);
DomainVO domain = _domainDao.findById(domainId);
domainId = domain.getParent();
}

View File

@ -2593,6 +2593,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
User caller = _userDao.findById(userId);
boolean status;
State vmState = vm.getState();
try {
status = _itMgr.destroy(vm, caller, account);
} catch (OperationTimedoutException e) {
@ -2611,7 +2612,9 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
}
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VM_DESTROY, vm.getAccountId(), vm.getDataCenterId(), vm.getId(), vm.getName());
_usageEventDao.persist(usageEvent);
_accountMgr.decrementResourceCount(vm.getAccountId(), ResourceType.user_vm);
if (vmState != State.Error) {
_accountMgr.decrementResourceCount(vm.getAccountId(), ResourceType.user_vm);
}
return _vmDao.findById(vmId);
} else {
throw new CloudRuntimeException("Failed to destroy vm with id " + vmId);

View File

@ -605,7 +605,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
}
if (dest == null) {
_accountMgr.decrementResourceCount(vm.getAccountId(), ResourceType.user_vm);
throw new InsufficientServerCapacityException("Unable to create a deployment for " + vmProfile, DataCenter.class, plan.getDataCenterId());
}
@ -693,6 +692,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
}
} finally {
if (startedVm == null) {
_accountMgr.decrementResourceCount(vm.getAccountId(), ResourceType.user_vm);
changeState(vm, Event.OperationFailed, null, work, Step.Done);
}
}