From 39207ded23212d33ecc53c05a1b7cc5fc14712c3 Mon Sep 17 00:00:00 2001 From: BiteTheDDDDt Date: Wed, 14 May 2025 19:28:04 +0800 Subject: [PATCH 1/8] fix ctrl+c can not cancel query --- .../runtime/runtime_query_statistics_mgr.cpp | 2 +- .../plans/commands/KillQueryCommand.java | 23 +++++++++++++------ .../plans/commands/KillQueryCommandTest.java | 11 +++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/be/src/runtime/runtime_query_statistics_mgr.cpp b/be/src/runtime/runtime_query_statistics_mgr.cpp index 9495dd8054a746..abb76247cb0f45 100644 --- a/be/src/runtime/runtime_query_statistics_mgr.cpp +++ b/be/src/runtime/runtime_query_statistics_mgr.cpp @@ -275,7 +275,7 @@ void RuntimeQueryStatisticsMgr::register_fragment_profile( _load_channel_profile_map[std::make_pair(query_id, fragment_id)] = load_channel_profile_x; } - LOG_INFO("register x profile done {}, fragment {}, profiles {}", print_id(query_id), + LOG_INFO("register profile done {}, fragment {}, profiles {}", print_id(query_id), fragment_id, p_profiles.size()); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommand.java index f21a865623c532..f775d7796208dd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommand.java @@ -40,31 +40,40 @@ import java.util.Collection; /** * kill query command + * follow https://dev.mysql.com/doc/refman/8.4/en/kill.html */ public class KillQueryCommand extends KillCommand { private static final Logger LOG = LogManager.getLogger(KillQueryCommand.class); - private final String queryId; + private final String processId; - public KillQueryCommand(String queryId) { + public KillQueryCommand(String processId) { super(PlanType.KILL_QUERY_COMMAND); - this.queryId = queryId; + this.processId = processId; } @Override public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { - ConnectContext killCtx = ctx.getConnectScheduler().getContextWithQueryId(queryId); + ConnectContext killCtx = ctx.getConnectScheduler().getContextWithQueryId(processId); + if (killCtx == null) { + try { + Integer connectionId = Integer.valueOf(processId); + killCtx = ctx.getConnectScheduler().getContext(connectionId); + } catch (NumberFormatException e) { + // processId is query id + } + } // when killCtx == null, this means the query not in FE, // then we just send kill signal to BE if (killCtx == null) { TUniqueId tQueryId = null; try { - tQueryId = DebugUtil.parseTUniqueIdFromString(queryId); + tQueryId = DebugUtil.parseTUniqueIdFromString(processId); } catch (NumberFormatException e) { throw new UserException(e.getMessage()); } - LOG.info("kill query {}", queryId); + LOG.info("kill query {}", processId); Collection nodesToPublish = Env.getCurrentSystemInfo() .getAllBackendsByAllCluster().values(); for (Backend be : nodesToPublish) { @@ -75,7 +84,7 @@ public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { .cancelPipelineXPlanFragmentAsync(be.getBrpcAddress(), tQueryId, cancelReason); } catch (Throwable t) { - LOG.info("send kill query {} rpc to be {} failed", queryId, be); + LOG.info("send kill query {} rpc to be {} failed", processId, be); } } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java index c2a95e2ed21ac4..aeee5469f0affa 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java @@ -69,4 +69,15 @@ public void testKillQuery() throws Exception { Assertions.assertDoesNotThrow(() -> command.doRun(connectContext, stmtExecutor)); Assertions.assertEquals(connectContext.getState().getStateType(), QueryState.MysqlStateType.OK); } + + @Test + public void testKillQueryByConnection() throws Exception { + runBefore(); + StmtExecutor stmtExecutor = new StmtExecutor(connectContext, "select 1"); + stmtExecutor.execute(); + String connectionId = DebugUtil.printId(stmtExecutor.getContext().connectionId()); + KillQueryCommand command = new KillQueryCommand(connectionId); + Assertions.assertDoesNotThrow(() -> command.doRun(connectContext, stmtExecutor)); + Assertions.assertEquals(connectContext.getState().getStateType(), QueryState.MysqlStateType.OK); + } } From 055871a51afc641a5e1bca623855471ec7011c92 Mon Sep 17 00:00:00 2001 From: BiteTheDDDDt Date: Wed, 14 May 2025 19:29:28 +0800 Subject: [PATCH 2/8] update --- .../nereids/trees/plans/commands/KillQueryCommandTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java index aeee5469f0affa..c6c1cb5ab10886 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java @@ -75,7 +75,7 @@ public void testKillQueryByConnection() throws Exception { runBefore(); StmtExecutor stmtExecutor = new StmtExecutor(connectContext, "select 1"); stmtExecutor.execute(); - String connectionId = DebugUtil.printId(stmtExecutor.getContext().connectionId()); + String connectionId = DebugUtil.printId(stmtExecutor.getContext().getConnectionId()); KillQueryCommand command = new KillQueryCommand(connectionId); Assertions.assertDoesNotThrow(() -> command.doRun(connectContext, stmtExecutor)); Assertions.assertEquals(connectContext.getState().getStateType(), QueryState.MysqlStateType.OK); From 9e8000f87d41d7ce5e08c460fa0493a1e2fb43a2 Mon Sep 17 00:00:00 2001 From: BiteTheDDDDt Date: Wed, 14 May 2025 19:34:34 +0800 Subject: [PATCH 3/8] format --- be/src/runtime/runtime_query_statistics_mgr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/be/src/runtime/runtime_query_statistics_mgr.cpp b/be/src/runtime/runtime_query_statistics_mgr.cpp index abb76247cb0f45..6333e420162365 100644 --- a/be/src/runtime/runtime_query_statistics_mgr.cpp +++ b/be/src/runtime/runtime_query_statistics_mgr.cpp @@ -275,8 +275,8 @@ void RuntimeQueryStatisticsMgr::register_fragment_profile( _load_channel_profile_map[std::make_pair(query_id, fragment_id)] = load_channel_profile_x; } - LOG_INFO("register profile done {}, fragment {}, profiles {}", print_id(query_id), - fragment_id, p_profiles.size()); + LOG_INFO("register profile done {}, fragment {}, profiles {}", print_id(query_id), fragment_id, + p_profiles.size()); } void RuntimeQueryStatisticsMgr::_report_query_profiles_function() { From 259a5a2cd8eb9702d2eacede73ec4d29feeeb07a Mon Sep 17 00:00:00 2001 From: BiteTheDDDDt Date: Wed, 14 May 2025 19:48:53 +0800 Subject: [PATCH 4/8] fix --- .../nereids/trees/plans/commands/KillQueryCommandTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java index c6c1cb5ab10886..1268333035dec1 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java @@ -75,7 +75,7 @@ public void testKillQueryByConnection() throws Exception { runBefore(); StmtExecutor stmtExecutor = new StmtExecutor(connectContext, "select 1"); stmtExecutor.execute(); - String connectionId = DebugUtil.printId(stmtExecutor.getContext().getConnectionId()); + String connectionId = String.valueOf(stmtExecutor.getContext().getConnectionId()); KillQueryCommand command = new KillQueryCommand(connectionId); Assertions.assertDoesNotThrow(() -> command.doRun(connectContext, stmtExecutor)); Assertions.assertEquals(connectContext.getState().getStateType(), QueryState.MysqlStateType.OK); From 79843c099f41576329b5f79e6ebe1df7cd83376c Mon Sep 17 00:00:00 2001 From: BiteTheDDDDt Date: Thu, 15 May 2025 11:12:56 +0800 Subject: [PATCH 5/8] fix --- .../src/main/java/org/apache/doris/common/util/DebugUtil.java | 4 ++-- .../nereids/trees/plans/commands/KillQueryCommandTest.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/DebugUtil.java b/fe/fe-core/src/main/java/org/apache/doris/common/util/DebugUtil.java index 82252d0f752431..d247f67b4cd316 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/util/DebugUtil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/DebugUtil.java @@ -142,12 +142,12 @@ public static String printId(final TUniqueId id) { // id is a String generated by DebugUtil.printId(TUniqueId) public static TUniqueId parseTUniqueIdFromString(String id) { if (Strings.isNullOrEmpty(id)) { - throw new NumberFormatException("invalid query id"); + throw new NumberFormatException("invalid query id: " + id); } String[] parts = id.split("-"); if (parts.length != 2) { - throw new NumberFormatException("invalid query id"); + throw new NumberFormatException("invalid query id: " + id); } TUniqueId uniqueId = new TUniqueId(); diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java index 1268333035dec1..087f0cfaa47b6e 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillQueryCommandTest.java @@ -45,6 +45,7 @@ private void runBefore() throws IOException { accessControllerManager = env.getAccessManager(); ConnectScheduler scheduler = new ConnectScheduler(10); connectContext.setQualifiedUser("root"); + scheduler.registerConnection(connectContext); new Expectations() { { accessControllerManager.checkGlobalPriv(connectContext, PrivPredicate.ADMIN); From efe74775b4ed35527bb0700ea068d54dd0e8b325 Mon Sep 17 00:00:00 2001 From: BiteTheDDDDt Date: Thu, 15 May 2025 15:40:02 +0800 Subject: [PATCH 6/8] fix --- .../src/main/java/org/apache/doris/common/util/DebugUtil.java | 2 +- .../test/java/org/apache/doris/common/util/DebugUtilTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/DebugUtil.java b/fe/fe-core/src/main/java/org/apache/doris/common/util/DebugUtil.java index d247f67b4cd316..25d8e5cf08497a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/util/DebugUtil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/DebugUtil.java @@ -142,7 +142,7 @@ public static String printId(final TUniqueId id) { // id is a String generated by DebugUtil.printId(TUniqueId) public static TUniqueId parseTUniqueIdFromString(String id) { if (Strings.isNullOrEmpty(id)) { - throw new NumberFormatException("invalid query id: " + id); + throw new NumberFormatException("invalid query id: null"); } String[] parts = id.split("-"); diff --git a/fe/fe-core/src/test/java/org/apache/doris/common/util/DebugUtilTest.java b/fe/fe-core/src/test/java/org/apache/doris/common/util/DebugUtilTest.java index aa599783f182f5..7811801d1b99dc 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/common/util/DebugUtilTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/common/util/DebugUtilTest.java @@ -108,7 +108,7 @@ public void testParseIdFromString() { try { nullTUniqueId = DebugUtil.parseTUniqueIdFromString(null); } catch (NumberFormatException e) { - Assert.assertTrue("invalid query id".equals(e.getMessage())); + Assert.assertTrue("invalid query id: null".equals(e.getMessage())); } Assert.assertTrue(nullTUniqueId == null); From 6fee80fd1ce35c3f337d58bfbe4eca8b6b21e0dd Mon Sep 17 00:00:00 2001 From: BiteTheDDDDt Date: Thu, 15 May 2025 16:40:40 +0800 Subject: [PATCH 7/8] fix --- .../test/java/org/apache/doris/common/util/DebugUtilTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fe/fe-core/src/test/java/org/apache/doris/common/util/DebugUtilTest.java b/fe/fe-core/src/test/java/org/apache/doris/common/util/DebugUtilTest.java index 7811801d1b99dc..7e96cf5516d2ce 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/common/util/DebugUtilTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/common/util/DebugUtilTest.java @@ -116,7 +116,7 @@ public void testParseIdFromString() { try { nullTUniqueId = DebugUtil.parseTUniqueIdFromString(""); } catch (NumberFormatException e) { - Assert.assertTrue("invalid query id".equals(e.getMessage())); + Assert.assertTrue("invalid query id: ".equals(e.getMessage())); } Assert.assertTrue(nullTUniqueId == null); From 9dfb41146636211c4e7b3ca31a12340dafcb9474 Mon Sep 17 00:00:00 2001 From: BiteTheDDDDt Date: Fri, 16 May 2025 11:58:03 +0800 Subject: [PATCH 8/8] fix --- .../src/main/java/org/apache/doris/common/util/DebugUtil.java | 2 +- .../test/java/org/apache/doris/common/util/DebugUtilTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/DebugUtil.java b/fe/fe-core/src/main/java/org/apache/doris/common/util/DebugUtil.java index 25d8e5cf08497a..80db9c9682ee2f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/util/DebugUtil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/DebugUtil.java @@ -142,7 +142,7 @@ public static String printId(final TUniqueId id) { // id is a String generated by DebugUtil.printId(TUniqueId) public static TUniqueId parseTUniqueIdFromString(String id) { if (Strings.isNullOrEmpty(id)) { - throw new NumberFormatException("invalid query id: null"); + throw new NumberFormatException("query id null or empty"); } String[] parts = id.split("-"); diff --git a/fe/fe-core/src/test/java/org/apache/doris/common/util/DebugUtilTest.java b/fe/fe-core/src/test/java/org/apache/doris/common/util/DebugUtilTest.java index 7e96cf5516d2ce..f9221fccb623db 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/common/util/DebugUtilTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/common/util/DebugUtilTest.java @@ -108,7 +108,7 @@ public void testParseIdFromString() { try { nullTUniqueId = DebugUtil.parseTUniqueIdFromString(null); } catch (NumberFormatException e) { - Assert.assertTrue("invalid query id: null".equals(e.getMessage())); + Assert.assertEquals("query id null or empty", e.getMessage()); } Assert.assertTrue(nullTUniqueId == null); @@ -116,7 +116,7 @@ public void testParseIdFromString() { try { nullTUniqueId = DebugUtil.parseTUniqueIdFromString(""); } catch (NumberFormatException e) { - Assert.assertTrue("invalid query id: ".equals(e.getMessage())); + Assert.assertEquals("query id null or empty", e.getMessage()); } Assert.assertTrue(nullTUniqueId == null);