cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kelv...@apache.org
Subject [3/3] git commit: updated refs/heads/4.4 to eb41250
Date Wed, 02 Apr 2014 23:06:57 GMT
Do app-level iteration to avoid mysql deadlocks


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

Branch: refs/heads/4.4
Commit: eb41250a48e8f754536c59090f593df2757c24b0
Parents: 04f5e93
Author: Kelven Yang <kelveny@gmail.com>
Authored: Wed Apr 2 15:46:50 2014 -0700
Committer: Kelven Yang <kelveny@gmail.com>
Committed: Wed Apr 2 16:01:34 2014 -0700

----------------------------------------------------------------------
 .../com/cloud/vm/VirtualMachineManagerImpl.java |  4 +-
 .../framework/jobs/dao/VmWorkJobDaoImpl.java    | 54 ++++++++++----------
 2 files changed, 28 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb41250a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 6aaedcf..d0c8543 100755
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -1,4 +1,4 @@
-// Licensed to the Apache Software Foundation (ASF) under one
+// Licensed to the Apacohe Software Foundation (ASF) under one
 // or more contributor license agreements.  See the NOTICE file
 // distributed with this work for additional information
 // regarding copyright ownership.  The ASF licenses this file
@@ -569,7 +569,7 @@ public class VirtualMachineManagerImpl extends ManagerBase implements
VirtualMac
     @Override
     public boolean start() {
         // TODO, initial delay is hardcoded
-        _executor.scheduleAtFixedRate(new CleanupTask(), 5000, VmJobStateReportInterval.value(),
TimeUnit.SECONDS);
+        _executor.scheduleAtFixedRate(new CleanupTask(), 5, VmJobStateReportInterval.value(),
TimeUnit.SECONDS);
         _executor.scheduleAtFixedRate(new TransitionTask(),  VmOpCleanupInterval.value(),
VmOpCleanupInterval.value(), TimeUnit.SECONDS);
         cancelWorkItems(_nodeId);
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb41250a/framework/jobs/src/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImpl.java
----------------------------------------------------------------------
diff --git a/framework/jobs/src/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImpl.java
b/framework/jobs/src/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImpl.java
index cf3e173..ee8748a 100644
--- a/framework/jobs/src/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImpl.java
+++ b/framework/jobs/src/org/apache/cloudstack/framework/jobs/dao/VmWorkJobDaoImpl.java
@@ -20,9 +20,10 @@ import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.util.Date;
 import java.util.List;
-import java.util.TimeZone;
-
 import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+
+import org.apache.log4j.Logger;
 
 import org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO;
 import org.apache.cloudstack.framework.jobs.impl.VmWorkJobVO.Step;
@@ -41,9 +42,14 @@ import com.cloud.utils.db.TransactionStatus;
 import com.cloud.vm.VirtualMachine;
 
 public class VmWorkJobDaoImpl extends GenericDaoBase<VmWorkJobVO, Long> implements
VmWorkJobDao {
+    private static final Logger s_logger = Logger.getLogger(VmWorkJobDaoImpl.class);
 
     protected SearchBuilder<VmWorkJobVO> PendingWorkJobSearch;
     protected SearchBuilder<VmWorkJobVO> PendingWorkJobByCommandSearch;
+    protected SearchBuilder<VmWorkJobVO> ExpungingWorkJobSearch;
+
+    @Inject
+    protected AsyncJobDao _baseJobDao;
 
     public VmWorkJobDaoImpl() {
     }
@@ -63,6 +69,12 @@ public class VmWorkJobDaoImpl extends GenericDaoBase<VmWorkJobVO, Long>
implemen
         PendingWorkJobByCommandSearch.and("step", PendingWorkJobByCommandSearch.entity().getStep(),
Op.NEQ);
         PendingWorkJobByCommandSearch.and("cmd", PendingWorkJobByCommandSearch.entity().getCmd(),
Op.EQ);
         PendingWorkJobByCommandSearch.done();
+
+        ExpungingWorkJobSearch = createSearchBuilder();
+        ExpungingWorkJobSearch.and("jobStatus", ExpungingWorkJobSearch.entity().getStatus(),
Op.NEQ);
+        ExpungingWorkJobSearch.and("cutDate", ExpungingWorkJobSearch.entity().getLastUpdated(),
Op.LT);
+        ExpungingWorkJobSearch.and("dispatcher", ExpungingWorkJobSearch.entity().getDispatcher(),
Op.EQ);
+        ExpungingWorkJobSearch.done();
     }
 
     @Override
@@ -124,33 +136,19 @@ public class VmWorkJobDaoImpl extends GenericDaoBase<VmWorkJobVO,
Long> implemen
 
                 expunge(sc);
         */
-        Transaction.execute(new TransactionCallbackNoReturn() {
-            @Override
-            public void doInTransactionWithoutResult(TransactionStatus status) {
-                TransactionLegacy txn = TransactionLegacy.currentTxn();
 
-                PreparedStatement pstmt = null;
-                try {
-                    pstmt = txn.prepareAutoCloseStatement(
-                            "DELETE FROM vm_work_job WHERE id IN (SELECT id FROM async_job
WHERE job_dispatcher='VmWorkJobDispatcher' AND job_status != 0 AND last_updated < ?)");
-                    pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"),
cutDate));
-
-                    pstmt.execute();
-                } catch (SQLException e) {
-                } catch (Throwable e) {
-                }
-
-                try {
-                    pstmt = txn.prepareAutoCloseStatement(
-                            "DELETE FROM async_job WHERE job_dispatcher='VmWorkJobDispatcher'
AND job_status != 0 AND last_updated < ?");
-                    pstmt.setString(1, DateUtil.getDateDisplayString(TimeZone.getTimeZone("GMT"),
cutDate));
-
-                    pstmt.execute();
-                } catch (SQLException e) {
-                } catch (Throwable e) {
-                }
-            }
-        });
+        // loop at application level to avoid mysql deadlock issues
+        SearchCriteria<VmWorkJobVO> sc = ExpungingWorkJobSearch.create();
+        sc.setParameters("jobStatus", JobInfo.Status.IN_PROGRESS);
+        sc.setParameters("lastUpdated", cutDate);
+        sc.setParameters("dispatcher", "VmWorkJobDispatcher");
+        List<VmWorkJobVO> expungeList = listBy(sc);
+        for (VmWorkJobVO job : expungeList) {
+            if (s_logger.isDebugEnabled())
+                s_logger.debug("Expunge completed work job-" + job.getId());
+            expunge(job.getId());
+            _baseJobDao.expunge(job.getId());
+        }
     }
 
     @Override


Mime
View raw message