bug 10847: sg got executed in a big transaction leading to the deadlock

This commit is contained in:
Alex Huang 2011-07-25 17:41:11 -07:00
parent 9c627a15f3
commit 200d2b9cd0

View File

@ -556,16 +556,19 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
throw new ConcurrentOperationException("Unable to change the state of " + vm); throw new ConcurrentOperationException("Unable to change the state of " + vm);
} }
@DB
protected <T extends VMInstanceVO> boolean changeState(T vm, Event event, Long hostId, ItWorkVO work, Step step) throws NoTransitionException { protected <T extends VMInstanceVO> boolean changeState(T vm, Event event, Long hostId, ItWorkVO work, Step step) throws NoTransitionException {
Transaction txn = Transaction.currentTxn(); // FIXME: We should do this better.
txn.start(); Step previousStep = work.getStep();
if (!stateTransitTo(vm, event, hostId)) {
return false;
}
_workDao.updateStep(work, step); _workDao.updateStep(work, step);
txn.commit(); boolean result = false;
return true; try {
result = stateTransitTo(vm, event, hostId);
return result;
} finally {
if (!result) {
_workDao.updateStep(work, previousStep);
}
}
} }
@Override @Override