-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
ddl: scatter the regions of table when creating them #10980
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10980 +/- ##
================================================
- Coverage 81.1735% 81.0344% -0.1391%
================================================
Files 421 422 +1
Lines 89916 89689 -227
================================================
- Hits 72988 72679 -309
- Misses 11687 11749 +62
- Partials 5241 5261 +20 |
3f48412
to
8f75385
Compare
/run-integration-common-test |
/run-all-tests |
/run-integration-common-test tidb-test=pr/844 |
For 100 tables, waiting to scatter finish costs 24 min, and no waiting cost 6 min. Try to make the default value of |
Change $ mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.16 Homebrew
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> load data local infile "~/tmp.csv" into table t;
Query OK, 1 row affected (0.07 sec)
Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
mysql> set global local_infile=0;
Query OK, 0 rows affected (0.00 sec)
mysql> load data local infile "~/tmp.csv" into table t;
ERROR 1148 (42000): The used command is not allowed with this MySQL version
-- set local_infile to on in another session.
mysql> load data local infile "~/tmp.csv" into table t;
Query OK, 1 row affected (0.05 sec)
Records: 1 Deleted: 0 Skipped: 0 Warnings: 0
|
/run-all-tests |
store/tikv/split_region.go
Outdated
} | ||
|
||
func (s *tikvStore) splitRegion(splitKey kv.Key) (*metapb.Region, error) { | ||
func (s *tikvStore) SplitRegion(splitKey kv.Key, scatter bool) (uint64, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need comment for the returned uint64
value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think SplitRegion
is better just used for splitting region, scatter region is another action. Use a boolean to indicate different actions is not clean code. Keep SplitRegionAndScatter
is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SplitRegionAndScatter
is even bad. I think it’s worse to combine the names of the actions together as the function name. And we also need an interface named SplitRegion
. The best way is to add a standalone interface for scattering, but now we have at least one interface saved, and split and scatter are really strongly related. If we need to use scatter separately in the future, I think we can separate them again.
sessionctx/variable/sysvar.go
Outdated
@@ -697,7 +697,7 @@ var defaultSysVars = []*SysVar{ | |||
{ScopeGlobal | ScopeSession, TiDBOptJoinReorderThreshold, strconv.Itoa(DefTiDBOptJoinReorderThreshold)}, | |||
{ScopeSession, TiDBCheckMb4ValueInUTF8, BoolToIntStr(config.GetGlobalConfig().CheckMb4ValueInUTF8)}, | |||
{ScopeSession, TiDBSlowQueryFile, ""}, | |||
{ScopeSession, TiDBWaitSplitRegionFinish, BoolToIntStr(DefTiDBWaitSplitRegionFinish)}, | |||
{ScopeGlobal, TiDBWaitSplitRegionFinish, BoolToIntStr(DefTiDBWaitSplitRegionFinish)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change to Global
scope?
/run-all-tests |
PTAL @crazycs520 @winkyao @coocood |
LGTM |
} else { | ||
regionIDs = append(regionIDs, splitRecordRegion(store, tbInfo.ID, scatter)) | ||
} | ||
regionIDs = append(regionIDs, splitIndexRegion(store, tbInfo, scatter)...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split index region for a common table, Is it expected?
It used to only split a table region for a common table, doesn't split the index regions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
emm... Yes, it is expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@winkyao PTAL |
PTAL @winkyao |
Signed-off-by: Shuaipeng Yu <jackysp@gmail.com>
ddl/ddl_api.go
Outdated
} | ||
} else if atomic.LoadUint32(&EnableSplitTableRegion) != 0 { | ||
scatterRegion := variable.TiDBOptOn(val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the variable.GetGlobalSystemVar
return err, scatterRegion should be false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rest LGTM
Signed-off-by: Shuaipeng Yu <jackysp@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
@jackysp Please cherry-pick this PR to v3.0 and v2.1. |
Conflicts: ddl/ddl_api.go ddl/table.go sessionctx/variable/tidb_vars.go sessionctx/variable/varsutil.go store/tikv/split_region.go
Conflicts: ddl/ddl_api.go ddl/table.go sessionctx/variable/tidb_vars.go sessionctx/variable/varsutil.go store/tikv/split_region.go
Signed-off-by: Shuaipeng Yu jackysp@gmail.com
What problem does this PR solve?
It’s a bit late to schedule the region when PD found the hotspot. It is better to scatter them when they are empty.
What is changed and how it works?
Scatter the regions of the tables when creating them.
Check List
Tests
Created 100 tables and compare the regions distribution.
master:
This PR:
Code changes
Side effects