Soft-Drop Table
Soft-drop 用于在分布式 GreptimeDB 集群中防止误执行 DROP TABLE。开启后,DROP TABLE 会关闭表的 regions,并把表元数据移动到 tombstone,而不是立即删除物理数据。你可以在保留期过期前恢复表,也可以在确认不再需要时手动 purge。
Soft-drop 适用于分布式模式下支持该能力的表引擎。Standalone 模式仍保持原有 hard-drop 行为。开启集群级 soft-drop 开关后,file-engine 表和 metric logical 表也仍保持 hard-drop 行为。
开启 soft-drop
Soft-drop 在 Metasrv 的 GC 配置中开启,并要求 Metasrv GC 已启用。
[gc]
enable = true
[gc.experimental_soft_drop]
enable = true
retention = "7d"
配置项如下:
| 配置项 | 说明 |
|---|---|
gc.enable | 启用 Metasrv GC 调度器。设置 gc.experimental_soft_drop.enable = true 时必须启用。 |
gc.experimental_soft_drop.enable | 在分布式模式中为支持的表启用 soft-drop。 |
gc.experimental_soft_drop.retention | Soft-dropped table 在 recycle bin 中保留多久后由 Metasrv GC 自动 purge。该值必须至少为 1ms。 |
修改配置后请重启 Metasrv。普通文件 GC 仍需按照垃圾回收(GC)中的说明,保持 Metasrv 与 Datanode 的 GC 配置一致。
删除表
开启 soft-drop 后,照常使用 DROP TABLE:
DROP TABLE monitor;
该表会对 DDL 和 DML 不可见,也不再出现在 information_schema.tables 中,但会出现在 information_schema.recycle_bin 中,直到被恢复、手动 purge,或在 retention deadline 后被自动 purge。
查看已删除表
查询 recycle bin 可以查看已删除表及其 retention deadline:
SELECT object_id,
object_type,
original_catalog_name,
original_schema_name,
original_object_name,
dropped_at,
retention_expires_at,
purge_status,
restorable
FROM information_schema.recycle_bin
WHERE original_schema_name = 'public';
该表只展示 active 且可恢复的 soft-dropped table。已经进入 purge 流程的表不会显示在 recycle bin 中。