diff --git a/fe/be-java-extensions/trino-connector-scanner/pom.xml b/fe/be-java-extensions/trino-connector-scanner/pom.xml index c9c821820a20ce..2c8b91e0a6c65a 100644 --- a/fe/be-java-extensions/trino-connector-scanner/pom.xml +++ b/fe/be-java-extensions/trino-connector-scanner/pom.xml @@ -33,11 +33,6 @@ under the License. - - org.apache.doris - hudi-scanner - ${project.version} - org.apache.doris java-common @@ -47,6 +42,11 @@ under the License. io.trino trino-main + + commons-io + commons-io + ${commons-io.version} + diff --git a/fe/be-java-extensions/trino-connector-scanner/src/main/java/org/apache/doris/trinoconnector/ProcessUtils.java b/fe/be-java-extensions/trino-connector-scanner/src/main/java/org/apache/doris/trinoconnector/ProcessUtils.java new file mode 100644 index 00000000000000..429b268e01ba1a --- /dev/null +++ b/fe/be-java-extensions/trino-connector-scanner/src/main/java/org/apache/doris/trinoconnector/ProcessUtils.java @@ -0,0 +1,74 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you 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 org.apache.doris.trinoconnector; + +import org.apache.commons.io.FileUtils; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.management.ManagementFactory; +import java.util.LinkedList; +import java.util.List; + +/** + * Utils for handling processes + */ +public class ProcessUtils { + public static long getCurrentProcId() { + try { + return ManagementFactory.getRuntimeMXBean().getPid(); + } catch (Exception e) { + throw new RuntimeException("Couldn't find PID of current JVM process.", e); + } + } + + public static List getChildProcessIds(long pid) { + try { + Process pgrep = (new ProcessBuilder("pgrep", "-P", String.valueOf(pid))).start(); + BufferedReader reader = new BufferedReader(new InputStreamReader(pgrep.getInputStream())); + List result = new LinkedList<>(); + String line; + while ((line = reader.readLine()) != null) { + result.add(Long.valueOf(line.trim())); + } + pgrep.waitFor(); + return result; + } catch (Exception e) { + throw new RuntimeException("Couldn't get child processes of PID " + pid, e); + } + } + + public static String getCommandLine(long pid) { + try { + return FileUtils.readFileToString(new File(String.format("/proc/%d/cmdline", pid))).trim(); + } catch (IOException e) { + return null; + } + } + + public static void killProcess(long pid) { + try { + Process kill = (new ProcessBuilder("kill", "-9", String.valueOf(pid))).start(); + kill.waitFor(); + } catch (Exception e) { + throw new RuntimeException("Couldn't kill process PID " + pid, e); + } + } +} diff --git a/fe/be-java-extensions/trino-connector-scanner/src/main/java/org/apache/doris/trinoconnector/TrinoConnectorCache.java b/fe/be-java-extensions/trino-connector-scanner/src/main/java/org/apache/doris/trinoconnector/TrinoConnectorCache.java index 0a076716b2fe77..e9d92a98f788ce 100644 --- a/fe/be-java-extensions/trino-connector-scanner/src/main/java/org/apache/doris/trinoconnector/TrinoConnectorCache.java +++ b/fe/be-java-extensions/trino-connector-scanner/src/main/java/org/apache/doris/trinoconnector/TrinoConnectorCache.java @@ -17,8 +17,6 @@ package org.apache.doris.trinoconnector; -import org.apache.doris.hudi.Utils; - import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -115,12 +113,12 @@ private static TrinoConnectorCacheValue loadCache(TrinoConnectorCacheKey key) { ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); executorService.scheduleAtFixedRate(() -> { if (!isKilled.get()) { - List pids = Utils.getChildProcessIds( - Utils.getCurrentProcId()); + List pids = ProcessUtils.getChildProcessIds( + ProcessUtils.getCurrentProcId()); for (long pid : pids) { - String cmd = Utils.getCommandLine(pid); + String cmd = ProcessUtils.getCommandLine(pid); if (cmd != null && cmd.contains("org.openjdk.jol.vm.sa.AttachMain")) { - Utils.killProcess(pid); + ProcessUtils.killProcess(pid); isKilled.set(true); } } diff --git a/regression-test/pipeline/external/conf/regression-conf.groovy b/regression-test/pipeline/external/conf/regression-conf.groovy index 3638891d75b61a..43994cccd8eb91 100644 --- a/regression-test/pipeline/external/conf/regression-conf.groovy +++ b/regression-test/pipeline/external/conf/regression-conf.groovy @@ -63,16 +63,11 @@ excludeSuites = "000_the_start_sentinel_do_not_touch," + // keep this line as th "test_cast_string_to_array," + "test_refresh_mtmv," + "test_spark_load," + - "test_trino_hive_orc," + - "test_trino_hive_other," + "test_hive_write_insert," + "test_broker_load_func," + "test_hive_write_partitions," + "zzz_the_end_sentinel_do_not_touch" // keep this line as the last line -// this directories will not be executed -excludeDirectories = "external_table_p0/trino_connector" // unstable - customConf1 = "test_custom_conf_value" // for test csv with header diff --git a/regression-test/pipeline/p0/conf/regression-conf.groovy b/regression-test/pipeline/p0/conf/regression-conf.groovy index c29b5f6bcf18ca..20238b26312afc 100644 --- a/regression-test/pipeline/p0/conf/regression-conf.groovy +++ b/regression-test/pipeline/p0/conf/regression-conf.groovy @@ -70,8 +70,6 @@ excludeSuites = "000_the_start_sentinel_do_not_touch," + // keep this line as th "test_profile," + "test_refresh_mtmv," + "test_spark_load," + - "test_trino_hive_orc," + - "test_trino_hive_other," + "test_hive_write_insert," + "test_hive_write_partitions," + "test_broker_load_func," + @@ -83,7 +81,6 @@ excludeDirectories = "000_the_start_sentinel_do_not_touch," + // keep this line "cloud," + "nereids_rules_p0/subquery," + "workload_manager_p1," + - "external_table_p0/trino_connector," + // unstable "zzz_the_end_sentinel_do_not_touch" // keep this line as the last line customConf1 = "test_custom_conf_value"