-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logicaldatabase): logical database change task implementation (#…
…3324) * execution engine implementation part1 * execution impl part2 * fix * stash * logical database change task framework * stash * implement logical database change tasks * impl * bugfix * refactor * bugfix * pmd * fix api * fix ut cases * delete unused code * remove unnecessary import * rename sql script * optimize concurrency issue * response to comments * response to comments * response to comments * response to comments * create connection session in SqlExecutionHandler * response to comments * response to comments * refacotr * refactor unit tetsts * response to comments * mark map as ConcurrentMap * response to comments * fix logic error * fix status update
- Loading branch information
1 parent
186c259
commit f801c5c
Showing
53 changed files
with
2,466 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...migrate/src/main/resources/migrate/common/V_4_3_2_9__add_logical_database_change_task.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CREATE TABLE IF NOT EXISTS `logicaldatabase_database_change_execution_unit` ( | ||
`id` bigint(20) NOT NULL AUTO_INCREMENT, | ||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||
`execution_id` varchar(64) NOT NULL COMMENT 'execution id of the logical database change task, uuid', | ||
`execution_order` bigint(20) NOT NULL COMMENT 'execution order', | ||
`schedule_task_id` bigint(20) NOT NULL COMMENT 'ID of the related schedule task, refer to schedule_task.id', | ||
`logical_database_id` bigint(20) NOT NULL COMMENT 'logical database id, reference to connect_database.id', | ||
`physical_database_id` bigint(20) NOT NULL COMMENT 'physical database id, reference to connect_database.id', | ||
`sql_content` mediumtext COMMENT 'sql content', | ||
`execution_result_json` mediumtext NOT NULL COMMENT 'execution result json, see SqlExecutionResultWrapper', | ||
`status` varchar(32) NOT NULL COMMENT 'status of the execution, see ExecutionStatus', | ||
CONSTRAINT `pk_logical_db_change_id` PRIMARY KEY (`id`), | ||
CONSTRAINT `uk_logical_db_change_execution_id` UNIQUE KEY (`execution_id`), | ||
CONSTRAINT `uk_logical_db_change_sti_pdi_order` UNIQUE KEY (`schedule_task_id`, `physical_database_id`, `execution_order`) | ||
) COMMENT = 'logical database change task execution units'; | ||
|
||
alter table schedule_schedule modify column connection_id bigint(20) COMMENT 'reference to connect_connection.id'; |
63 changes: 63 additions & 0 deletions
63
...main/java/com/oceanbase/odc/server/web/controller/v2/LogicalDatabaseChangeController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2023 OceanBase. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.oceanbase.odc.server.web.controller.v2; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.oceanbase.odc.service.common.response.Responses; | ||
import com.oceanbase.odc.service.common.response.SuccessResponse; | ||
import com.oceanbase.odc.service.connection.logicaldatabase.LogicalDatabaseChangeService; | ||
import com.oceanbase.odc.service.connection.logicaldatabase.model.SqlExecutionUnitResp; | ||
import com.oceanbase.odc.service.task.exception.JobException; | ||
|
||
/** | ||
* @Author: Lebie | ||
* @Date: 2024/9/4 12:20 | ||
* @Description: [] | ||
*/ | ||
@RestController | ||
@RequestMapping("/api/v2/logicaldatabase") | ||
public class LogicalDatabaseChangeController { | ||
@Autowired | ||
private LogicalDatabaseChangeService logicalDatabaseChangeService; | ||
|
||
@RequestMapping(value = "/scheduleTasks/{scheduleTaskId:[\\d]+}/physicalDatabases/{physicalDatabaseId:[\\d]+}", | ||
method = RequestMethod.GET) | ||
public SuccessResponse<SqlExecutionUnitResp> detailPhysicalDatabaseChangeTask(@PathVariable Long scheduleTaskId, | ||
@PathVariable Long physicalDatabaseId) { | ||
return Responses.success(logicalDatabaseChangeService.detail(scheduleTaskId, physicalDatabaseId)); | ||
} | ||
|
||
@RequestMapping( | ||
value = "/scheduleTasks/{scheduleTaskId:[\\d]+}/physicalDatabases/{physicalDatabaseId:[\\d]+}/skipCurrentStatement", | ||
method = RequestMethod.POST) | ||
public SuccessResponse<Boolean> skipCurrentStatement(@PathVariable Long scheduleTaskId, | ||
@PathVariable Long physicalDatabaseId) throws InterruptedException, JobException { | ||
return Responses.success(logicalDatabaseChangeService.skipCurrent(scheduleTaskId, physicalDatabaseId)); | ||
} | ||
|
||
@RequestMapping( | ||
value = "/scheduleTasks/{scheduleTaskId:[\\d]+}/physicalDatabases/{physicalDatabaseId:[\\d]+}/terminateCurrentStatement", | ||
method = RequestMethod.POST) | ||
public SuccessResponse<Boolean> terminateCurrentStatement(@PathVariable Long scheduleTaskId, | ||
@PathVariable Long physicalDatabaseId) throws InterruptedException, JobException { | ||
return Responses.success(logicalDatabaseChangeService.terminateCurrent(scheduleTaskId, physicalDatabaseId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...m/oceanbase/odc/metadb/connection/logicaldatabase/LogicalDBChangeExecutionUnitEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2023 OceanBase. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.oceanbase.odc.metadb.connection.logicaldatabase; | ||
|
||
import java.util.Date; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.EnumType; | ||
import javax.persistence.Enumerated; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
import org.hibernate.annotations.Generated; | ||
import org.hibernate.annotations.GenerationTime; | ||
|
||
import com.oceanbase.odc.service.connection.logicaldatabase.core.executor.execution.ExecutionStatus; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* @Author: Lebie | ||
* @Date: 2024/9/3 19:56 | ||
* @Description: [] | ||
*/ | ||
@Data | ||
@Entity | ||
@Table(name = "logicaldatabase_database_change_execution_unit") | ||
public class LogicalDBChangeExecutionUnitEntity { | ||
@Id | ||
@Column(name = "id", nullable = false) | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "execution_id", nullable = false, updatable = false) | ||
private String executionId; | ||
|
||
@Column(name = "execution_order", nullable = false, updatable = false) | ||
private Long executionOrder; | ||
|
||
@Column(name = "schedule_task_id", nullable = false) | ||
private Long scheduleTaskId; | ||
|
||
@Column(name = "logical_database_id", nullable = false, updatable = false) | ||
private Long logicalDatabaseId; | ||
|
||
@Column(name = "physical_database_id", nullable = false, updatable = false) | ||
private Long physicalDatabaseId; | ||
|
||
@Column(name = "sql_content", nullable = false, updatable = false) | ||
private String sql; | ||
|
||
@Column(name = "execution_result_json", nullable = false) | ||
private String executionResultJson; | ||
|
||
@Column(name = "status", nullable = false) | ||
@Enumerated(EnumType.STRING) | ||
private ExecutionStatus status; | ||
|
||
@Generated(GenerationTime.ALWAYS) | ||
@Column(name = "create_time", insertable = false, updatable = false) | ||
private Date createTime; | ||
|
||
@Generated(GenerationTime.ALWAYS) | ||
@Column(name = "update_time", insertable = false, updatable = false) | ||
private Date updateTime; | ||
} |
30 changes: 30 additions & 0 deletions
30
...ava/com/oceanbase/odc/metadb/connection/logicaldatabase/LogicalDBExecutionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2023 OceanBase. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.oceanbase.odc.metadb.connection.logicaldatabase; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import com.oceanbase.odc.config.jpa.OdcJpaRepository; | ||
|
||
public interface LogicalDBExecutionRepository extends OdcJpaRepository<LogicalDBChangeExecutionUnitEntity, Long> { | ||
Optional<LogicalDBChangeExecutionUnitEntity> findByExecutionId(String executionId); | ||
|
||
List<LogicalDBChangeExecutionUnitEntity> findByScheduleTaskIdOrderByExecutionOrderAsc(Long scheduleTaskId); | ||
|
||
List<LogicalDBChangeExecutionUnitEntity> findByScheduleTaskIdAndPhysicalDatabaseIdOrderByExecutionOrderAsc( | ||
Long scheduleTaskId, Long physicalDatabaseId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.