From f6faf272b06cb34f6d51c7a3f5a2cd09d3656fcd Mon Sep 17 00:00:00 2001 From: Ang <43255684+ungreat@users.noreply.github.com> Date: Thu, 25 Jan 2024 15:15:40 +0800 Subject: [PATCH] fix(flow): revert #1380 and #1402 from dev/4.2.x (#1454) * Revert "fix(flow): reduce the result set size of the flow Instance query by parent instance id (#1402)" This reverts commit 349f780542f43983ac1d9a327d5acc4e4b9a5af8. * Revert "fix(flow):improve list API rt (#1383)" This reverts commit db06895a * revert --- .../service/flow/FlowInstanceServiceTest.java | 13 --------- .../V_4_2_4_5__add_flow_instance_index.sql | 28 ------------------- .../metadb/flow/FlowInstanceRepository.java | 15 ++-------- .../factory/FlowResponseMapperFactory.java | 10 +------ 4 files changed, 3 insertions(+), 63 deletions(-) delete mode 100644 server/odc-migrate/src/main/resources/migrate/common/V_4_2_4_5__add_flow_instance_index.sql diff --git a/server/integration-test/src/test/java/com/oceanbase/odc/service/flow/FlowInstanceServiceTest.java b/server/integration-test/src/test/java/com/oceanbase/odc/service/flow/FlowInstanceServiceTest.java index 6902616f34..21f80252f9 100644 --- a/server/integration-test/src/test/java/com/oceanbase/odc/service/flow/FlowInstanceServiceTest.java +++ b/server/integration-test/src/test/java/com/oceanbase/odc/service/flow/FlowInstanceServiceTest.java @@ -62,7 +62,6 @@ import com.oceanbase.odc.core.shared.exception.OverLimitException; import com.oceanbase.odc.metadb.flow.FlowInstanceEntity; import com.oceanbase.odc.metadb.flow.FlowInstanceRepository; -import com.oceanbase.odc.metadb.flow.FlowInstanceRepository.ParentInstanceIdCount; import com.oceanbase.odc.metadb.flow.GateWayInstanceRepository; import com.oceanbase.odc.metadb.flow.NodeInstanceEntityRepository; import com.oceanbase.odc.metadb.flow.SequenceInstanceRepository; @@ -449,14 +448,6 @@ public void listStatus() { Assert.assertEquals(0, status.size()); } - @Test - public void testFindByParentInstanceIdIn() { - createChildFlowInstance("test", 1L); - List byParentInstanceIdIn = flowInstanceRepository.findByParentInstanceIdIn( - Arrays.asList(1L, 2L)); - Assert.assertEquals(byParentInstanceIdIn.size(), 1); - } - private void buildFlowInstance(FlowInstance flowInstance) { buildFlowInstanceWithTaskType(flowInstance, TaskType.ASYNC); } @@ -500,10 +491,6 @@ private FlowInstance createFlowInstance(String name) { return flowFactory.generateFlowInstance(name, null, 1L, null); } - private FlowInstance createChildFlowInstance(String name, Long parentFloweInstanceId) { - return flowFactory.generateFlowInstance(name, parentFloweInstanceId, 1L, null); - } - private FlowTaskInstance createTaskInstance(Long flowInstanceId, TaskEntity taskEntity, ExecutionStrategyConfig config) { FlowTaskInstance taskInstance = new FlowTaskInstance(taskEntity.getTaskType(), diff --git a/server/odc-migrate/src/main/resources/migrate/common/V_4_2_4_5__add_flow_instance_index.sql b/server/odc-migrate/src/main/resources/migrate/common/V_4_2_4_5__add_flow_instance_index.sql deleted file mode 100644 index dcf11634e8..0000000000 --- a/server/odc-migrate/src/main/resources/migrate/common/V_4_2_4_5__add_flow_instance_index.sql +++ /dev/null @@ -1,28 +0,0 @@ -alter table `flow_instance` add index `flow_instance_parent_ins_id`(`parent_instance_id`); - -alter table `flow_instance_node_task` add index `flow_instance_node_task_flow_instance_id`(`flow_instance_id`); - -alter table `flow_instance` add index `flow_instance_parent_oid_ct_id`(`organization_id`,`create_time`,`id`); - -CREATE or replace VIEW `list_flow_instance_view` AS -select - `flow_instance`.`id` AS `id`, - `flow_instance`.`create_time` AS `create_time`, - `flow_instance`.`update_time` AS `update_time`, - `flow_instance`.`name` AS `name`, - `flow_instance`.`flow_config_id` AS `flow_config_id`, - `flow_instance`.`creator_id` AS `creator_id`, - `flow_instance`.`organization_id` AS `organization_id`, - `flow_instance`.`process_definition_id` AS `process_definition_id`, - `flow_instance`.`process_instance_id` AS `process_instance_id`, - `flow_instance`.`status` AS `status`, - `flow_instance`.`flow_config_snapshot_xml` AS `flow_config_snapshot_xml`, - `flow_instance`.`description` AS `description`, - `flow_instance`.`parent_instance_id` AS `parent_instance_id`, - `flow_instance`.`project_id` AS `project_id`, - `flow_instance_node_task`.`task_type` AS `task_type` -from - ( - `flow_instance` join `flow_instance_node_task` on ( `flow_instance`.`id` = `flow_instance_node_task`.`flow_instance_id`) - ) -group by `flow_instance`.`id`,`flow_instance_node_task`.`task_type` \ No newline at end of file diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/metadb/flow/FlowInstanceRepository.java b/server/odc-service/src/main/java/com/oceanbase/odc/metadb/flow/FlowInstanceRepository.java index deb1e18a93..5bf5f6a3df 100644 --- a/server/odc-service/src/main/java/com/oceanbase/odc/metadb/flow/FlowInstanceRepository.java +++ b/server/odc-service/src/main/java/com/oceanbase/odc/metadb/flow/FlowInstanceRepository.java @@ -21,12 +21,12 @@ import javax.transaction.Transactional; +import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import com.oceanbase.odc.config.jpa.OdcJpaRepository; import com.oceanbase.odc.core.shared.constant.FlowStatus; import com.oceanbase.odc.core.shared.constant.TaskType; @@ -39,7 +39,7 @@ * @see org.springframework.data.jpa.repository.JpaRepository */ public interface FlowInstanceRepository - extends OdcJpaRepository, JpaSpecificationExecutor { + extends JpaRepository, JpaSpecificationExecutor { List findByIdIn(Collection ids); @@ -82,7 +82,6 @@ int updateProcessDefinitionIdById(@Param("flowInstanceId") Long flowInstanceId, List findByParentInstanceId(Long parentInstanceId); - @Query(value = "select a.parent_instance_id from flow_instance a left join flow_instance_node_task b on a.id = b.flow_instance_id" + " where a.id=:id and task_task_id is not null and b.task_type='ALTER_SCHEDULE' LIMIT 1", nativeQuery = true) @@ -100,14 +99,4 @@ List findByFlowInstanceIdsAndTaskType(@Param("ids") Collecti nativeQuery = true) Set findByScheduleIdAndStatus(@Param("scheduleIds") Set scheduleIds, @Param("status") FlowStatus status); - - @Query("select e.parentInstanceId as parentInstanceId, count(1) as count from FlowInstanceEntity e where e.parentInstanceId in (?1) group by parentInstanceId") - List findByParentInstanceIdIn(Collection parentInstanceId); - - interface ParentInstanceIdCount { - - Long getParentInstanceId(); - - Integer getCount(); - } } diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/flow/factory/FlowResponseMapperFactory.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/flow/factory/FlowResponseMapperFactory.java index b606c52ab0..e3d52f8bce 100644 --- a/server/odc-service/src/main/java/com/oceanbase/odc/service/flow/factory/FlowResponseMapperFactory.java +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/flow/factory/FlowResponseMapperFactory.java @@ -36,7 +36,6 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Component; -import com.google.common.base.MoreObjects; import com.oceanbase.odc.common.json.JsonUtils; import com.oceanbase.odc.common.util.StringUtils; import com.oceanbase.odc.core.shared.constant.TaskType; @@ -45,7 +44,6 @@ import com.oceanbase.odc.metadb.connection.ConnectionSpecs; import com.oceanbase.odc.metadb.flow.FlowInstanceEntity; import com.oceanbase.odc.metadb.flow.FlowInstanceRepository; -import com.oceanbase.odc.metadb.flow.FlowInstanceRepository.ParentInstanceIdCount; import com.oceanbase.odc.metadb.flow.ServiceTaskInstanceEntity; import com.oceanbase.odc.metadb.flow.ServiceTaskInstanceRepository; import com.oceanbase.odc.metadb.flow.ServiceTaskInstanceSpecs; @@ -284,14 +282,8 @@ private FlowInstanceMapper generateMapper(@NonNull Collection flowInstance .collect(Collectors.groupingBy(ServiceTaskInstanceEntity::getFlowInstanceId, Collectors.mapping(ServiceTaskInstanceEntity::getStrategy, Collectors.toList()))); - Map parentInstanceIdMap = flowInstanceRepository - .findByParentInstanceIdIn(flowInstanceIds) - .stream().collect( - Collectors.toMap(ParentInstanceIdCount::getParentInstanceId, ParentInstanceIdCount::getCount)); - Map flowInstanceId2Rollbackable = flowInstanceIds.stream().collect(Collectors - .toMap(Function.identity(), - id -> MoreObjects.firstNonNull(parentInstanceIdMap.get(id), 0) == 0)); + .toMap(Function.identity(), id -> flowInstanceRepository.findByParentInstanceId(id).size() == 0)); /** * In order to improve the interface efficiency, it is necessary to find out the task entity