首页 > 数据库 > 国内数据库 > OceanBase 租户延迟删除的设计猜想
杨涛涛,资深数据库专家,专研 MySQL 十余年。擅长 MySQL、PostgreSQL、MongoDB 等开源数据库相关的备份恢复、SQL 调优、监控运维、高可用架构设计等。目前任职于爱可生,为各大运营商及银行金融企业提供 MySQL 相关技术支持、MySQL 相关课程培训等工作。
对于第二种方式,之前同事们有内部讨论过 OceanBase 的设计初衷:有可能是以防租户被误删、或者是给费用到期并且不续租的租户一段缓冲的时间,让他能在时间到期前备份自己的数据。
DROP TENANT [IF EXISTS] tenant_name [PURGE|FORCE];
DROP TENANT:依赖 sys 租户回收站是否开启,有两种表现形式。
DROP TENANT PURGE:此操作仅延迟删除租户,且具体表现形式和回收站是否开启无关。也即无论回收站开启与否,删除的租户都不会进入回收站,而是到期后,由后台垃圾清理线程删除租户。
DROP TENANT FORCE:此操作立刻删除租户!
那我们接下来用几个简单例子诠释下这些删除操作。
先来创建两个新租户 tenant1、tenant2 。
mysql:5.6.25:oceanbase>create resource unit mini1 max_cpu 1,max_memory '1G',max_disk_size '1G',max_session_num 1200,max_iops 1000;Query OK, 0 rows affected (0.015 sec)<mysql:5.6.25:oceanbase>create resource pool p3 unit 'mini1',unit_num=1;Query OK, 0 rows affected (0.038 sec)<mysql:5.6.25:oceanbase>create resource pool p4 unit 'mini1',unit_num=1;Query OK, 0 rows affected (0.062 sec)<mysql:5.6.25:oceanbase>create tenant tenant1 resource_pool_list=('p3');Query OK, 0 rows affected (2.660 sec)<mysql:5.6.25:oceanbase>create tenant tenant2 resource_pool_list=('p4');回收站开启,删除租户 tenant1 : 查询系统表 __all_tenant ,租户 tenant1 已经被删除,但是租户数据存放在 sys 租户回收站里,可以随时被恢复。
mysql:5.6.25:oceanbase>set recyclebin=on; Query OK, 0 rows affected (0.000 sec) <mysql:5.6.25:oceanbase>drop tenant tenant1; Query OK, 0 rows affected (0.040 sec) <mysql:5.6.25:oceanbase>show recyclebin; +--------------------------------+---------------+--------+----------------------------+ | OBJECT_NAME | ORIGINAL_NAME | TYPE | CREATETIME | +--------------------------------+---------------+--------+----------------------------+ | __recycle_$_1_1678073859469312 | tenant1 | TENANT | 2023-03-06 12:07:21.626602 | +--------------------------------+---------------+--------+----------------------------+ 1 row in set (0.012 sec) <mysql:5.6.25:oceanbase>select tenant_name from __all_tenant where tenant_name = 'tenant1'; Empty set (0.001 sec)
从回收站恢复租户 tenant1 :再次查询系统表 __all_tenant ,租户 tenant1 恢复正常。
mysql:5.6.25:oceanbase>flashback tenant tenant1 to before drop; Query OK, 0 rows affected (0.044 sec) <mysql:5.6.25:oceanbase>show recyclebin; Empty set (0.003 sec) <mysql:5.6.25:oceanbase>select tenant_name from __all_tenant where tenant_name = 'tenant1'; +-------------+ | tenant_name | +-------------+ | tenant1 | +-------------+ 1 row in set (0.002 sec)
回收站关闭,删除租户 tenant1:删除后,依然可以通过系统表 __all_tenant 查询到租户信息。
mysql:5.6.25:oceanbase>set recyclebin=off; Query OK, 0 rows affected (0.001 sec) <mysql:5.6.25:oceanbase>drop tenant tenant1; Query OK, 0 rows affected (0.041 sec) <mysql:5.6.25:oceanbase>select tenant_name from __all_tenant where tenant_name = 'tenant1'; +-------------+ | tenant_name | +-------------+ | tenant1 | +-------------+ 1 row in set (0.001 sec)
直到配置项 schema_history_expire_time 设定的时间到期前,租户 tenant1 都可以对其内部对象正常操作:比如 DQL 语句 、DML 语句等。
[root@ytt-pc obytt111]# obclient -uroot@tenant1#ob-ytt -P 2883 -cA -h 127.1 -D ytt -e "select * from t1;" +----+ | id | +----+ | 1 | | 2 | +----+ [root@ytt-pc obytt111]# obclient -uroot@tenant1#ob-ytt -P 2883 -cA -h 127.1 -Dytt -e "insert into t1 values (10)"
但是无法执行 DDL 语句:比如新建表 t2 则会报错!
[root@ytt-pc obytt111]# obclient -uroot@tenant1#ob-ytt -P 2883 -cA -h 127.1 -Dytt -e "create table t2 like t1;" ERROR 4179 (HY000) at line 1: ddl operation during dropping tenant not allowed
DROP TENANT tenant2 PURGE:延迟删除租户,同样是等配置项 schema_history_expire_time 设定的时间到期后,彻底将租户删除,和上面例子类似。
<mysql:5.6.25:oceanbase>drop tenant tenant2 purge; Query OK, 0 rows affected (0.055 sec) <mysql:5.6.25:oceanbase>select tenant_name from __all_tenant where tenant_name ='tenant2'; +-------------+ | tenant_name | +-------------+ | tenant2 | +-------------+ 1 row in set (0.002 sec)
DROP TENANT tenant2 FORCE :后续不再需要租户 tenant2 ,可以立即删除。
mysql:5.6.25:oceanbase>drop tenant tenant2 force; Query OK, 0 rows affected (0.050 sec) <mysql:5.6.25:oceanbase>select tenant_name from __all_tenant where tenant_name = 'tenant2'; Empty set (0.002 sec)
来自 “ ”, 原文作者: ;原文链接:,如有侵权,请联系管理员删除。