mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-15 18:12:35 +01:00
avoid mysql lock-promotion situation.
This commit is contained in:
parent
0c1b6b44a8
commit
de252adadf
@ -899,7 +899,8 @@ public class HostDaoImpl extends GenericDaoBase<HostVO, Long> implements HostDao
|
||||
|
||||
@Override
|
||||
public boolean updateState(Status oldStatus, Event event, Status newStatus, Host vo, Object data) {
|
||||
HostVO host = findById(vo.getId());
|
||||
// lock target row from beginning to avoid lock-promotion caused deadlock
|
||||
HostVO host = lockRow(vo.getId(), true);
|
||||
if (host == null) {
|
||||
if (event == Event.Remove && newStatus == Status.Removed) {
|
||||
host = findByIdIncludingRemoved(vo.getId());
|
||||
|
||||
@ -425,18 +425,21 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO, Long> implem
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Pair<Long, Long> hosts = (Pair<Long, Long>)opaque;
|
||||
Pair<Long, Long> hosts = (Pair<Long,Long>)opaque;
|
||||
Long newHostId = hosts.second();
|
||||
|
||||
VMInstanceVO vmi = (VMInstanceVO)vm;
|
||||
Long oldHostId = vmi.getHostId();
|
||||
Long oldUpdated = vmi.getUpdated();
|
||||
Date oldUpdateDate = vmi.getUpdateTime();
|
||||
if (newState.equals(oldState) && newHostId != null && newHostId.equals(oldHostId)) {
|
||||
if ( newState.equals(oldState) && newHostId != null && newHostId.equals(oldHostId) ) {
|
||||
// state is same, don't need to update
|
||||
return true;
|
||||
}
|
||||
|
||||
// lock the target row at beginning to avoid lock-promotion caused deadlock
|
||||
lockRow(vm.getId(), true);
|
||||
|
||||
SearchCriteria<VMInstanceVO> sc = StateChangeSearch.create();
|
||||
sc.setParameters("id", vmi.getId());
|
||||
sc.setParameters("states", oldState);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user