-
Notifications
You must be signed in to change notification settings - Fork 69
[DNM] RFC: keyspace level GC #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ystaticy
wants to merge
54
commits into
tikv:master
Choose a base branch
from
ystaticy:ks_level_gc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 53 commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
57aef25
ks_level_gc init commit
ystaticy b2e017a
in check consistency and trigger compaction
ystaticy 3e5f711
fix words
ystaticy 9196bce
fix words
ystaticy 9e72539
fix words
ystaticy e90dd88
fix words
ystaticy 0900f46
fix words
ystaticy 2dce1cc
add link
ystaticy 09181ad
format
ystaticy b97f612
add details for optimize trigger timing and assert judgment
ystaticy 3689a4d
add details
ystaticy a964053
fix comments
ystaticy 342a08d
fix comments
ystaticy 9c5d786
fix comments
ystaticy 24b2ff8
fix comments
ystaticy 73afd99
fix comments
ystaticy 1b4af39
add Usage and Compatibility
ystaticy 3f2582a
fix comments
ystaticy 0a63d88
fix
ystaticy fb72c0c
fix pick
ystaticy e09dd1e
add upgrade,remove Other non-GC logic desc
ystaticy d68bf14
update img
ystaticy 9607e07
update img
ystaticy 57ad936
fix lint
baiyuqing bd4f336
add Data import and export
ystaticy f40a3c9
add desc about global br
ystaticy 98812bc
add desc about global br
ystaticy 44a3b5e
update
baiyuqing af1fb55
update
baiyuqing 66fbb9b
update formula
baiyuqing c142552
update formula
baiyuqing a5dffa3
update
baiyuqing b1bf526
update
baiyuqing bf00fec
fix
baiyuqing 575fbbe
update Motivation
ystaticy 7cafe00
add
ystaticy 02c37c8
add link for keyspace meta
ystaticy d53aa00
Modify the flow chart
ystaticy d10dbec
Modify the flow chart
ystaticy 8ac31a2
fix comments
ystaticy db0b6b2
fix comments
ystaticy db34775
fix comments
ystaticy 0a9b122
fix comments
ystaticy 1d329a9
fix comments
ystaticy 1eb7445
fix comments
ystaticy 38df077
fix comments
ystaticy 1478202
fix comments
ystaticy 6f70d7d
fix comments
ystaticy 3da02a3
fix code format
ystaticy a83f127
remove upgrade part
ystaticy 1b86eae
correct grammatical and spelling errors
ystaticy a0818df
small fix: Grammar and Expression
ystaticy 5eb460b
small fix: Grammar and Expression
ystaticy 47f606a
update words
ystaticy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Keyspace level GC | ||
|
|
||
| - RFC PR: https://github.com/tikv/rfcs/pull/113 | ||
| - Tracking Issue: https://github.com/tikv/tikv/issues/16896 | ||
|
|
||
| ## Summary | ||
|
|
||
| TiKV support [keyspace][1] level GC (garbage collection). | ||
|
|
||
| ## Concepts of GC management type | ||
|
|
||
| 1. Global GC: | ||
| - It represents the previous default GC logic, All TiDB clusters (including those without keyspace configuration and those with keyspace configuration) use the GC safe point calculated by the GC worker owner without keyspace configuration. | ||
| - The default GC management type for keyspaces is the Global GC. | ||
| 2. Keyspace Level GC: | ||
| - This indicates that each keyspace will advance its own GC safe point. | ||
| - Keyspace GC-related data includes the minimum start timestamp, GC safe point, service safe point, which are stored in the respective etcd paths of each keyspace in PD. | ||
|
|
||
| ## Motivation | ||
|
|
||
| In order to facilitate multi-tenant deployment of TiDB in a shared TiKV cluster, TiDB now supports the keyspace feature. Currently, a TiDB cluster with keyspace can only utilize the GC safe point calculated by the global GC worker. A global TiDB GC worker (a TiDB server without keyspace configuration) shared by all TiDB instances is responsible for calculating the global GC safe point and resolving locks, while each keyspace's TiDB instance has its own GC worker. The GC worker for each keyspace performs only one operation: utilizing the global GC safe point to execute "delete-range" operations within its keyspace ranges. | ||
|
|
||
| However, in this implementation, the calculation of the global GC safe point depends on the oldest timestamp (minStartTS, service safe point, etc.) used to calculate the GC safe point for all TiDB clusters (including those with keyspace configured and those without keyspace configured). When any factor affecting the GC safe point is blocked, the GC of all TiDB clusters will also be blocked. | ||
|
|
||
| Therefore, we propose the **Keyspace Level GC**: | ||
|
|
||
| TiDB Side: | ||
| Isolate the GC safe point calculations and the storage of related data between keyspaces (this concept is referred to as `keyspace level GC`). This will not affect the GC safe point calculations of other keyspaces. Keyspaces can be created by setting `gc_management_type = keyspace_level_gc` to enable keyspace level GC. Then, this keyspace can calculate its own GC safe point. | ||
|
|
||
| TiKV Side: | ||
| In the GC process, it parses the keyspace ID from the data key, uses the keyspace meta configuration and the keyspace level GC safe point corresponding to the keyspace ID to determine the GC safe point value of the data key and then executes the GC logic. | ||
|
|
||
| ## Implementation in TiKV | ||
|
|
||
| 1. Get [keyspace metadata](https://github.com/pingcap/kvproto/blob/d9297553c9009f569eaf4350f68a908f7811ee55/proto/keyspacepb.proto#L26C1-L33C2) and keyspace-level GC safe points from PD: | ||
| - Create a keyspace metadata watch service: Watch the keyspace metadata etcd path to get the keyspace metadata and store it in the mapping from keyspace ID to keyspace metadata. | ||
| - Create a keyspace level GC watch service: Watch the corresponding etcd path to get the GC safe point for the keyspace and store it in the mapping from keyspace ID to keyspace level GC safe point. | ||
|
|
||
| 2. How to get the GC safe point after getting the MVCC key in the Compaction Filter: | ||
|  | ||
|
|
||
| 3. How to determine if a keyspace uses a keyspace level GC safe point: | ||
|  | ||
|
|
||
| 4. Use GC safe point to optimize trigger timing and assert judgment: | ||
| 1. In the global GC, it will skip GC when GC safe point is `0` in `create_compaction_filter`. | ||
| After supporting keyspace level GC, GC is skipped if global GC safe point is 0 or if no keyspace level GC is initialized. | ||
| 2. In the global GC, `check_need_gc` will skip GC in the compaction filter when `props.min_ts` is greater than all GC safe points. | ||
| After implementing keyspace level GC, if `props.min_ts` is greater than the global GC safe point and `props.min_ts` is greater than all keyspace level GC safe points, it will return false. | ||
| 3. In the global GC, assert( safe_point > 0 ) when new compaction filter. | ||
| After supporting keyspace level GC, the assert condition is whether global GC safe point > 0 or any keyspace level GC safe point has been initialized. | ||
|
|
||
| 5. Support the use of keyspace level GC for data import and export: | ||
| - When using BR, CDC, Lightning, or Dumpling to import or export keyspace data, you need to update the service safe point for the specified keyspace. When the task starts, it needs to get the keyspace metadata first to determine whether global or keyspace GC is being used, and then execute the relevant GC logic on the corresponding GC safe point and service safe point. | ||
|
|
||
| ## Global Backup | ||
|
|
||
| Specify ts to backup data for non-keyspaces and all keyspaces in the entire cluster. It will be introduced in another RFC. | ||
|
|
||
| [1]: https://github.com/tikv/rfcs/blob/master/text/0069-api-v2.md#new-key-value-codec | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.