From 5f62c74bc2ebbe50838db9a8ebe8a1b0cd6849ca Mon Sep 17 00:00:00 2001 From: yh263208 Date: Thu, 19 Oct 2023 11:12:49 +0800 Subject: [PATCH 1/2] fix(databasechange): fix task costs too much time to start up --- client | 2 +- .../flow/task/DatabaseChangeRuntimeFlowableTask.java | 2 +- .../odc/service/flow/task/DatabaseChangeThread.java | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/client b/client index b942423e45..91dabffcdc 160000 --- a/client +++ b/client @@ -1 +1 @@ -Subproject commit b942423e456065427a0923002afe8de52e153cf9 +Subproject commit 91dabffcdc65bf8a9c9091c411337e61977ce526 diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/flow/task/DatabaseChangeRuntimeFlowableTask.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/flow/task/DatabaseChangeRuntimeFlowableTask.java index 2d184256be..9b530771c7 100644 --- a/server/odc-service/src/main/java/com/oceanbase/odc/service/flow/task/DatabaseChangeRuntimeFlowableTask.java +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/flow/task/DatabaseChangeRuntimeFlowableTask.java @@ -184,7 +184,7 @@ private DatabaseChangeThread generateOdcAsyncTaskThread(Long taskId, DelegateExe ConnectionSessionUtil.setSqlCommentProcessor(connectionSession, processor); ConnectionSessionUtil.setCurrentSchema(connectionSession, FlowTaskUtil.getSchemaName(execution)); ConnectionSessionUtil.setColumnAccessor(connectionSession, new DatasourceColumnAccessor(connectionSession)); - DatabaseChangeThread returnVal = new DatabaseChangeThread(connectionSession, parameters, creatorId, + DatabaseChangeThread returnVal = new DatabaseChangeThread(connectionSession, parameters, cloudObjectStorageService, objectStorageFacade, maskingService); returnVal.setTaskId(taskId); returnVal.setFlowInstanceId(this.getFlowInstanceId()); diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/flow/task/DatabaseChangeThread.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/flow/task/DatabaseChangeThread.java index f3f48d1039..0aedcb1ef1 100644 --- a/server/odc-service/src/main/java/com/oceanbase/odc/service/flow/task/DatabaseChangeThread.java +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/flow/task/DatabaseChangeThread.java @@ -116,7 +116,7 @@ public class DatabaseChangeThread extends Thread { private final ObjectStorageFacade objectStorageFacade; private final DataMaskingService maskingService; - public DatabaseChangeThread(ConnectionSession connectionSession, DatabaseChangeParameters parameters, Long userId, + public DatabaseChangeThread(ConnectionSession connectionSession, DatabaseChangeParameters parameters, CloudObjectStorageService cloudObjectStorageService, ObjectStorageFacade objectStorageFacade, DataMaskingService maskingService) { this.connectionSession = connectionSession; @@ -124,7 +124,6 @@ public DatabaseChangeThread(ConnectionSession connectionSession, DatabaseChangeP this.cloudObjectStorageService = cloudObjectStorageService; this.objectStorageFacade = objectStorageFacade; this.maskingService = maskingService; - init(userId); } private void init(Long userId) { @@ -168,6 +167,9 @@ private String readSqlFiles(Long userId, List objectIds) throws IOExcept public void run() { TaskContextHolder.trace(userId, taskId); log.info("Async task start to run, task id:{}", this.getTaskId()); + log.info("Start read sql content, taskId={}", this.getTaskId()); + init(userId); + log.info("Read sql content successfully, taskId={}, sqlCount={}", this.getTaskId(), this.sqls.size()); startTimestamp = System.currentTimeMillis(); String fileDir = FileManager.generateDir(FileBucket.ASYNC); for (int index = 1; index <= sqls.size(); index++) { From 7050f3b9a64d1a632ba42986add89681c9c67454 Mon Sep 17 00:00:00 2001 From: yh263208 Date: Thu, 19 Oct 2023 11:48:44 +0800 Subject: [PATCH 2/2] refactor: move session init first --- .../odc/service/session/factory/OBConsoleDataSourceFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/session/factory/OBConsoleDataSourceFactory.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/session/factory/OBConsoleDataSourceFactory.java index bab9dfc48a..823b23b07f 100644 --- a/server/odc-service/src/main/java/com/oceanbase/odc/service/session/factory/OBConsoleDataSourceFactory.java +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/session/factory/OBConsoleDataSourceFactory.java @@ -194,11 +194,11 @@ public DataSource getDataSource() { dataSource.setAutoCommit(autoCommit); } if (this.initConnection) { + dataSource.addInitializer(new SessionCreatedInitializer(connectionConfig)); List initializers = connectionExtensionPoint.getConnectionInitializers(); if (!CollectionUtils.isEmpty(initializers)) { initializers.forEach(dataSource::addInitializer); } - dataSource.addInitializer(new SessionCreatedInitializer(connectionConfig)); } return dataSource; }