多次查询oceanbase.V$OB_TRANSACTION_PARTICIPANTS,结果有时为空

【 使用环境 】 测试环境
【 OB or 其他组件 】
【 使用版本 】
Server version: OceanBase_CE 4.1.0.1 (r102000042023061314-43bca414d5065272a730c92a645c3e25768c1d05) (Built Jun 13 2023 14:26:23)

【问题描述】
多次查询oceanbase.V$OB_TRANSACTION_PARTICIPANTS,结果有时为空,不是太理解为什么。
文档: V$OB_TRANSACTION_PARTICIPANTS -OceanBase 数据库 -OceanBase文档中心-分布式数据库使用文档 这里也没有详细解释。

【复现路径】
两个session,连接同一个observer
session1:
obclient -h172.17.140.123 -P2881 -uroot -p’x’ -Ddb1 -A

session2:
obclient -h172.17.140.123 -P2881 -uroot -p’x’ -Ddb1 -A

session1启动一个事务:

begin; select * from sbtest1 where id =1 for update;

session2中多次执行下面的查询,结果有时为空:

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
Empty set (0.006 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
Empty set (0.005 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
Empty set (0.006 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
Empty set (0.006 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
Empty set (0.010 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
Empty set (0.005 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
Empty set (0.005 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
+-----------+----------------+----------+------------+-----------------------+-----------+----------+-------+--------------+----------------------------+----------------------------+--------+--------+------------------+------------------+--------+-------+----------------------------+----------+----------+----------+
| TENANT_ID | SVR_IP         | SVR_PORT | SESSION_ID | SCHEDULER_ADDR        | TX_TYPE   | TX_ID    | LS_ID | PARTICIPANTS | CTX_CREATE_TIME            | TX_EXPIRED_TIME            | STATE  | ACTION | PENDING_LOG_SIZE | FLUSHED_LOG_SIZE | ROLE   | COORD | LAST_REQUEST_TIME          | FORMATID | GLOBALID | BRANCHID |
+-----------+----------------+----------+------------+-----------------------+-----------+----------+-------+--------------+----------------------------+----------------------------+--------+--------+------------------+------------------+--------+-------+----------------------------+----------+----------+----------+
|      1001 | 172.17.140.123 |     2882 |          1 | "172.17.140.123:2882" | UNDECIDED | 17148233 |     1 | NULL         | 2023-08-08 16:40:12.190024 | 2023-08-08 16:40:42.190016 | ACTIVE | START  |               42 |                0 | LEADER |    -1 | 2023-08-08 16:40:12.193214 |       -1 | NULL     | NULL     |
|      1001 | 172.17.140.123 |     2882 |          1 | "172.17.136.59:2882"  | UNDECIDED | 17029200 |     1 | NULL         | 2023-08-08 16:40:12.186823 | 2023-08-08 16:40:42.182269 | ACTIVE | START  |               81 |                0 | LEADER |    -1 | 2023-08-08 16:40:12.188951 |       -1 | NULL     | NULL     |
+-----------+----------------+----------+------------+-----------------------+-----------+----------+-------+--------------+----------------------------+----------------------------+--------+--------+------------------+------------------+--------+-------+----------------------------+----------+----------+----------+
2 rows in set (0.005 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
+-----------+----------------+----------+------------+----------------------+-----------+----------+-------+--------------+----------------------------+----------------------------+--------+--------+------------------+------------------+----------+-------+----------------------------+----------+----------+----------+
| TENANT_ID | SVR_IP         | SVR_PORT | SESSION_ID | SCHEDULER_ADDR       | TX_TYPE   | TX_ID    | LS_ID | PARTICIPANTS | CTX_CREATE_TIME            | TX_EXPIRED_TIME            | STATE  | ACTION | PENDING_LOG_SIZE | FLUSHED_LOG_SIZE | ROLE     | COORD | LAST_REQUEST_TIME          | FORMATID | GLOBALID | BRANCHID |
+-----------+----------------+----------+------------+----------------------+-----------+----------+-------+--------------+----------------------------+----------------------------+--------+--------+------------------+------------------+----------+-------+----------------------------+----------+----------+----------+
|      1001 | 172.17.140.123 |     2882 |          1 | "172.17.136.59:2882" | UNDECIDED | 17029206 |     1 | NULL         | 2023-08-08 16:40:12.864583 | 2023-08-08 16:40:42.861597 | ACTIVE | START  |               81 |                0 | LEADER   |    -1 | 2023-08-08 16:40:12.867252 |       -1 | NULL     | NULL     |
|      1002 | 172.17.140.123 |     2882 | 3221817072 | "172.17.136.59:2882" | UNDECIDED |  9446385 |  1001 | NULL         | 2023-08-08 16:40:12.785422 | 2023-08-08 16:50:12.785422 | ACTIVE | START  |            11524 |            16426 | LEADER   |    -1 | 2023-08-08 16:40:12.863531 |       -1 | NULL     | NULL     |
|      1002 | 172.17.140.123 |     2882 |          0 | "172.17.136.59:2882" | UNDECIDED |  9446385 |  1002 | NULL         | 2023-08-08 16:40:12.860339 | NULL                       | ACTIVE | NULL   |                0 |            16426 | FOLLOWER |    -1 | 2023-08-08 16:40:12.860339 |       -1 | NULL     | NULL     |
|      1002 | 172.17.140.123 |     2882 |          0 | "172.17.136.59:2882" | UNDECIDED |  9446385 |  1003 | NULL         | 2023-08-08 16:40:12.827930 | NULL                       | ACTIVE | NULL   |                0 |            16426 | FOLLOWER |    -1 | 2023-08-08 16:40:12.827930 |       -1 | NULL     | NULL     |
+-----------+----------------+----------+------------+----------------------+-----------+----------+-------+--------------+----------------------------+----------------------------+--------+--------+------------------+------------------+----------+-------+----------------------------+----------+----------+----------+
4 rows in set (0.006 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
Empty set (0.005 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
Empty set (0.006 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
Empty set (0.006 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
Empty set (0.005 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
+-----------+----------------+----------+------------+-----------------------+---------+----------+-------+--------------+----------------------------+----------------------------+--------+--------+------------------+------------------+--------+-------+----------------------------+----------+----------+----------+
| TENANT_ID | SVR_IP         | SVR_PORT | SESSION_ID | SCHEDULER_ADDR        | TX_TYPE | TX_ID    | LS_ID | PARTICIPANTS | CTX_CREATE_TIME            | TX_EXPIRED_TIME            | STATE  | ACTION | PENDING_LOG_SIZE | FLUSHED_LOG_SIZE | ROLE   | COORD | LAST_REQUEST_TIME          | FORMATID | GLOBALID | BRANCHID |
+-----------+----------------+----------+------------+-----------------------+---------+----------+-------+--------------+----------------------------+----------------------------+--------+--------+------------------+------------------+--------+-------+----------------------------+----------+----------+----------+
|      1001 | 172.17.140.123 |     2882 |          1 | "172.17.140.123:2882" | LOCAL   | 17148633 |     1 | [{id:1}]     | 2023-08-08 16:40:30.350641 | 2023-08-08 16:41:00.350628 | ACTIVE | COMMIT |                0 |               74 | LEADER |     1 | 2023-08-08 16:40:30.350641 |       -1 | NULL     | NULL     |
+-----------+----------------+----------+------------+-----------------------+---------+----------+-------+--------------+----------------------------+----------------------------+--------+--------+------------------+------------------+--------+-------+----------------------------+----------+----------+----------+
1 row in set (0.006 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
+-----------+----------------+----------+------------+-----------------------+---------+----------+-------+--------------+----------------------------+----------------------------+--------+--------+------------------+------------------+--------+-------+----------------------------+----------+----------+----------+
| TENANT_ID | SVR_IP         | SVR_PORT | SESSION_ID | SCHEDULER_ADDR        | TX_TYPE | TX_ID    | LS_ID | PARTICIPANTS | CTX_CREATE_TIME            | TX_EXPIRED_TIME            | STATE  | ACTION | PENDING_LOG_SIZE | FLUSHED_LOG_SIZE | ROLE   | COORD | LAST_REQUEST_TIME          | FORMATID | GLOBALID | BRANCHID |
+-----------+----------------+----------+------------+-----------------------+---------+----------+-------+--------------+----------------------------+----------------------------+--------+--------+------------------+------------------+--------+-------+----------------------------+----------+----------+----------+
|      1001 | 172.17.140.123 |     2882 |          1 | "172.17.140.123:2882" | LOCAL   | 17148689 |     1 | [{id:1}]     | 2023-08-08 16:40:32.773210 | 2023-08-08 16:41:02.773201 | ACTIVE | COMMIT |                0 |               74 | LEADER |     1 | 2023-08-08 16:40:32.773210 |       -1 | NULL     | NULL     |
|      1001 | 172.17.140.123 |     2882 | 3221669691 | "172.17.x.1:2882" | LOCAL   | 17148690 |     1 | [{id:1}]     | 2023-08-08 16:40:32.890280 | 2023-08-08 16:41:02.890268 | ACTIVE | COMMIT |                0 |               73 | LEADER |     1 | 2023-08-08 16:40:32.891351 |       -1 | NULL     | NULL     |
+-----------+----------------+----------+------------+-----------------------+---------+----------+-------+--------------+----------------------------+----------------------------+--------+--------+------------------+------------------+--------+-------+----------------------------+----------+----------+----------+
2 rows in set (0.008 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
Empty set (0.005 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
Empty set (0.005 sec)

[root@wldb1] [db1]>SELECT * FROM oceanbase.V$OB_TRANSACTION_PARTICIPANTS;
Empty set (0.013 sec)```

视图V$OB_TRANSACTION_PARTICIPANTS主要用于查询事务参与者上下文,只读语句不产生事务参与者上下文,可以换成更新语句进行尝试。
由于系统中内部逻辑会产生事务,因此查询该视图偶尔可以获取到内容。

session1中换成下面的update事务,也是同样情况:

>update sbtest1 set k=rand()*1024000 where id=1;

不开启事务,执行结束就不会在里边体现

是 begin; update … 这样的显式事务

如果集群包含多个节点,可以采用视图GV$OB_TRANSACTION_PARTICIPANTS
V$OB_TRANSACTION_PARTICIPANTS仅展示会话所在节点上的信息