This is an automated email from the ASF dual-hosted git repository. kxiao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 43433c3fab [improvement](processlist) Add more information for `show processlist` (#24000) 43433c3fab is described below commit 43433c3faba63e7db5b7822b1a4e6b41c386def0 Author: yagagagaga <zhangminkefromflyd...@gmail.com> AuthorDate: Tue Sep 26 14:25:42 2023 +0800 [improvement](processlist) Add more information for `show processlist` (#24000) --- .../Show-Statements/SHOW-PROCESSLIST.md | 15 +++++++++++- .../Show-Statements/SHOW-PROCESSLIST.md | 17 +++++++++++-- .../apache/doris/analysis/ShowProcesslistStmt.java | 5 +++- .../doris/httpv2/controller/SessionController.java | 7 ++++-- .../java/org/apache/doris/qe/ConnectContext.java | 26 ++++++++++++++++---- .../java/org/apache/doris/qe/ConnectScheduler.java | 1 + .../java/org/apache/doris/qe/ShowExecutor.java | 2 +- .../java/org/apache/doris/qe/StmtExecutor.java | 7 ++++++ .../org/apache/doris/qe/ConnectContextTest.java | 28 +++++++++++++--------- 9 files changed, 85 insertions(+), 23 deletions(-) diff --git a/docs/en/docs/sql-manual/sql-reference/Show-Statements/SHOW-PROCESSLIST.md b/docs/en/docs/sql-manual/sql-reference/Show-Statements/SHOW-PROCESSLIST.md index 50ffe740bd..cde7757d86 100644 --- a/docs/en/docs/sql-manual/sql-reference/Show-Statements/SHOW-PROCESSLIST.md +++ b/docs/en/docs/sql-manual/sql-reference/Show-Statements/SHOW-PROCESSLIST.md @@ -42,14 +42,17 @@ SHOW [FULL] PROCESSLIST illustrate: +- CurrentConnected: Indicates whether the connection is currently connected - Id: It is the unique identifier of this thread. When we find that there is a problem with this thread, we can use the kill command to add this Id value to kill this thread. Earlier we said that the information displayed by show processlist comes from the information_schema.processlist table, so this Id is the primary key of this table. - User: refers to the user who started this thread. - Host: Records the IP and port number of the client sending the request. Through this information, when troubleshooting the problem, we can locate which client and which process sent the request. -- Cluster: Cluster name +- LoginTime: Timestamp when the connection is make. +- Catalog: Catalog name. - Db: which database the currently executed command is on. If no database is specified, the value is NULL . - Command: refers to the command that the thread is executing at the moment. - Time: Indicates the time the thread is in the current state. - State: The state of the thread, corresponding to Command. +- QueryId: The ID of the current query statement. - Info: Generally recorded is the statement executed by the thread. By default, only the first 100 characters are displayed, that is, the statement you see may be truncated. To see all the information, you need to use show full processlist. Common Command types are as follows: @@ -68,6 +71,16 @@ Other types can refer to [MySQL official website for explanation](https://dev.my ````SQL SHOW PROCESSLIST ```` + return + ``` + MySQL [test]> show full processlist; + +------------------+------+------+-----------------+---------------------+----------+------+---------+------+-------+-----------------------------------+-----------------------+ + | CurrentConnected | Id | User | Host | LoginTime | Catalog | Db | Command | Time | State | QueryId | Info | + +------------------+------+------+-----------------+---------------------+----------+------+---------+------+-------+-----------------------------------+-----------------------+ + | Yes | 0 | root | 127.0.0.1:34650 | 2023-09-06 12:01:02 | internal | test | Query | 0 | OK | c84e397193a54fe7-bbe9bc219318b75e | select 1 | + | | 1 | root | 127.0.0.1:34776 | 2023-09-06 12:01:07 | internal | | Sleep | 29 | EOF | 886ffe2894314f50-8dd73a6ca06699e4 | show full processlist | + +------------------+------+------+-----------------+---------------------+----------+------+---------+------+-------+-----------------------------------+-----------------------+ + ``` ### Keywords diff --git a/docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-PROCESSLIST.md b/docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-PROCESSLIST.md index edeee196e7..002da45ee5 100644 --- a/docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-PROCESSLIST.md +++ b/docs/zh-CN/docs/sql-manual/sql-reference/Show-Statements/SHOW-PROCESSLIST.md @@ -42,14 +42,17 @@ SHOW [FULL] PROCESSLIST 说明: +- CurrentConnected: 是否为当前连接。 - Id: 就是这个线程的唯一标识,当我们发现这个线程有问题的时候,可以通过 kill 命令,加上这个Id值将这个线程杀掉。前面我们说了show processlist 显示的信息时来自information_schema.processlist 表,所以这个Id就是这个表的主键。 - User: 就是指启动这个线程的用户。 - Host: 记录了发送请求的客户端的 IP 和 端口号。通过这些信息在排查问题的时候,我们可以定位到是哪个客户端的哪个进程发送的请求。 -- Cluster:集群名称 +- LoginTime: 建立连接的时间。 +- Catalog: 当前执行的命令是在哪一个数据目录上。 - Db: 当前执行的命令是在哪一个数据库上。如果没有指定数据库,则该值为 NULL 。 - Command: 是指此刻该线程正在执行的命令。 -- Time: 表示该线程处于当前状态的时间。 +- Time: 上一条命令提交到当前状态的时间,单位为秒。 - State: 线程的状态,和 Command 对应。 +- QueryId: 当前查询语句的ID。 - Info: 一般记录的是线程执行的语句。默认只显示前100个字符,也就是你看到的语句可能是截断了的,要看全部信息,需要使用 show full processlist。 常见的 Command 类型如下: @@ -67,6 +70,16 @@ SHOW [FULL] PROCESSLIST ```SQL SHOW PROCESSLIST ``` + 返回结果 + ``` + MySQL [test]> show full processlist; + +------------------+------+------+-----------------+---------------------+----------+------+---------+------+-------+-----------------------------------+-----------------------+ + | CurrentConnected | Id | User | Host | LoginTime | Catalog | Db | Command | Time | State | QueryId | Info | + +------------------+------+------+-----------------+---------------------+----------+------+---------+------+-------+-----------------------------------+-----------------------+ + | Yes | 0 | root | 127.0.0.1:34650 | 2023-09-06 12:01:02 | internal | test | Query | 0 | OK | c84e397193a54fe7-bbe9bc219318b75e | select 1 | + | | 1 | root | 127.0.0.1:34776 | 2023-09-06 12:01:07 | internal | | Sleep | 29 | EOF | 886ffe2894314f50-8dd73a6ca06699e4 | show full processlist | + +------------------+------+------+-----------------+---------------------+----------+------+---------+------+-------+-----------------------------------+-----------------------+ + ``` ### Keywords diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowProcesslistStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowProcesslistStmt.java index 6e3aa5150a..3b6c67b1bb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowProcesslistStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowProcesslistStmt.java @@ -26,14 +26,17 @@ import org.apache.doris.qe.ShowResultSetMetaData; // Used to show connection belong to this user. public class ShowProcesslistStmt extends ShowStmt { private static final ShowResultSetMetaData META_DATA = ShowResultSetMetaData.builder() + .addColumn(new Column("CurrentConnected", ScalarType.createVarchar(16))) .addColumn(new Column("Id", ScalarType.createType(PrimitiveType.BIGINT))) .addColumn(new Column("User", ScalarType.createVarchar(16))) .addColumn(new Column("Host", ScalarType.createVarchar(16))) - .addColumn(new Column("Cluster", ScalarType.createVarchar(16))) + .addColumn(new Column("LoginTime", ScalarType.createVarchar(16))) + .addColumn(new Column("Catalog", ScalarType.createVarchar(16))) .addColumn(new Column("Db", ScalarType.createVarchar(16))) .addColumn(new Column("Command", ScalarType.createVarchar(16))) .addColumn(new Column("Time", ScalarType.createType(PrimitiveType.INT))) .addColumn(new Column("State", ScalarType.createVarchar(64))) + .addColumn(new Column("QueryId", ScalarType.createVarchar(64))) .addColumn(new Column("Info", ScalarType.STRING)).build(); private boolean isFull; diff --git a/fe/fe-core/src/main/java/org/apache/doris/httpv2/controller/SessionController.java b/fe/fe-core/src/main/java/org/apache/doris/httpv2/controller/SessionController.java index 53a32a5796..27a28dbb4f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/httpv2/controller/SessionController.java +++ b/fe/fe-core/src/main/java/org/apache/doris/httpv2/controller/SessionController.java @@ -58,14 +58,17 @@ public class SessionController extends RestBaseController { private static final Logger LOG = LogManager.getLogger(SessionController.class); static { + SESSION_TABLE_HEADER.add("CurrentConnected"); SESSION_TABLE_HEADER.add("Id"); SESSION_TABLE_HEADER.add("User"); SESSION_TABLE_HEADER.add("Host"); - SESSION_TABLE_HEADER.add("Cluster"); + SESSION_TABLE_HEADER.add("LoginTime"); + SESSION_TABLE_HEADER.add("Catalog"); SESSION_TABLE_HEADER.add("Db"); SESSION_TABLE_HEADER.add("Command"); SESSION_TABLE_HEADER.add("Time"); SESSION_TABLE_HEADER.add("State"); + SESSION_TABLE_HEADER.add("QueryId"); SESSION_TABLE_HEADER.add("Info"); ALL_SESSION_TABLE_HEADER.addAll(SESSION_TABLE_HEADER); } @@ -111,7 +114,7 @@ public class SessionController extends RestBaseController { .listConnection("root", false); long nowMs = System.currentTimeMillis(); return threadInfos.stream() - .map(info -> info.toRow(nowMs, showFe)) + .map(info -> info.toRow(-1, nowMs, showFe)) .map(row -> { Map<String, String> record = new HashMap<>(); for (int i = 0; i < row.size(); i++) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java index 5a427a1080..302d3544de 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java @@ -26,6 +26,7 @@ import org.apache.doris.cluster.ClusterNamespace; import org.apache.doris.common.Config; import org.apache.doris.common.telemetry.Telemetry; import org.apache.doris.common.util.DebugUtil; +import org.apache.doris.common.util.TimeUtils; import org.apache.doris.datasource.CatalogIf; import org.apache.doris.datasource.InternalCatalog; import org.apache.doris.datasource.SessionContext; @@ -87,6 +88,8 @@ public class ConnectContext { protected volatile String traceId; // id for this connection protected volatile int connectionId; + // Timestamp when the connection is make + protected volatile long loginTime; // mysql net protected volatile MysqlChannel mysqlChannel; // state @@ -500,6 +503,10 @@ public class ConnectContext { this.connectionId = connectionId; } + public void resetLoginTime() { + this.loginTime = System.currentTimeMillis(); + } + public MysqlChannel getMysqlChannel() { return mysqlChannel; } @@ -772,21 +779,30 @@ public class ConnectContext { public class ThreadInfo { public boolean isFull; - public List<String> toRow(long nowMs, boolean showFe) { + public List<String> toRow(int connId, long nowMs, boolean showFe) { List<String> row = Lists.newArrayList(); if (showFe) { row.add(Env.getCurrentEnv().getSelfNode().getHost()); } + if (connId == connectionId) { + row.add("Yes"); + } else { + row.add(""); + } row.add("" + connectionId); row.add(ClusterNamespace.getNameFromFullName(qualifiedUser)); row.add(getMysqlChannel().getRemoteHostPortString()); - row.add(clusterName); + row.add(TimeUtils.longToTimeString(loginTime)); + row.add(defaultCatalog); row.add(ClusterNamespace.getNameFromFullName(currentDb)); row.add(command.toString()); row.add("" + (nowMs - startTime) / 1000); - row.add(""); - if (queryId != null) { - String sql = QeProcessorImpl.INSTANCE.getCurrentQueryByQueryId(queryId); + row.add(state.toString()); + row.add(DebugUtil.printId(queryId)); + if (state.getStateType() == QueryState.MysqlStateType.ERR) { + row.add(state.getErrorMessage()); + } else if (executor != null) { + String sql = executor.getOriginStmtInString(); if (!isFull) { sql = sql.substring(0, Math.min(sql.length(), 100)); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectScheduler.java b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectScheduler.java index a89324de39..5090e623a9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectScheduler.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectScheduler.java @@ -81,6 +81,7 @@ public class ConnectScheduler { return false; } context.setConnectionId(nextConnectionId.getAndAdd(1)); + context.resetLoginTime(); return true; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java index bb435c443d..47a29ce962 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java @@ -461,7 +461,7 @@ public class ShowExecutor { .listConnection(ctx.getQualifiedUser(), showStmt.isFull()); long nowMs = System.currentTimeMillis(); for (ConnectContext.ThreadInfo info : threadInfos) { - rowSet.add(info.toRow(nowMs, false)); + rowSet.add(info.toRow(ctx.getConnectionId(), nowMs, false)); } resultSet = new ShowResultSet(showStmt.getMetaData(), rowSet); diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java index e0e68180bd..26914ba481 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java @@ -2759,6 +2759,13 @@ public class StmtExecutor { public OriginStatement getOriginStmt() { return originStmt; } + + public String getOriginStmtInString() { + if (originStmt != null && originStmt.originStmt != null) { + return originStmt.originStmt; + } + return ""; + } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java b/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java index ee9f605693..a15bdd8178 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/qe/ConnectContextTest.java @@ -99,19 +99,25 @@ public class ConnectContextTest { ctx.setCommand(MysqlCommand.COM_PING); Assert.assertEquals(MysqlCommand.COM_PING, ctx.getCommand()); + // LoginTime + ctx.loginTime = 1694002396223L; + // Thread info Assert.assertNotNull(ctx.toThreadInfo(false)); - List<String> row = ctx.toThreadInfo(false).toRow(1000, false); - Assert.assertEquals(9, row.size()); - Assert.assertEquals("101", row.get(0)); - Assert.assertEquals("testUser", row.get(1)); - Assert.assertEquals("", row.get(2)); - Assert.assertEquals("testCluster", row.get(3)); - Assert.assertEquals("testDb", row.get(4)); - Assert.assertEquals("Ping", row.get(5)); - Assert.assertEquals("1", row.get(6)); - Assert.assertEquals("", row.get(7)); - Assert.assertEquals("", row.get(8)); + List<String> row = ctx.toThreadInfo(false).toRow(101, 1000, false); + Assert.assertEquals(12, row.size()); + Assert.assertEquals("Yes", row.get(0)); + Assert.assertEquals("101", row.get(1)); + Assert.assertEquals("testUser", row.get(2)); + Assert.assertEquals("", row.get(3)); + Assert.assertEquals("2023-09-06 20:13:16", row.get(4)); + Assert.assertEquals("internal", row.get(5)); + Assert.assertEquals("testDb", row.get(6)); + Assert.assertEquals("Ping", row.get(7)); + Assert.assertEquals("1", row.get(8)); + Assert.assertEquals("OK", row.get(9)); + Assert.assertEquals("", row.get(10)); + Assert.assertEquals("", row.get(11)); // Start time Assert.assertEquals(0, ctx.getStartTime()); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org