软删除主要用于防范数据被错误的永久删除。具体而言,软删除应该具有如下几个功能:
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
,默认为10分钟)扫描各个数据文件夹(配置文件 data_dirs
),统计文件夹的使用情况。对于标记为 .gar
后缀的 replica 文件夹,获取其最后修改时间,并和当前时间进行比较,只有当两者时间差超过了阈值(配置文件 gc_disk_garbage_replica_interval_seconds
,默认为1天)后,在会将文件夹删除掉。此时数据才算被真正物理删除。所以综上所述,能够影响表被删除后进行物理删除的时间点的配置项包括:
[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 更新配置的情况,可以登入Pegasus的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
关键点:
实现要点简述: