Bug 9273 : [Stress Test] 'Count' in resource_count table has negative values

pushing 2.2.4 changes in to master
This commit is contained in:
Murali Reddy 2011-04-11 15:37:53 +05:30
parent 8b30507841
commit 290c799b2c
4 changed files with 16 additions and 5 deletions

View File

@ -1635,8 +1635,11 @@ public class StorageManagerImpl implements StorageManager, StorageService, Manag
// Delete the recurring snapshot policies for this volume.
_snapshotMgr.deletePoliciesForVolume(volumeId);
// Decrement the resource count for volumes
_accountMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume);
VMInstanceVO vmInstance = _vmInstanceDao.findById(volume.getInstanceId());
if(vmInstance.getType().equals(VirtualMachine.Type.User)) {
// Decrement the resource count for volumes belonging user VM's only
_accountMgr.decrementResourceCount(volume.getAccountId(), ResourceType.volume);
}
txn.commit();
}

View File

@ -230,6 +230,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
if (m_resourceCountLock.lock(120)) { // 2 minutes
try {
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
@ -237,6 +238,7 @@ public class AccountManagerImpl implements AccountManager, AccountService, Manag
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) {
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

@ -2594,6 +2594,8 @@ 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) {
@ -2612,8 +2614,12 @@ 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);
return _vmDao.findById(vmId);
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);
}
}