tikv / tikv/pd

Clean up data related to archived keyspaces

Open
#9,298 0 comments 0 reactions 0 assignees View on GitHub
type/enhancement
Dominant language
Go
Stars
1.2k
Forks
783
Avg merge
5d 21h
Merged PRs (30d)
36

Description

## Enhancement Task

**The process between PD and TiKV**
1. On the PD side, iterate over archived keyspaces and perform:
1. Cleanup of Etcd keys
2. Cleanup of placement rules
3. PD returns the following list to TiKV in the heartbeat response: List of archived keyspaces
2. On the TiKV side:
1. Upon receiving the archived keyspaces in the heartbeat response, execute unsafeDestroyRange
3. On the PD side, determine whether the data cleanup for the corresponding keyspace on TiKV has completed:
1. Use the condition that all regions under the archived keyspace have approximate_keys == 0 as the indicator that TiKV has finished cleaning the data
2. If the condition (all region approximate_keys == 0) is not met, maintain the archived state and continue notifying TiKV via heartbeat to execute unsafeDestroyRange
4. PD side cleans up Region labels:
1. If PD determines that all regions under the keyspace have approximate_keys == 0, proceed to clean Region labels
5. After PD completes cleaning Region labels: Finally set the keyspace state to tombstone.

**TiKV-side Logic**
**Handling of Archived Keyspaces**

1. When TiKV initializes `gc_worker`, it receives:
```rust
pub struct ArchivedKeyspaceManager {
archived_keyspaces: Arc>, // List of archived keyspaces returned by PD
}
```
2. The `pd_worker` in TiKV also receives `Arc`.
3. In `store_heartbeat`, TiKV obtains the list of archived keyspaces returned by PD and:
1. Updates `ArchivedKeyspaceManager.archived_keyspaces` accordingly.
4. Removal of elements from `archived_keyspaces`:
1. TiKV's `gc_worker` periodically processes `archived_keyspaces`. Upon successful cleanup of a keyspace, it calls back to remove that keyspace from `archived_keyspaces`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.