From a5826292a59e155eece858a1bf9d30612f589d20 Mon Sep 17 00:00:00 2001 From: Ponfee Date: Tue, 19 Mar 2024 23:12:35 +0800 Subject: [PATCH] modify batch update sql mode, remove allowMultiQueries --- disjob-admin/pom.xml | 2 +- .../resources/application-disjob-mysql.yml | 2 +- .../ponfee/disjob/core/base/Supervisor.java | 2 +- .../cn/ponfee/disjob/core/base/Worker.java | 2 +- .../conf-supervisor/application-mysql.yml | 2 +- .../application-registry_database.yml | 2 +- .../component/DistributedJobManager.java | 2 +- .../dao/SupervisorDataSourceConfig.java | 2 +- .../supervisor/dao/xml/SchedTaskMapper.xml | 19 ++++++++++--------- .../src/test/resources/application.yml | 2 +- 10 files changed, 19 insertions(+), 18 deletions(-) diff --git a/disjob-admin/pom.xml b/disjob-admin/pom.xml index abc7ee9b2..a78eb52b7 100644 --- a/disjob-admin/pom.xml +++ b/disjob-admin/pom.xml @@ -42,7 +42,7 @@ 2.3.3 1.4.7 1.2.83 - 6.4.13 + 6.5.0 2.15.1 5.2.5 2.3 diff --git a/disjob-admin/ruoyi-disjob/src/main/resources/application-disjob-mysql.yml b/disjob-admin/ruoyi-disjob/src/main/resources/application-disjob-mysql.yml index 51d9d3f35..55708ba02 100644 --- a/disjob-admin/ruoyi-disjob/src/main/resources/application-disjob-mysql.yml +++ b/disjob-admin/ruoyi-disjob/src/main/resources/application-disjob-mysql.yml @@ -1,7 +1,7 @@ # database configuration disjob.datasource: driver-class-name: com.mysql.cj.jdbc.Driver - jdbc-url: jdbc:mysql://localhost:3306/disjob?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&connectTimeout=2000&socketTimeout=5000&serverTimezone=Asia/Shanghai&failOverReadOnly=false + jdbc-url: jdbc:mysql://localhost:3306/disjob?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&connectTimeout=2000&socketTimeout=5000&serverTimezone=Asia/Shanghai&failOverReadOnly=false username: disjob password: disjob$123456 minimum-idle: 2 diff --git a/disjob-core/src/main/java/cn/ponfee/disjob/core/base/Supervisor.java b/disjob-core/src/main/java/cn/ponfee/disjob/core/base/Supervisor.java index aeb2df8bc..ee43f8c0a 100644 --- a/disjob-core/src/main/java/cn/ponfee/disjob/core/base/Supervisor.java +++ b/disjob-core/src/main/java/cn/ponfee/disjob/core/base/Supervisor.java @@ -169,7 +169,7 @@ public int hashCode() { private static synchronized Current create(final String host, final int port, final UnaryOperator workerContextPath) { if (instance != null) { - throw new Error("Current supervisor already set."); + throw new Error("Current supervisor already created."); } instance = new Current(host, port) { diff --git a/disjob-core/src/main/java/cn/ponfee/disjob/core/base/Worker.java b/disjob-core/src/main/java/cn/ponfee/disjob/core/base/Worker.java index d891acfcb..5690e4331 100644 --- a/disjob-core/src/main/java/cn/ponfee/disjob/core/base/Worker.java +++ b/disjob-core/src/main/java/cn/ponfee/disjob/core/base/Worker.java @@ -268,7 +268,7 @@ private static synchronized Current create(final String group, final String work final String wToken, final String sToken, final String supervisorContextPath) { if (instance != null) { - throw new Error("Current worker already set."); + throw new Error("Current worker already created."); } instance = new Current(group, workerId, host, port) { diff --git a/disjob-samples/conf-supervisor/application-mysql.yml b/disjob-samples/conf-supervisor/application-mysql.yml index 798f19f50..ab97d8d94 100644 --- a/disjob-samples/conf-supervisor/application-mysql.yml +++ b/disjob-samples/conf-supervisor/application-mysql.yml @@ -1,7 +1,7 @@ # database configuration disjob.datasource: driver-class-name: com.mysql.cj.jdbc.Driver - jdbc-url: jdbc:mysql://localhost:3306/disjob?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&connectTimeout=2000&socketTimeout=5000&serverTimezone=Asia/Shanghai&failOverReadOnly=false + jdbc-url: jdbc:mysql://localhost:3306/disjob?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&connectTimeout=2000&socketTimeout=5000&serverTimezone=Asia/Shanghai&failOverReadOnly=false username: disjob password: disjob$123456 minimum-idle: 2 diff --git a/disjob-samples/disjob-samples-springboot-common/src/main/resources/application-registry_database.yml b/disjob-samples/disjob-samples-springboot-common/src/main/resources/application-registry_database.yml index 118afa5f1..019cd9dd6 100644 --- a/disjob-samples/disjob-samples-springboot-common/src/main/resources/application-registry_database.yml +++ b/disjob-samples/disjob-samples-springboot-common/src/main/resources/application-registry_database.yml @@ -4,7 +4,7 @@ disjob.registry.database: session-timeout-ms: 30000 datasource: driver-class-name: com.mysql.cj.jdbc.Driver - jdbc-url: jdbc:mysql://localhost:3306/disjob?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&connectTimeout=2000&socketTimeout=5000&serverTimezone=Asia/Shanghai&failOverReadOnly=false + jdbc-url: jdbc:mysql://localhost:3306/disjob?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&connectTimeout=2000&socketTimeout=5000&serverTimezone=Asia/Shanghai&failOverReadOnly=false username: disjob password: disjob$123456 minimum-idle: 2 diff --git a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/component/DistributedJobManager.java b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/component/DistributedJobManager.java index fbcd06c05..ccb7ac137 100644 --- a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/component/DistributedJobManager.java +++ b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/component/DistributedJobManager.java @@ -194,7 +194,7 @@ public void updateTaskWorker(List list) { if (CollectionUtils.isNotEmpty(list)) { // Sort for prevent sql deadlock: Deadlock found when trying to get lock; try restarting transaction list.sort(Comparator.comparingLong(UpdateTaskWorkerParam::getTaskId)); - Collects.batchProcess(list, taskMapper::batchUpdateWorker, PROCESS_BATCH_SIZE); + Collects.batchProcess(list, taskMapper::batchUpdateWorker, 20); } } diff --git a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/dao/SupervisorDataSourceConfig.java b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/dao/SupervisorDataSourceConfig.java index edfab1f8e..461f14136 100644 --- a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/dao/SupervisorDataSourceConfig.java +++ b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/dao/SupervisorDataSourceConfig.java @@ -39,7 +39,7 @@ *
  *  disjob.datasource:
  *    driver-class-name: com.mysql.cj.jdbc.Driver
- *    jdbc-url: jdbc:mysql://localhost:3306/disjob?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&connectTimeout=2000&socketTimeout=5000&serverTimezone=Asia/Shanghai&failOverReadOnly=false
+ *    jdbc-url: jdbc:mysql://localhost:3306/disjob?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&connectTimeout=2000&socketTimeout=5000&serverTimezone=Asia/Shanghai&failOverReadOnly=false
  *    username: disjob
  *    password:
  *    minimum-idle: 10
diff --git a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/dao/xml/SchedTaskMapper.xml b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/dao/xml/SchedTaskMapper.xml
index 3fb960592..70825b3d6 100644
--- a/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/dao/xml/SchedTaskMapper.xml
+++ b/disjob-supervisor/src/main/java/cn/ponfee/disjob/supervisor/dao/xml/SchedTaskMapper.xml
@@ -137,15 +137,16 @@
       AND (SELECT cnt FROM (SELECT COUNT(*) cnt FROM  WHERE instance_id = #{instanceId,jdbcType=BIGINT} AND execute_state < 40) t)=0
   
 
-  
-  
-    
-      UPDATE 
-      SET worker = #{item.worker,jdbcType=VARCHAR},
-          version = version+1
-      WHERE task_id = #{item.taskId,jdbcType=BIGINT}
-        AND execute_state = 10
-    
+  
+    UPDATE 
+    SET version = version+1,
+        worker =
+          CASE
+            
+              WHEN task_id = #{item.taskId,jdbcType=BIGINT} THEN #{item.worker,jdbcType=VARCHAR}
+            
+          END
+    WHERE task_id IN (#{item.taskId,jdbcType=BIGINT})
   
 
 
diff --git a/disjob-supervisor/src/test/resources/application.yml b/disjob-supervisor/src/test/resources/application.yml
index ebe8e64b6..aa6d06770 100644
--- a/disjob-supervisor/src/test/resources/application.yml
+++ b/disjob-supervisor/src/test/resources/application.yml
@@ -3,7 +3,7 @@ server.port: 0
 # database configuration
 disjob.datasource:
   driver-class-name: com.mysql.cj.jdbc.Driver
-  jdbc-url: jdbc:mysql://localhost:23306/disjob?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&connectTimeout=2000&socketTimeout=5000&serverTimezone=Asia/Shanghai&failOverReadOnly=false
+  jdbc-url: jdbc:mysql://localhost:23306/disjob?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&connectTimeout=2000&socketTimeout=5000&serverTimezone=Asia/Shanghai&failOverReadOnly=false
   username: disjob
   password: disjob$123456
   minimum-idle: 2