yugabyte / yugabyte-db

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.
https://www.yugabyte.com
Other
8.89k stars 1.06k forks source link

[DocDB] Tablet splitting: parent_data_compacted field may be updated too early #19239

Open arybochkin opened 1 year ago

arybochkin commented 1 year ago

Jira Link: DB-8029

Description

There's a chance that KvStoreInfoPB.parent_data_compacted get updated while parent's SST files are still being compacted. Consider the following scenario: 1) Parent tablet is split 2) First child tablet is opening and starting post split compaction 3) Second child tablet is opening and is waiting for a free slot to run post split compaction (by default only 1 manual compaction can be run on a tserver, post split compaction is a type of manual compaction) 4) Background compaction is actively running for the second tablet 5) First child's post split compaction is done, its parent_data_compacted is changed to true 6) Second child's post split compaction is starting, but background compaction has taken all the SST files and is still running 7) Second child's post split compaction sees there are no files to take and finished post split compaction with changing parent_data_compacted to true 8) Tablet splitting is triggered for a second child while background compaction with parent's SST files is still running, but second child sees parent_data_compacted is true and starts splitting.

Side effect of the second split with the uncompacted data could result in non-optimal middle key for the second split (split of a second child), in worse case one of second child's children can be empty and parent's files got referenced longer.

Warning: Please confirm that this issue does not contain any sensitive information

arybochkin commented 1 year ago

This statement should be moved after comparison agains file number and return an indication of manual conflict.