This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new a2bb08cce1d [improvement](processlist) Add more information for show 
processlist #24000 (#25123)
a2bb08cce1d is described below

commit a2bb08cce1d37e1f47d16cf57f898244393e6578
Author: yagagagaga <zhangminkefromflyd...@gmail.com>
AuthorDate: Sun Oct 8 22:53:21 2023 +0800

    [improvement](processlist) Add more information for show processlist #24000 
(#25123)
---
 .../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 50ffe740bdf..cde7757d860 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 edeee196e70..002da45ee54 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 6e3aa5150ae..3b6c67b1bba 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 35a93a4178f..4f20fc8c9ef 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
@@ -40,14 +40,17 @@ public class SessionController extends BaseController {
     private static final List<String> SESSION_TABLE_HEADER = 
Lists.newArrayList();
 
     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");
     }
 
@@ -71,7 +74,7 @@ public class SessionController extends BaseController {
 
         long nowMs = System.currentTimeMillis();
         for (ConnectContext.ThreadInfo info : threadInfos) {
-            rows.add(info.toRow(nowMs));
+            rows.add(info.toRow(-1, nowMs));
         }
 
         for (List<String> row : rows) {
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 89f1a9e74e5..62734093277 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;
@@ -79,6 +80,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
@@ -461,6 +464,10 @@ public class ConnectContext {
         this.connectionId = connectionId;
     }
 
+    public void resetLoginTime() {
+        this.loginTime = System.currentTimeMillis();
+    }
+
     public MysqlChannel getMysqlChannel() {
         return mysqlChannel;
     }
@@ -727,18 +734,27 @@ public class ConnectContext {
     public class ThreadInfo {
         public boolean isFull;
 
-        public List<String> toRow(long nowMs) {
+        public List<String> toRow(int connId, long nowMs) {
             List<String> row = Lists.newArrayList();
+            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 8ce1615bb29..acc9ffa0c84 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
@@ -85,6 +85,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 0ebcb1c7dcf..06e8f4d3929 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
@@ -455,7 +455,7 @@ public class ShowExecutor {
                 .listConnection(ctx.getQualifiedUser(), showStmt.isFull());
         long nowMs = System.currentTimeMillis();
         for (ConnectContext.ThreadInfo info : threadInfos) {
-            rowSet.add(info.toRow(nowMs));
+            rowSet.add(info.toRow(ctx.getConnectionId(), nowMs));
         }
 
         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 e08b782106d..a98d47806e4 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
@@ -2588,6 +2588,13 @@ public class StmtExecutor {
     public void setProxyResultSet(ShowResultSet proxyResultSet) {
         this.proxyResultSet = proxyResultSet;
     }
+
+    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 3b9bb05fcbc..85b60f53e3a 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);
-        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);
+        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

Reply via email to