Skip to content
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

[DNM] RFC: keyspace level GC #113

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
57aef25
ks_level_gc init commit
ystaticy Apr 24, 2024
b2e017a
in check consistency and trigger compaction
ystaticy Apr 24, 2024
3e5f711
fix words
ystaticy Apr 24, 2024
9196bce
fix words
ystaticy Apr 24, 2024
9e72539
fix words
ystaticy Apr 24, 2024
e90dd88
fix words
ystaticy Apr 24, 2024
0900f46
fix words
ystaticy Apr 24, 2024
2dce1cc
add link
ystaticy Apr 25, 2024
09181ad
format
ystaticy Apr 26, 2024
b97f612
add details for optimize trigger timing and assert judgment
ystaticy May 6, 2024
3689a4d
add details
ystaticy May 6, 2024
a964053
fix comments
ystaticy May 9, 2024
342a08d
fix comments
ystaticy May 9, 2024
9c5d786
fix comments
ystaticy May 9, 2024
24b2ff8
fix comments
ystaticy May 9, 2024
73afd99
fix comments
ystaticy May 9, 2024
1b4af39
add Usage and Compatibility
ystaticy May 9, 2024
3f2582a
fix comments
ystaticy May 9, 2024
0a63d88
fix
ystaticy May 10, 2024
fb72c0c
fix pick
ystaticy May 10, 2024
e09dd1e
add upgrade,remove Other non-GC logic desc
ystaticy May 10, 2024
d68bf14
update img
ystaticy May 10, 2024
9607e07
update img
ystaticy May 10, 2024
57ad936
fix lint
baiyuqing May 10, 2024
bd4f336
add Data import and export
ystaticy May 10, 2024
f40a3c9
add desc about global br
ystaticy May 10, 2024
98812bc
add desc about global br
ystaticy May 10, 2024
44a3b5e
update
baiyuqing May 11, 2024
af1fb55
update
baiyuqing May 11, 2024
66fbb9b
update formula
baiyuqing May 11, 2024
c142552
update formula
baiyuqing May 13, 2024
a5dffa3
update
baiyuqing May 16, 2024
b1bf526
update
baiyuqing May 16, 2024
bf00fec
fix
baiyuqing May 16, 2024
575fbbe
update Motivation
ystaticy Jun 5, 2024
7cafe00
add
ystaticy Jun 5, 2024
02c37c8
add link for keyspace meta
ystaticy Jun 5, 2024
d53aa00
Modify the flow chart
ystaticy Jun 12, 2024
d10dbec
Modify the flow chart
ystaticy Jun 12, 2024
8ac31a2
fix comments
ystaticy Jun 12, 2024
db0b6b2
fix comments
ystaticy Jun 12, 2024
db34775
fix comments
ystaticy Jun 12, 2024
0a9b122
fix comments
ystaticy Jun 12, 2024
1d329a9
fix comments
ystaticy Jun 12, 2024
1eb7445
fix comments
ystaticy Jun 12, 2024
38df077
fix comments
ystaticy Jun 12, 2024
1478202
fix comments
ystaticy Jun 12, 2024
6f70d7d
fix comments
ystaticy Jun 12, 2024
3da02a3
fix code format
ystaticy Jun 25, 2024
a83f127
remove upgrade part
ystaticy Jun 25, 2024
1b86eae
correct grammatical and spelling errors
ystaticy Sep 20, 2024
a0818df
small fix: Grammar and Expression
ystaticy Sep 23, 2024
5eb460b
small fix: Grammar and Expression
ystaticy Sep 23, 2024
47f606a
update words
ystaticy Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added media/keyspace-level-gc-get-gc-sp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added media/keyspace-level-gc-is-global-gc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions text/0113-keyspace-level-gc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Keyspace level GC

## Summary

- RFC PR: https://github.com/tikv/rfcs/pull/113
- Tracking Issue: https://github.com/tikv/tikv/issues/16896

TiKV support keyspace level gc.

## Motivation

Previously, TiDB has supported the deployment of multiple TiDB clusters with different keyspaces
on a single PD TiKV cluster.

We've implemented multiple TiDB clusters, with one global TiDB GC worker (A TiDB server without Keyspace configuration)
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
to calculate the global GC safe point and resolve locks, While each keyspace's TiDB has their own GC Worker,
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
keyspace GC Worker use the global GC safe point to do deleteRange in the sepical keyspace ranges.

But old implementation causes the calculation of the global gc to depend on the oldest safe point and min start ts
of all keyspaces and TiDB cluster without keyspace configured.
ystaticy marked this conversation as resolved.
Show resolved Hide resolved

So we propose the implementation of keyspace level gc:

TiDB PR https://github.com/pingcap/tidb/pull/51300 implements:
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
Isolation of GC safe point calculations between keyspaces (the concept is 'keyspace level GC').
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
When the Keyspace GC safe point calculation of Keyspace with keyspace level gc is slow,
it will not affect other keyspaces GC safe point calculation.
Keyspaces can be created by setting gc_management_type = keyspace_level_gc to enable keyspace level GC,
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
then this keyspace can calculate GC safe point by itself.

TiKV PR https://github.com/tikv/tikv/pull/16808 implemented on TiKV side:
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
In GC process, it parses the keyspace id from the data key,
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
combines the keyspace meta config and the keyspace level GC safe point corresponding to the keyspace id to determine
the GC safe point value of the data key and execute the GC logic.


## Concepts of GC management type:
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
1. Global GC:
- Represents the previous default GC logic; there is a TiDB calculate the global GC safe point for the whole cluster.
- The default GC management type for keyspace is Global GC,
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
2. Keyspace level GC:
- Indicates that the keyspace will advance its own gc safe point.
- It is possible and only possible to set gc_management_type = keyspace_level_gc when PD creates keyspaces.
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
- The keyspace which already set gc_management_type = keyspace_level_gc, 'gc_management_type' it can not be updated
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
to "global_gc".
- Keyspace GC-related data: min start ts, GC safe point,service safe point of keyspace have their own etcd path
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
with keyspace prefix in PD.
- Therefore, the keysapce can calculate the GC by itself.
ystaticy marked this conversation as resolved.
Show resolved Hide resolved


## Implementation in TiKV
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
1. Get keyspace meta and keyspace level GC safe point:
- New KeyspaceMetaWatchService : Watch keyspace meta etcd path to get the keyspace meta and put it
in cache keyspace_id_meta_map<u32, keyspacepb::KeyspaceMeta>.
- New KeyspaceLevelGCWatchService : Watch the etcd path of the keyspace GC safe point to get the GC safe point
with keyspace level GC enabled, put it in cache keyspace_level_gc_map<u32, u64>.

2. How to get GC safe point by mvcc key in Compaction Filter:
![img.png](../media/keyspace-level-gc-get-gc-sp.png)

3. How to determine if a keyspace uses a global gc safe point:
![img.png](../media/keyspace-level-gc-is-global-gc.png)

4. Use GC safe point to optimize trigger timing and assert judgment
1. Skip GC when GC safe point is 0 in create_compaction_filter.
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
2. check_need_gc function return false in create_compaction_filter.
3. assert( safe_point > 0 ) when new compaction filter.

5. Other non-GC logic that uses GC safe point does not currently have to support keyspace level GC.
1. check region consistency command:
1. It needs check GC safe point on followers to ensure that the data to be checked on the follower is not GC.
2. It doesn't support which keyspace with keyspace level gc enabled yet, if user request check consistency
for the keyspace range, the user will get a "not supported" message.
2. GC safe point used in raftstore to trigger compaction when no valid split key can be found.
ystaticy marked this conversation as resolved.
Show resolved Hide resolved
It was introduced in PR https://github.com/tikv/tikv/pull/15284
1. It just uses GC safe point to determine when to trigger compaction.
The main PR of the Keyspace level gc will not fit this logic.
It will be considered for submitting another PR for support after the keyspace level gc core PR is merged.