软删除主要用于防范数据被错误的永久删除。具体而言,软删除应该具有如下几个功能:
shell端提供了drop
和recall
命令支持软删除。
使用方式:
drop <app_name> [-r|--reserve_seconds num]
drop命令用于删除一个表,通过-r
选项指定数据的保留时间,从删除时间开始计算,单位为秒。如果不指定,则使用配置文件hold_seconds_for_dropped_app
指定的值,默认为7天。
表删除成功后:
ERR_OBJECT_NOT_FOUND
,提示表不存在。ls
命令看不到被删除的表。ls -a
命令可以看到被删除的表。过期表的数据在各个replica server上也未必能立即被物理删除,因为:
set_meta_level lively
,使meta server进入负载均衡模式,meta server才会通过config_sync
RPC通知replica server删除相关的replica。而replica server在收到meta server的通知后,就会将需删除的replica文件夹通过添加.gar
后缀进行重命名,表示这是可以被删除的垃圾数据。但此时数据仍未被真正物理删除。disk_stat_interval_seconds
)扫描各个数据文件夹(配置文件data_dirs
),统计文件夹的使用情况。对于标记为.gar
后缀的replica文件夹,获取其最后修改时间,并和当前时间进行比较,只有当两者时间差超过了阈值(配置文件gc_disk_garbage_replica_interval_seconds
)后,在会将文件夹删除掉。此时数据才算被真正物理删除。所以综上所述,能够影响表被删除后进行物理删除的时间点的配置项包括:
[meta_server] hold_seconds_for_dropped_app
:当drop表没有指定-r
选项时,决定该表的保留时间。[replication] disk_stat_interval_seconds
:replica server定期扫描各个数据文件夹的时间间隔。[replication] gc_disk_garbage_replica_interval_seconds
:垃圾replica文件夹的最后修改时间距离当前时间超过这个阈值,文件夹才会被删除。如果遇到需要紧急删除数据以释放磁盘空间,但是又不方便重启replica server更新配置的情况,可以根据表ID进行手工暴力删除,但是千万注意:
使用方式
recall <app_id> [new_app_name]
只要表的保留时间还没有过期,就能执行恢复:
以下是使用示例:删除mytable表,然后恢复成新表名mytable2
>>> ls app_id status app_name app_type partition_count replica_count is_stateful drop_expire_time envs_count 1 AVAILABLE temp pegasus 8 3 true - 0 2 AVAILABLE mytable pegasus 8 3 true - 0 list apps succeed >>> drop mytable reserve_seconds = 0 drop app mytable succeed >>> ls app_id status app_name app_type partition_count replica_count is_stateful drop_expire_time envs_count 1 AVAILABLE temp pegasus 8 3 true - 0 list apps succeed >>> ls -a app_id status app_name app_type partition_count replica_count is_stateful drop_expire_time envs_count 1 AVAILABLE temp pegasus 8 3 true - 0 2 DROPPED mytable pegasus 8 3 true 2018-07-28 19:07:21 0 list apps succeed >>> recall 2 mytable2 recall app ok, id(2), name(mytable2), partition_count(8), wait it ready mytable2 not ready yet, still waiting... (0/8) mytable2 not ready yet, still waiting... (0/8) mytable2 not ready yet, still waiting... (0/8) mytable2 not ready yet, still waiting... (0/8) mytable2 not ready yet, still waiting... (0/8) mytable2 not ready yet, still waiting... (0/8) mytable2 not ready yet, still waiting... (0/8) mytable2 not ready yet, still waiting... (0/8) mytable2 not ready yet, still waiting... (7/8) mytable2 is ready now: (8/8) recall app 2 succeed >>> ls app_id status app_name app_type partition_count replica_count is_stateful drop_expire_time envs_count 1 AVAILABLE temp pegasus 8 3 true - 0 2 AVAILABLE mytable2 pegasus 8 3 true - 0 list apps succeed
关键点:
实现要点简述: