Skip to content

TiKV GcKeys task doesn't work when called with multiple keys (at least in 5.1 but I think for everything) #11217

Description

@frew

Bug Report

In gc worker, https://github.com/tikv/tikv/blob/master/src/server/gc_worker/gc_worker.rs#L340 the GcKeys GC task when called with multiple keys tries to get the list of regions overlapping the key range for the task and then do a sorted merge of the keys and the space encompassed by the regions. However, it fails to prepend the keys with the data prefix ('z') when passing them to get_regions_in_range, get_regions_in_range doesn't prepend the keys, and so the keys form an invalid range and no regions are ever returned. This makes garbage collection of delete markers not happen.

To verify the issue I added some logging statements in a branch: https://github.com/frew/tikv/pull/1/files#diff-fad0fef4b49a4159243096a9212032ae40e8b88cd0deb3c60df42a3dbdc639dfR385 - an example line from the first logging statement showing the issue in our cluster:

[2021/11/03 06:46:28.397 +00:00] [INFO] [region_info_accessor.rs:385] ["gc get_regions_in_range"] [start_key="[116, 128, 0, 0, 0, 0, 0, 0, 255, 159, 95, 114, 128, 0, 0, 12, 81, 255, 152, 74, 144, 0, 0, 0, 0, 0, 250]"] [first_region="Some(([122, 116, 128, 0, 0, 0, 0, 0, 0, 255, 19, 0, 0, 0, 0, 0, 0, 0, 248], 53))"] [regions_size=126845]

(note the prefix 122 on the first_region but not on the start_key)

I suggest adding data_key() to https://github.com/tikv/tikv/blob/master/src/server/gc_worker/gc_worker.rs#L338 and the following line, but defer to your expertise.

What version of TiKV are you using?

5.1.2

What operating system and CPU are you using?

Linux on GCP n2d

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-5.0This bug affects 5.0.x versions.affects-5.1This bug affects 5.1.x versions.affects-5.2This bug affects 5.2.x versions.severity/criticaltype/bugThe issue is confirmed as a bug.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions