Skip to content

Commit

Permalink
modify batch update sql mode, remove allowMultiQueries
Browse files Browse the repository at this point in the history
  • Loading branch information
ponfee committed Mar 19, 2024
1 parent 11650f2 commit a582629
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion disjob-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<kaptcha.version>2.3.3</kaptcha.version>
<pagehelper-spring-boot-starter.version>1.4.7</pagehelper-spring-boot-starter.version>
<fastjson.version>1.2.83</fastjson.version>
<oshi-core.version>6.4.13</oshi-core.version>
<oshi-core.version>6.5.0</oshi-core.version>
<commons-io.version>2.15.1</commons-io.version>
<poi-ooxml.version>5.2.5</poi-ooxml.version>
<velocity-engine-core.version>2.3</velocity-engine-core.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public int hashCode() {
private static synchronized Current create(final String host, final int port,
final UnaryOperator<String> workerContextPath) {
if (instance != null) {
throw new Error("Current supervisor already set.");
throw new Error("Current supervisor already created.");
}

instance = new Current(host, port) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion disjob-samples/conf-supervisor/application-mysql.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void updateTaskWorker(List<UpdateTaskWorkerParam> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* <pre>
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,16 @@
AND (SELECT cnt FROM (SELECT COUNT(*) cnt FROM <include refid="Table_Name" /> WHERE instance_id = #{instanceId,jdbcType=BIGINT} AND execute_state &lt; 40) t)=0
</delete>

<!-- allowMultiQueries=true -->
<update id="batchUpdateWorker" parameterType="collection">
<foreach collection="collection" item="item" separator=";">
UPDATE <include refid="Table_Name" />
SET worker = #{item.worker,jdbcType=VARCHAR},
version = version+1
WHERE task_id = #{item.taskId,jdbcType=BIGINT}
AND execute_state = 10
</foreach>
<update id="batchUpdateWorker" parameterType="list">
UPDATE <include refid="Table_Name" />
SET version = version+1,
worker =
CASE
<foreach collection="list" item="item" separator=" ">
WHEN task_id = #{item.taskId,jdbcType=BIGINT} THEN #{item.worker,jdbcType=VARCHAR}
</foreach>
END
WHERE task_id IN (<foreach collection="list" separator="," item="item">#{item.taskId,jdbcType=BIGINT}</foreach>)
</update>

</mapper>
2 changes: 1 addition & 1 deletion disjob-supervisor/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a582629

Please sign in to comment.