cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject [1/3] git commit: updated refs/heads/master to ce1e53f
Date Wed, 19 Mar 2014 00:00:56 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master 0c1b6b44a -> ce1e53f45


avoid mysql lock-promotion situation.


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/de252ada
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/de252ada
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/de252ada

Branch: refs/heads/master
Commit: de252adadf4816b62d5e686b92b42837ae83e20a
Parents: 0c1b6b4
Author: Kelven Yang <kelveny@gmail.com>
Authored: Sat Mar 15 12:56:19 2014 -0700
Committer: Kelven Yang <kelveny@gmail.com>
Committed: Tue Mar 18 16:45:02 2014 -0700

----------------------------------------------------------------------
 .../src/com/cloud/host/dao/HostDaoImpl.java     |  3 +-
 .../src/com/cloud/vm/dao/VMInstanceDaoImpl.java | 73 ++++++++++----------
 2 files changed, 40 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/de252ada/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java b/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
index 426c90d..3a3bdf6 100755
--- a/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
+++ b/engine/schema/src/com/cloud/host/dao/HostDaoImpl.java
@@ -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());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/de252ada/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java b/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
index 7c59492..0c13ae7 100644
--- a/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
+++ b/engine/schema/src/com/cloud/vm/dao/VMInstanceDaoImpl.java
@@ -417,41 +417,44 @@ public class VMInstanceDaoImpl extends GenericDaoBase<VMInstanceVO,
Long> implem
 
     @Override
     public boolean updateState(State oldState, Event event, State newState, VirtualMachine
vm, Object opaque) {
-        if (newState == null) {
-            if (s_logger.isDebugEnabled()) {
-                s_logger.debug("There's no way to transition from old state: " + oldState.toString()
+ " event: " + event.toString());
-            }
-            return false;
-        }
-
-        @SuppressWarnings("unchecked")
-        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))
{
-            // state is same, don't need to update
-            return true;
-        }
-
-        SearchCriteria<VMInstanceVO> sc = StateChangeSearch.create();
-        sc.setParameters("id", vmi.getId());
-        sc.setParameters("states", oldState);
-        sc.setParameters("host", vmi.getHostId());
-        sc.setParameters("update", vmi.getUpdated());
-
-        vmi.incrUpdated();
-        UpdateBuilder ub = getUpdateBuilder(vmi);
-
-        ub.set(vmi, "state", newState);
-        ub.set(vmi, "hostId", newHostId);
-        ub.set(vmi, "podIdToDeployIn", vmi.getPodIdToDeployIn());
-        ub.set(vmi, _updateTimeAttr, new Date());
-
-        int result = update(vmi, sc);
+    	if (newState == null) {
+    		if (s_logger.isDebugEnabled()) {
+    			s_logger.debug("There's no way to transition from old state: " + oldState.toString()
+ " event: " + event.toString());
+    		}
+    		return false;
+    	}
+
+    	@SuppressWarnings("unchecked")
+		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)
) {
+    	    // 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);
+    	sc.setParameters("host", vmi.getHostId());
+    	sc.setParameters("update", vmi.getUpdated());
+
+    	vmi.incrUpdated();
+    	UpdateBuilder ub = getUpdateBuilder(vmi);
+
+    	ub.set(vmi, "state", newState);
+    	ub.set(vmi, "hostId", newHostId);
+    	ub.set(vmi, "podIdToDeployIn", vmi.getPodIdToDeployIn());
+    	ub.set(vmi, _updateTimeAttr, new Date());
+
+    	int result = update(vmi, sc);
         if (result == 0) {
             VMInstanceVO vo = findByIdIncludingRemoved(vm.getId());
 


Mime
View raw message