Skip to content

Commit 7c71f04

Browse files
authored
Merge pull request #3890 from jsonwan/github_perf/jdk17
perf: 升级JDK17问题处理 #3887
2 parents 885c2f3 + 61095c3 commit 7c71f04

File tree

11 files changed

+189
-94
lines changed

11 files changed

+189
-94
lines changed

op-tools/batch-invoke/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def main():
8383
if plan == "exit":
8484
break
8585
elif os.path.exists(plan):
86-
initial_cmd = "./" + plan
86+
initial_cmd = "bash ./" + plan
8787
else:
8888
print("输入的脚本不存在,请重新输入")
8989
continue

src/backend/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ subprojects {
400400
dependency "com.squareup.okhttp3:okhttp:$okHttpVersion"
401401
dependency "com.rabbitmq:amqp-client:$amqpClientVersion"
402402
dependency "org.eclipse.jgit:org.eclipse.jgit:$jgitVersion"
403-
dependency "mysql:mysql-connector-java:$mysqlConnectorVersion"
403+
dependency "com.mysql:mysql-connector-j:$mysqlConnectorVersion"
404404
}
405405
}
406406
dependencies {

src/backend/commons/common-mysql-sharding/leaf_gen_jooq.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ apply plugin: 'nu.studer.jooq'
2525

2626
dependencies {
2727
api "org.jooq:jooq"
28-
jooqGenerator 'mysql:mysql-connector-java'
28+
jooqGenerator 'com.mysql:mysql-connector-j'
2929
}
3030

3131
def databaseName = "job_leaf"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making BK-JOB蓝鲸智云作业平台 available.
3+
*
4+
* Copyright (C) 2021 Tencent. All rights reserved.
5+
*
6+
* BK-JOB蓝鲸智云作业平台 is licensed under the MIT License.
7+
*
8+
* License for BK-JOB蓝鲸智云作业平台:
9+
* --------------------------------------------------------------------
10+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
11+
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
12+
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
13+
* to permit persons to whom the Software is furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of
16+
* the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
19+
* THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21+
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22+
* IN THE SOFTWARE.
23+
*/
24+
25+
package com.tencent.bk.job.common.mysql.listener;
26+
27+
import lombok.extern.slf4j.Slf4j;
28+
import org.jooq.ExecuteContext;
29+
import org.jooq.ExecuteListener;
30+
31+
import java.sql.Connection;
32+
33+
/**
34+
* 打印SQL连接信息的监听器,用于排查某些连接相关的问题
35+
*/
36+
@Slf4j
37+
public class ConnectionLoggingListener implements ExecuteListener {
38+
@Override
39+
public void prepareStart(ExecuteContext ctx) {
40+
try {
41+
logConnectionInfo(ctx);
42+
} catch (Throwable t) {
43+
log.warn("Fail to logConnectionInfo", t);
44+
}
45+
}
46+
47+
/**
48+
* 打印SQL连接信息
49+
*
50+
* @param ctx SQL执行上下文
51+
*/
52+
private void logConnectionInfo(ExecuteContext ctx) {
53+
Connection connection = ctx.connection();
54+
int connectionHashId = connection != null ? System.identityHashCode(connection) : -1;
55+
if (connection == null) {
56+
log.warn("connection is null");
57+
return;
58+
}
59+
if (log.isDebugEnabled()) {
60+
log.debug("connectionHashId=" + connectionHashId);
61+
}
62+
}
63+
64+
@Override
65+
public void renderEnd(ExecuteContext ctx) {
66+
if (log.isDebugEnabled()) {
67+
log.debug("SQL=" + ctx.sql());
68+
}
69+
}
70+
}

src/backend/commons/common-mysql/src/main/java/com/tencent/bk/job/common/mysql/util/JooqConfigurationUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ public class JooqConfigurationUtil {
3737
/**
3838
* 获取jOOQ配置
3939
*
40-
* @param connectionProvider 连接提供者
41-
* @param executeListenerProvider 执行监听器提供者
40+
* @param connectionProvider 连接提供者
41+
* @param executeListenerProviders 执行监听器提供者数组
4242
* @return jOOQ配置
4343
*/
4444
public static org.jooq.Configuration getConfiguration(ConnectionProvider connectionProvider,
45-
DefaultExecuteListenerProvider executeListenerProvider) {
45+
DefaultExecuteListenerProvider... executeListenerProviders) {
4646
org.jooq.Configuration configuration = new DefaultConfiguration()
4747
.derive(connectionProvider)
4848
.derive(SQLDialect.MYSQL);
49-
configuration.set(executeListenerProvider);
49+
configuration.set(executeListenerProviders);
5050
return configuration;
5151
}
5252
}

src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/AbstractStepEventHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected void finishStepWithAbnormalState(StepInstanceDTO stepInstance) {
7474
protected void finishStep(StepInstanceDTO stepInstance, RunStatusEnum status) {
7575
long endTime = System.currentTimeMillis();
7676
if (!RunStatusEnum.isFinishedStatus(stepInstance.getStatus())) {
77-
long totalTime = TaskCostCalculator.calculate(stepInstance.getStartTime(), endTime,
77+
Long totalTime = TaskCostCalculator.calculate(stepInstance.getStartTime(), endTime,
7878
stepInstance.getTotalTime());
7979
stepInstanceService.updateStepExecutionInfo(
8080
stepInstance.getTaskInstanceId(),

src/backend/job-execute/service-job-execute/src/main/java/com/tencent/bk/job/execute/engine/listener/GseStepEventHandler.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,12 @@ private void startStep(StepEvent stepEvent, StepInstanceDTO stepInstance) {
190190
Long gseTaskId = saveInitialGseTask(stepInstance);
191191
saveExecuteObjectTasksForStartStep(gseTaskId, stepInstance, rollingConfig);
192192

193+
// 设置步骤开始时间
194+
if (stepInstance.getStartTime() == null) {
195+
stepInstance.setStartTime(DateUtils.currentTimeMillis());
196+
}
193197
stepInstanceService.updateStepExecutionInfo(taskInstanceId, stepInstanceId, RunStatusEnum.RUNNING,
194-
stepInstance.getStartTime() == null ? DateUtils.currentTimeMillis() : null, null, null);
198+
stepInstance.getStartTime(), null, null);
195199
if (isRollingStep) {
196200
stepInstanceRollingTaskService.updateRollingTask(
197201
taskInstanceId,

src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/config/DbConfig.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,12 @@
2424

2525
package com.tencent.bk.job.file_gateway.config;
2626

27+
import com.tencent.bk.job.common.mysql.listener.ConnectionLoggingListener;
2728
import com.tencent.bk.job.common.mysql.util.JooqConfigurationUtil;
2829
import org.jooq.ConnectionProvider;
2930
import org.jooq.DSLContext;
30-
import org.jooq.SQLDialect;
3131
import org.jooq.conf.Settings;
3232
import org.jooq.impl.DataSourceConnectionProvider;
33-
import org.jooq.impl.DefaultConfiguration;
34-
import org.jooq.impl.DefaultDSLContext;
3533
import org.jooq.impl.DefaultExecuteListenerProvider;
3634
import org.springframework.beans.factory.annotation.Qualifier;
3735
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -86,7 +84,11 @@ public DSLContext dslContext(
8684
@Qualifier("job-file-gateway-conn-provider") ConnectionProvider connectionProvider,
8785
DefaultExecuteListenerProvider jooqExecuteListenerProvider
8886
) {
89-
return JooqConfigurationUtil.getConfiguration(connectionProvider, jooqExecuteListenerProvider);
87+
return JooqConfigurationUtil.getConfiguration(
88+
connectionProvider,
89+
jooqExecuteListenerProvider,
90+
new DefaultExecuteListenerProvider(new ConnectionLoggingListener())
91+
);
9092
}
9193

9294
@Qualifier("job-file-gateway-conn-provider")

src/backend/job-file-gateway/service-job-file-gateway/src/main/java/com/tencent/bk/job/file_gateway/dao/filesource/impl/FileWorkerDAOImpl.java

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import lombok.val;
4141
import org.apache.commons.collections4.CollectionUtils;
4242
import org.jooq.Condition;
43+
import org.jooq.Configuration;
4344
import org.jooq.DSLContext;
4445
import org.jooq.Record;
4546
import org.jooq.Result;
@@ -60,6 +61,7 @@
6061
import java.util.List;
6162
import java.util.Objects;
6263
import java.util.Set;
64+
import java.util.concurrent.atomic.AtomicReference;
6365
import java.util.stream.Collectors;
6466

6567
@Repository
@@ -461,52 +463,61 @@ public List<FileWorkerDTO> listFileWorkersByConditions(Collection<Condition> con
461463
if (conditions == null) {
462464
conditions = new ArrayList<>();
463465
}
464-
Result<Record> records = null;
465-
// 保存group_concat_max_len原参数值并设置目标值
466-
defaultContext.execute("SET @t = @@group_concat_max_len");
467-
defaultContext.execute("SET @@group_concat_max_len = 10240");
468-
val query = defaultContext.select(
469-
defaultTable.ID,
470-
defaultTable.APP_ID,
471-
defaultTable.NAME,
472-
defaultTable.DESCRIPTION,
473-
defaultTable.TOKEN,
474-
defaultTable.CLUSTER_NAME,
475-
defaultTable.ACCESS_HOST,
476-
defaultTable.ACCESS_PORT,
477-
defaultTable.CLOUD_AREA_ID,
478-
defaultTable.INNER_IP_PROTOCOL,
479-
defaultTable.INNER_IP,
480-
defaultTable.CPU_OVERLOAD,
481-
defaultTable.MEM_RATE,
482-
defaultTable.MEM_FREE_SPACE,
483-
defaultTable.DISK_RATE,
484-
defaultTable.DISK_FREE_SPACE,
485-
defaultTable.VERSION,
486-
defaultTable.ONLINE_STATUS,
487-
defaultTable.LAST_HEART_BEAT,
488-
defaultTable.CREATOR,
489-
defaultTable.CREATE_TIME,
490-
defaultTable.LAST_MODIFY_USER,
491-
defaultTable.LAST_MODIFY_TIME,
492-
DSL.groupConcat(tFileWorkerAbility.TAG).separator(GROUP_CONCAT_SEPARATOR).as(KEY_FILE_WORKER_ABILITY_TAGS)
493-
)
494-
.from(defaultTable)
495-
.leftJoin(tFileWorkerAbility)
496-
.on(defaultTable.ID.eq(tFileWorkerAbility.WORKER_ID))
497-
.where(conditions)
498-
.groupBy(defaultTable.ID)
499-
.orderBy(defaultTable.LAST_HEART_BEAT.desc());
500-
try {
501-
String sql = query.getSQL(ParamType.INLINED);
502-
log.debug("SQL=" + sql);
503-
records = query.fetch();
504-
} catch (Exception e) {
505-
log.error(String.format("Fail to execute SQL:%s", query.getSQL(ParamType.INLINED)), e);
506-
} finally {
507-
// 恢复group_concat_max_len原参数值
508-
defaultContext.execute("SET @@group_concat_max_len = @t");
509-
}
466+
Collection<Condition> finalConditions = conditions;
467+
AtomicReference<Result<Record>> recordsWrapper = new AtomicReference<>();
468+
defaultContext.transaction((Configuration trx) -> {
469+
DSLContext ctx = trx.dsl();
470+
Result<Record> records;
471+
// 保存group_concat_max_len原参数值并设置目标值
472+
ctx.execute("SET @t = @@group_concat_max_len");
473+
ctx.execute("SET @@group_concat_max_len = 10240");
474+
val query = ctx.select(
475+
defaultTable.ID,
476+
defaultTable.APP_ID,
477+
defaultTable.NAME,
478+
defaultTable.DESCRIPTION,
479+
defaultTable.TOKEN,
480+
defaultTable.CLUSTER_NAME,
481+
defaultTable.ACCESS_HOST,
482+
defaultTable.ACCESS_PORT,
483+
defaultTable.CLOUD_AREA_ID,
484+
defaultTable.INNER_IP_PROTOCOL,
485+
defaultTable.INNER_IP,
486+
defaultTable.CPU_OVERLOAD,
487+
defaultTable.MEM_RATE,
488+
defaultTable.MEM_FREE_SPACE,
489+
defaultTable.DISK_RATE,
490+
defaultTable.DISK_FREE_SPACE,
491+
defaultTable.VERSION,
492+
defaultTable.ONLINE_STATUS,
493+
defaultTable.LAST_HEART_BEAT,
494+
defaultTable.CREATOR,
495+
defaultTable.CREATE_TIME,
496+
defaultTable.LAST_MODIFY_USER,
497+
defaultTable.LAST_MODIFY_TIME,
498+
DSL.groupConcat(tFileWorkerAbility.TAG)
499+
.separator(GROUP_CONCAT_SEPARATOR)
500+
.as(KEY_FILE_WORKER_ABILITY_TAGS)
501+
)
502+
.from(defaultTable)
503+
.leftJoin(tFileWorkerAbility)
504+
.on(defaultTable.ID.eq(tFileWorkerAbility.WORKER_ID))
505+
.where(finalConditions)
506+
.groupBy(defaultTable.ID)
507+
.orderBy(defaultTable.LAST_HEART_BEAT.desc());
508+
try {
509+
String sql = query.getSQL(ParamType.INLINED);
510+
log.debug("SQL=" + sql);
511+
records = query.fetch();
512+
recordsWrapper.set(records);
513+
} catch (Exception e) {
514+
log.error(String.format("Fail to execute SQL:%s", query.getSQL(ParamType.INLINED)), e);
515+
} finally {
516+
// 恢复group_concat_max_len原参数值
517+
ctx.execute("SET @@group_concat_max_len = @t");
518+
}
519+
});
520+
Result<Record> records = recordsWrapper.get();
510521
if (records == null || records.isEmpty()) {
511522
return Collections.emptyList();
512523
} else {

src/backend/job-manage/service-job-manage/src/main/java/com/tencent/bk/job/manage/dao/whiteip/impl/WhiteIPRecordDAOImpl.java

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.apache.commons.collections4.CollectionUtils;
5858
import org.apache.commons.lang3.StringUtils;
5959
import org.jooq.Condition;
60+
import org.jooq.Configuration;
6061
import org.jooq.DSLContext;
6162
import org.jooq.OrderField;
6263
import org.jooq.Record;
@@ -80,6 +81,7 @@
8081
import java.util.HashSet;
8182
import java.util.List;
8283
import java.util.Map;
84+
import java.util.concurrent.atomic.AtomicReference;
8385
import java.util.stream.Collectors;
8486

8587
import static com.tencent.bk.job.manage.api.common.constants.whiteip.Keys.KEY_ACTION_SCOPE_ID_LIST;
@@ -326,40 +328,46 @@ private List<WhiteIPRecordVO> listWhiteIPRecordByConditions(List<Condition> cond
326328
}
327329
int start = baseSearchCondition.getStartOrDefault(0);
328330
int length = baseSearchCondition.getLengthOrDefault(10);
329-
// 保存group_concat_max_len原参数值并设置目标值
330-
dslContext.execute("SET @t = @@group_concat_max_len");
331-
dslContext.execute("SET @@group_concat_max_len = 102400");
332-
val query = dslContext.select(
333-
tWhiteIPRecord.ID.as(KEY_ID),
334-
DSL.max(tApplication.APP_NAME).as(KEY_APP_NAME),
335-
DSL.max(tApplication.APP_TYPE).as(KEY_APP_TYPE),
336-
DSL.max(tWhiteIPRecord.REMARK).as(KEY_REMARK),
337-
DSL.max(tWhiteIPRecord.CREATOR).as(KEY_CREATOR),
338-
DSL.max(tWhiteIPRecord.CREATE_TIME).as(KEY_CREATE_TIME),
339-
DSL.max(tWhiteIPRecord.LAST_MODIFY_USER).as(KEY_LAST_MODIFY_USER),
340-
DSL.max(tWhiteIPRecord.LAST_MODIFY_TIME).as(KEY_LAST_MODIFY_TIME),
341-
DSL.max(tWhiteIPIP.CLOUD_AREA_ID).as(KEY_CLOUD_AREA_ID),
342-
DSL.groupConcat(tWhiteIPAppRel.APP_ID).as(KEY_APP_ID_LIST),
343-
DSL.groupConcat(tWhiteIPIP.IP).as(KEY_IP_LIST),
344-
DSL.groupConcat(tActionScope.ID).as(KEY_ACTION_SCOPE_ID_LIST)
345-
).from(tWhiteIPRecord)
346-
.join(tWhiteIPIP).on(tWhiteIPRecord.ID.eq(tWhiteIPIP.RECORD_ID))
347-
.leftJoin(tWhiteIPActionScope).on(tWhiteIPRecord.ID.eq(tWhiteIPActionScope.RECORD_ID))
348-
.leftJoin(tActionScope).on(tWhiteIPActionScope.ACTION_SCOPE_ID.eq(tActionScope.ID))
349-
.join(tWhiteIPAppRel).on(tWhiteIPRecord.ID.eq(tWhiteIPAppRel.RECORD_ID))
350-
.leftJoin(tApplication).on(tWhiteIPAppRel.APP_ID.eq(tApplication.APP_ID.cast(Long.class)))
351-
.where(conditions)
352-
.groupBy(tWhiteIPRecord.ID)
353-
.orderBy(orderFields)
354-
.limit(start, length);
355-
LOG.info(query.getSQL(ParamType.INLINED));
356-
try {
357-
val records = query.fetch();
358-
return convertRecords(records);
359-
} finally {
360-
// 恢复group_concat_max_len原参数值
361-
dslContext.execute("SET @@group_concat_max_len = @t");
362-
}
331+
AtomicReference<List<WhiteIPRecordVO>> resultListWrapper = new AtomicReference<>();
332+
// 在同一事务中执行多个SQL语句,确保使用同一连接避免暂存变量无效
333+
dslContext.transaction((Configuration trx) -> {
334+
DSLContext ctx = trx.dsl();
335+
// 保存group_concat_max_len原参数值并设置目标值
336+
ctx.execute("SET @t = @@group_concat_max_len");
337+
ctx.execute("SET @@group_concat_max_len = 102400");
338+
val query = ctx.select(
339+
tWhiteIPRecord.ID.as(KEY_ID),
340+
DSL.max(tApplication.APP_NAME).as(KEY_APP_NAME),
341+
DSL.max(tApplication.APP_TYPE).as(KEY_APP_TYPE),
342+
DSL.max(tWhiteIPRecord.REMARK).as(KEY_REMARK),
343+
DSL.max(tWhiteIPRecord.CREATOR).as(KEY_CREATOR),
344+
DSL.max(tWhiteIPRecord.CREATE_TIME).as(KEY_CREATE_TIME),
345+
DSL.max(tWhiteIPRecord.LAST_MODIFY_USER).as(KEY_LAST_MODIFY_USER),
346+
DSL.max(tWhiteIPRecord.LAST_MODIFY_TIME).as(KEY_LAST_MODIFY_TIME),
347+
DSL.max(tWhiteIPIP.CLOUD_AREA_ID).as(KEY_CLOUD_AREA_ID),
348+
DSL.groupConcat(tWhiteIPAppRel.APP_ID).as(KEY_APP_ID_LIST),
349+
DSL.groupConcat(tWhiteIPIP.IP).as(KEY_IP_LIST),
350+
DSL.groupConcat(tActionScope.ID).as(KEY_ACTION_SCOPE_ID_LIST)
351+
).from(tWhiteIPRecord)
352+
.join(tWhiteIPIP).on(tWhiteIPRecord.ID.eq(tWhiteIPIP.RECORD_ID))
353+
.leftJoin(tWhiteIPActionScope).on(tWhiteIPRecord.ID.eq(tWhiteIPActionScope.RECORD_ID))
354+
.leftJoin(tActionScope).on(tWhiteIPActionScope.ACTION_SCOPE_ID.eq(tActionScope.ID))
355+
.join(tWhiteIPAppRel).on(tWhiteIPRecord.ID.eq(tWhiteIPAppRel.RECORD_ID))
356+
.leftJoin(tApplication).on(tWhiteIPAppRel.APP_ID.eq(tApplication.APP_ID.cast(Long.class)))
357+
.where(conditions)
358+
.groupBy(tWhiteIPRecord.ID)
359+
.orderBy(orderFields)
360+
.limit(start, length);
361+
LOG.info(query.getSQL(ParamType.INLINED));
362+
try {
363+
val records = query.fetch();
364+
resultListWrapper.set(convertRecords(records));
365+
} finally {
366+
// 恢复group_concat_max_len原参数值
367+
ctx.execute("SET @@group_concat_max_len = @t");
368+
}
369+
});
370+
return resultListWrapper.get();
363371
}
364372

365373
private List<WhiteIPRecordVO> convertRecords(

0 commit comments

Comments
 (0)