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

merge-checker: The empty region corresponding to the dropped table cannot be merged forever with enable-cross-table-merge false #8886

Open
AndreMouche opened this issue Dec 9, 2024 · 2 comments
Labels
affects-6.0 affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.2 affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. type/bug The issue is confirmed as a bug.

Comments

@AndreMouche
Copy link
Member

Bug Report

The empty region corresponding to the dropped table cannot be merged forever with enable-cross-table-merge false.

What did you do?

First, I adjusted the following configuration, expecting each region to contain data for only one table.

 tiup ctl:v7.5.2 pd config set enable-cross-table-merge false
Starting component ctl: /home/tidb/.tiup/components/ctl/v7.5.2/ctl pd config set enable-cross-table-merge false
Success!

mysql> set config tikv `coprocessor.split-region-on-table`=true;
Query OK, 0 rows affected (0.01 sec)

2.create a new database and create 100 tables in it: After creating 100 tables, I saw that 300 new regions were created.

sysbench --config-file=config oltp_point_select --tables=100 --table-size=10 prepare

mysql> select count(*),DB_name from information_schema.TIKV_REGION_STATUS where DB_name='crosstable'\G
*************************** 1. row ***************************
count(*): 400
 DB_name: crosstable

select distinct(region_id) from information_schema.TIKV_REGION_STATUS where DB_name='crosstable'\G
...
region_id: 539796156
*************************** 297. row ***************************
region_id: 539795040
*************************** 298. row ***************************
region_id: 539794808
*************************** 299. row ***************************
region_id: 539794792
*************************** 300. row ***************************
region_id: 539794976
300 rows in set (0.09 sec)
  1. drop databse:Just delete all these one hundred tables directly.
mysql> drop database crosstable;
Query OK, 0 rows affected (2.02 sec)

What did you expect to see?

The number of empty regions will be restored to the state before testing began, which means that the regions corresponding to these 100 tables should be merged together.

What did you see instead?

The number of empty regions increased by 100 compared to before the test, meaning that each of these one hundred tables left behind an empty region.

Image

The reason for the inability to merge is "adj-disallow-merge"

Image

It returns false on L292

return false
}
}
policy := cluster.GetSharedConfig().GetKeyType()
switch policy {
case constant.Table:
if cluster.GetSharedConfig().IsCrossTableMergeEnabled() {
return true
}
return isTableIDSame(region, adjacent)
case constant.Raw:
return true
case constant.Txn:
return true
default:
return isTableIDSame(region, adjacent)

The main reason is that PD cannot know if the region corresponding to the table has been completely deleted(drop). PD needs a method to distinguish between drop table and truncate table's empty regions in order to fix this issue.

What version of PD are you using (pd-server -V)?

v7.5.2

@AndreMouche AndreMouche added type/bug The issue is confirmed as a bug. affects-6.0 affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.2 affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. labels Dec 9, 2024
@rleungx
Copy link
Member

rleungx commented Dec 11, 2024

I think it's an expected behavior?

@AndreMouche
Copy link
Member Author

AndreMouche commented Dec 17, 2024

I think it's an expected behavior?

Yes, but the scenarios mentioned in the issue are indeed real and we need to consider addressing this issue.
I think one simpler way to fix this issue is add logic both in PD and TiDB:

TIDB(ddl owner?):

  1. when executing truncate/drop table which will delete data in a special table-id, we can also add a label or placement-rule to the data-range corresponding to these table-id

PD:(in merge checker)

  1. check the label after isTableIDSame(region, adjacent)
  2. delete or merge the corresponding label/placement-rule when needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.0 affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.2 affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

2 participants