Skip to content

Commit

Permalink
add doc of pub-sub
Browse files Browse the repository at this point in the history
  • Loading branch information
yangj1211 committed Oct 28, 2024
1 parent 250888e commit b813c97
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 414 deletions.
442 changes: 159 additions & 283 deletions docs/MatrixOne/Develop/Publish-Subscribe/pub-sub-overview.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ALTER PUBLICATION pubname
| DROP account_name, [, ... ]]
[COMMENT 'string']
[DATABASE database_name]
[TAble table_name]
```

## 语法解释
Expand All @@ -32,39 +33,39 @@ create account acc2 admin_name 'root' identified by '111';
create database t;
create publication pub3 database t account acc0,acc1;

alter publication pub3 account add accx;--修改发布范围
alter publication pub3 account add acc2;--修改发布范围
mysql> show create publication pub3;
+-------------+-----------------------------------------------------------------------+
| Publication | Create Publication |
+-------------+-----------------------------------------------------------------------+
| pub3 | CREATE PUBLICATION `pub3` DATABASE `t` ACCOUNT `acc0`, `acc1`, `accx` |
+-------------+-----------------------------------------------------------------------+
+-------------+-----------------------------------------------------------+
| Publication | Create Publication |
+-------------+-----------------------------------------------------------+
| pub3 | CREATE PUBLICATION pub3 DATABASE t ACCOUNT acc0,acc1,acc2 |
+-------------+-----------------------------------------------------------+
1 row in set (0.01 sec)

mysql> show publications;
+-------------+----------+---------------------+---------------------+----------------+----------+
| publication | database | create_time | update_time | sub_account | comments |
+-------------+----------+---------------------+---------------------+----------------+----------+
| pub3 | t | 2024-04-24 11:17:37 | 2024-04-24 11:17:44 | acc0,acc1,accx | |
+-------------+----------+---------------------+---------------------+----------------+----------+
1 row in set (0.01 sec)
+-------------+----------+--------+----------------+---------------------+---------------------+---------------------+----------+
| publication | database | tables | sub_account | subscribed_accounts | create_time | update_time | comments |
+-------------+----------+--------+----------------+---------------------+---------------------+---------------------+----------+
| pub3 | t | * | acc0,acc1,acc2 | | 2024-10-28 11:20:20 | 2024-10-28 11:20:43 | |
+-------------+----------+--------+----------------+---------------------+---------------------+---------------------+----------+
1 row in set (0.00 sec)

alter publication pub3 comment "this is pubs";--修改发布备注
mysql> show publications;
+-------------+----------+---------------------+---------------------+----------------+--------------+
| publication | database | create_time | update_time | sub_account | comments |
+-------------+----------+---------------------+---------------------+----------------+--------------+
| pub3 | t | 2024-04-24 11:17:37 | 2024-04-24 11:41:43 | acc0,acc1,accx | this is pubs |
+-------------+----------+---------------------+---------------------+----------------+--------------+
+-------------+----------+--------+----------------+---------------------+---------------------+---------------------+--------------+
| publication | database | tables | sub_account | subscribed_accounts | create_time | update_time | comments |
+-------------+----------+--------+----------------+---------------------+---------------------+---------------------+--------------+
| pub3 | t | * | acc0,acc1,acc2 | | 2024-10-28 11:20:20 | 2024-10-28 11:21:28 | this is pubs |
+-------------+----------+--------+----------------+---------------------+---------------------+---------------------+--------------+
1 row in set (0.00 sec)

create database new_pub3;
alter publication pub3 database new_pub3;--修改发布数据库
mysql> show publications;
+-------------+----------+---------------------+---------------------+----------------+--------------+
| publication | database | create_time | update_time | sub_account | comments |
+-------------+----------+---------------------+---------------------+----------------+--------------+
| pub3 | new_pub3 | 2024-04-24 11:17:37 | 2024-04-24 11:43:36 | acc0,acc1,accx | this is pubs |
+-------------+----------+---------------------+---------------------+----------------+--------------+
+-------------+----------+--------+----------------+---------------------+---------------------+---------------------+--------------+
| publication | database | tables | sub_account | subscribed_accounts | create_time | update_time | comments |
+-------------+----------+--------+----------------+---------------------+---------------------+---------------------+--------------+
| pub3 | new_pub3 | * | acc0,acc1,acc2 | | 2024-10-28 11:20:20 | 2024-10-28 11:21:44 | this is pubs |
+-------------+----------+--------+----------------+---------------------+---------------------+---------------------+--------------+
1 row in set (0.00 sec)
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
## **语法结构**

```
CREATE PUBLICATION pubname
DATABASE database_name ACCOUNT
CREATE PUBLICATION <pubname>
DATABASE <database_name>[<table_name>] ACCOUNT
[ { ALL
| account_name, [, ... ] }]
[ COMMENT 'string']
Expand All @@ -23,13 +23,20 @@ CREATE PUBLICATION pubname
## **示例**

```sql
create database t;
create account acc0 admin_name 'root' identified by '111';
create account acc1 admin_name 'root' identified by '111';
mysql> create publication pub1 database t account acc0,acc1;
Query OK, 0 rows affected (0.01 sec)
create account acc01 admin_name 'root' identified by '111';
create account acc02 admin_name 'root' identified by '111';
create database db1;
use db1;
create table t1(n1 int);
create table t2(n1 int);

--数据库级别发布
create publication db_pub1 database db1 account acc01,acc02;

--表级别发布
create publication tab_pub1 database db1 table t1,t2 account acc01,acc02;
```

## 限制

MatrxiOne 当前仅支持一次发布一个数据库数据
- 数据库级别的发布,目前仅支持一次发布一个数据库数据
Original file line number Diff line number Diff line change
Expand Up @@ -21,81 +21,37 @@ PUBLICATION pubname;
## **示例**

```sql
-- 假设系统管理员创建了一个租户 acc1 为订阅方
create account acc1 admin_name 'root' identified by '111';

-- 假设会话 1 为发布方,由发布方先发布一个数据库给租户
create database sys_db_1;
use sys_db_1;
create table sys_tbl_1(a int primary key );
insert into sys_tbl_1 values(1),(2),(3);
create view v1 as (select * from sys_tbl_1);
create publication sys_pub_1 database sys_db_1;
mysql> show publications;
+-------------+----------+---------------------+-------------+-------------+----------+
| publication | database | create_time | update_time | sub_account | comments |
+-------------+----------+---------------------+-------------+-------------+----------+
| sys_pub_1 | sys_db_1 | 2024-04-24 11:54:36 | NULL | * | |
+-------------+----------+---------------------+-------------+-------------+----------+
1 row in set (0.01 sec)

-- 再开启一个新的会话,假设会话 2 为订阅方,由订阅方订阅已发布的数据库
mysql -h 127.0.0.1 -P 6001 -u acc1:root -p --登录租户账号

create database sub1 from sys publication sys_pub_1;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mo_catalog |
| mysql |
| sub1 |
| system |
| system_metrics |
+--------------------+
6 rows in set (0.01 sec)
create account acc01 admin_name 'root' identified by '111';
create database db1;
use db1;
create table t1(n1 int);
create table t2(n1 int);

--创建发布
create publication db_pub1 database db1 account acc01;
create publication tab_pub1 database db1 table t1,t2 account acc01;

--连接租户 acc01
mysql> show subscriptions all;
+----------+-------------+--------------+------------+-------------+---------------------+----------+----------+--------+
| pub_name | pub_account | pub_database | pub_tables | pub_comment | pub_time | sub_name | sub_time | status |
+----------+-------------+--------------+------------+-------------+---------------------+----------+----------+--------+
| tab_pub1 | sys | db1 | t1,t2 | | 2024-10-25 17:06:06 | NULL | NULL | 0 |
| db_pub1 | sys | db1 | * | | 2024-10-25 17:05:54 | NULL | NULL | 0 |
+----------+-------------+--------------+------------+-------------+---------------------+----------+----------+--------+
2 rows in set (0.00 sec)

create database db_sub1 from sys publication db_pub1;
create database tab_sub1 from sys publication tab_pub1;

mysql> show subscriptions;
+-----------+-------------+--------------+---------------------+----------+---------------------+
| pub_name | pub_account | pub_database | pub_time | sub_name | sub_time |
+-----------+-------------+--------------+---------------------+----------+---------------------+
| sys_pub_1 | sys | sys_db_1 | 2024-04-24 11:54:36 | sub1 | 2024-04-24 11:56:05 |
+-----------+-------------+--------------+---------------------+----------+---------------------+
1 row in set (0.01 sec)

mysql> use sub1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_sub1 |
+----------------+
| sys_tbl_1 |
| v1 |
+----------------+
2 rows in set (0.01 sec)

mysql> desc sys_tbl_1;
+-------+---------+------+------+---------+-------+---------+
| Field | Type | Null | Key | Default | Extra | Comment |
+-------+---------+------+------+---------+-------+---------+
| a | INT(32) | NO | PRI | NULL | | |
+-------+---------+------+------+---------+-------+---------+
1 row in set (0.01 sec)

mysql> select * from sys_tbl_1 order by a;
+------+
| a |
+------+
| 1 |
| 2 |
| 3 |
+------+
3 rows in set (0.01 sec)
-- 订阅成功
+----------+-------------+--------------+------------+-------------+---------------------+----------+---------------------+--------+
| pub_name | pub_account | pub_database | pub_tables | pub_comment | pub_time | sub_name | sub_time | status |
+----------+-------------+--------------+------------+-------------+---------------------+----------+---------------------+--------+
| tab_pub1 | sys | db1 | t1,t2 | | 2024-10-25 17:06:06 | tab_sub1 | 2024-10-25 17:09:24 | 0 |
| db_pub1 | sys | db1 | * | | 2024-10-25 17:05:54 | db_sub1 | 2024-10-25 17:09:23 | 0 |
+----------+-------------+--------------+------------+-------------+---------------------+----------+---------------------+--------+
2 rows in set (0.00 sec)
```

!!! note
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## **语法说明**

返回所有发布名、发布的数据库名、发布创建时间、发布最新修改时间、发布指定的租户名列表(如果是所有则展示 "*")和备注
返回所有发布名、发布的数据库/表名、发布创建时间、发布最新修改时间、发布指定的租户名列表(如果是所有则展示 "*")等信息

如需查看更多信息,需要拥有租户管理员权限,查看系统表 mo_pubs 查看更多参数。

Expand All @@ -22,10 +22,10 @@ create database t;
create publication pub3 database t account acc0,acc1;

mysql> show publications;
+-------------+----------+---------------------+-------------+-------------+----------+
| publication | database | create_time | update_time | sub_account | comments |
+-------------+----------+---------------------+-------------+-------------+----------+
| pub3 | t | 2024-04-23 10:10:59 | NULL | acc0,acc1 | |
+-------------+----------+---------------------+-------------+-------------+----------+
+-------------+----------+--------+-------------+---------------------+---------------------+-------------+----------+
| publication | database | tables | sub_account | subscribed_accounts | create_time | update_time | comments |
+-------------+----------+--------+-------------+---------------------+---------------------+-------------+----------+
| pub3 | t | * | acc0,acc1 | | 2024-10-25 16:36:04 | NULL | |
+-------------+----------+--------+-------------+---------------------+---------------------+-------------+----------+
1 row in set (0.00 sec)
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## **语法说明**

返回所有发布名、发布租户名、发布的数据库名、发布给该租户的时间、订阅名和创建该订阅的时间
返回所有发布名、发布租户名、发布的数据库名、发布的表名、备注、发布给该租户的时间、订阅名、创建该订阅的时间和订阅状态(0:可正常订阅;1:发布存在,但无订阅权限;2:本来订阅了发布,但是又删除了发布)

## **语法结构**

Expand All @@ -17,34 +17,53 @@ SHOW SUBSCRIPTIONS [ALL];
## **示例**

```sql

-- 在 sys 租户执行

create account acc01 admin_name 'root' identified by '111';
create account acc02 admin_name 'root' identified by '111';
create database db1;
use db1;
create table t1(n1 int);
create table t2(n1 int);

--数据库级别发布
create publication db_pub1 database db1 account acc01,acc02;

--表级别发布
create publication tab_pub1 database db1 table t1,t2 account acc01,acc02;

-- 在 acc01 租户执行
mysql> show subscriptions all;
+----------+-------------+--------------+---------------------+----------+----------+
| pub_name | pub_account | pub_database | pub_time | sub_name | sub_time |
+----------+-------------+--------------+---------------------+----------+----------+
| pub3 | sys | t | 2024-04-23 11:11:06 | NULL | NULL |
+----------+-------------+--------------+---------------------+----------+----------+
1 row in set (0.01 sec)
+----------+-------------+--------------+------------+-------------+---------------------+----------+----------+--------+
| pub_name | pub_account | pub_database | pub_tables | pub_comment | pub_time | sub_name | sub_time | status |
+----------+-------------+--------------+------------+-------------+---------------------+----------+----------+--------+
| tab_pub1 | sys | db1 | t1,t2 | | 2024-10-14 19:00:21 | NULL | NULL | 0 |
| db_pub1 | sys | db1 | * | | 2024-10-14 19:00:16 | NULL | NULL | 0 |
+----------+-------------+--------------+------------+-------------+---------------------+----------+----------+--------+
2 rows in set (0.00 sec)

mysql> show subscriptions;
Empty set (0.00 sec)

mysql> create database sub3 from sys publication pub3;
Query OK, 1 row affected (0.02 sec)
create database db_sub1 from sys publication db_pub1;
create database tab_sub1 from sys publication tab_pub1;

mysql> show subscriptions all;
+----------+-------------+--------------+---------------------+----------+---------------------+
| pub_name | pub_account | pub_database | pub_time | sub_name | sub_time |
+----------+-------------+--------------+---------------------+----------+---------------------+
| pub3 | sys | t | 2024-04-23 11:11:06 | sub3 | 2024-04-23 11:12:11 |
+----------+-------------+--------------+---------------------+----------+---------------------+
1 row in set (0.00 sec)
+----------+-------------+--------------+------------+-------------+---------------------+----------+---------------------+--------+
| pub_name | pub_account | pub_database | pub_tables | pub_comment | pub_time | sub_name | sub_time | status |
+----------+-------------+--------------+------------+-------------+---------------------+----------+---------------------+--------+
| tab_pub1 | sys | db1 | t1,t2 | | 2024-10-14 19:00:21 | tab_sub1 | 2024-10-14 19:01:41 | 0 |
| db_pub1 | sys | db1 | * | | 2024-10-14 19:00:16 | db_sub1 | 2024-10-14 19:01:30 | 0 |
+----------+-------------+--------------+------------+-------------+---------------------+----------+---------------------+--------+
2 rows in set (0.00 sec)

mysql> show subscriptions;
+----------+-------------+--------------+---------------------+----------+---------------------+
| pub_name | pub_account | pub_database | pub_time | sub_name | sub_time |
+----------+-------------+--------------+---------------------+----------+---------------------+
| pub3 | sys | t | 2024-04-23 11:11:06 | sub3 | 2024-04-23 11:12:11 |
+----------+-------------+--------------+---------------------+----------+---------------------+
1 row in set (0.01 sec)

+----------+-------------+--------------+------------+-------------+---------------------+----------+---------------------+--------+
| pub_name | pub_account | pub_database | pub_tables | pub_comment | pub_time | sub_name | sub_time | status |
+----------+-------------+--------------+------------+-------------+---------------------+----------+---------------------+--------+
| tab_pub1 | sys | db1 | t1,t2 | | 2024-10-14 19:00:21 | tab_sub1 | 2024-10-14 19:01:41 | 0 |
| db_pub1 | sys | db1 | * | | 2024-10-14 19:00:16 | db_sub1 | 2024-10-14 19:01:30 | 0 |
+----------+-------------+--------------+------------+-------------+---------------------+----------+---------------------+--------+
2 rows in set (0.00 sec)
```
16 changes: 16 additions & 0 deletions docs/MatrixOne/Reference/System-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,26 @@ MatrixOne 系统数据库和表是 MatrixOne 存储系统信息的地方,你
| table_list | TEXT(0) | 在非 all table 时,发布库内包含的表清单,表名与 database_id 对应数据库下的表一一对应|
| account_list | TEXT(0) |在非 all account 时,允许订阅该发布库的 account 清单|
| created_time | TIMESTAMP(0) |创建发布库的时间 |
| updated_time | TIMESTAMP(0) |更新发布库的时间 |
| owner | INT UNSIGNED(32) | 创建发布库对应的角色 ID |
| creator | INT UNSIGNED(32) | 创建发布库对应的用户 ID |
| comment | TEXT(0) | 创建发布库的备注信息 |

### `mo_subs`

| 列属性 | 类型 | 描述 |
| ---------------------| --------------- | ----------------- |
| sub_account_id | INT(32) | 订阅租户 id|
| sub_name | VARCHAR(5000) | 订阅名 |
| sub_time | TIMESTAMP(0) | 订阅时间 |
| pub_account_name |VARCHAR(300) | 发布租户的名称 |
| pub_name | VARCHAR(64) | 发布名称|
| pub_database | VARCHAR(5000) |发布的数据库|
| pub_tables | TEXT(0) |发布的表 |
| pub_time | TIMESTAMP(0) | 发布的时间 |
| pub_comment | TEXT(0) | 来自发布库的备注信息 |
| status | TINYINT(8) | 订阅状态,0 是正常订阅,1 是发布存在,但无订阅权限,2 是本来订阅了发布,但是又删除了发布 |

### `mo_stages`

| 列属性 | 类型 | 描述 |
Expand Down

0 comments on commit b813c97

Please sign in to comment.