Skip to content

Commit

Permalink
config: add split-region-max-num in config to control the maximum spl…
Browse files Browse the repository at this point in the history
…it region number (#11427) (#12079)
  • Loading branch information
crazycs520 authored and sre-bot committed Sep 9, 2019
1 parent 8938907 commit 2ebecd4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ type Config struct {
CheckMb4ValueInUTF8 bool `toml:"check-mb4-value-in-utf8" json:"check-mb4-value-in-utf8"`
// TreatOldVersionUTF8AsUTF8MB4 is use to treat old version table/column UTF8 charset as UTF8MB4. This is for compatibility.
// Currently not support dynamic modify, because this need to reload all old version schema.
TreatOldVersionUTF8AsUTF8MB4 bool `toml:"treat-old-version-utf8-as-utf8mb4" json:"treat-old-version-utf8-as-utf8mb4"`
TreatOldVersionUTF8AsUTF8MB4 bool `toml:"treat-old-version-utf8-as-utf8mb4" json:"treat-old-version-utf8-as-utf8mb4"`
SplitRegionMaxNum uint64 `toml:"split-region-max-num" json:"split-region-max-num"`
}

// Log is the log section of config.
Expand Down Expand Up @@ -321,6 +322,7 @@ var defaultConf = Config{
EnableStreaming: false,
CheckMb4ValueInUTF8: true,
TreatOldVersionUTF8AsUTF8MB4: true,
SplitRegionMaxNum: 1000,
TxnLocalLatches: TxnLocalLatches{
Enabled: true,
Capacity: 2048000,
Expand Down
3 changes: 3 additions & 0 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ check-mb4-value-in-utf8 = true
# treat-old-version-utf8-as-utf8mb4 use for upgrade compatibility. Set to true will treat old version table/column UTF8 charset as UTF8MB4.
treat-old-version-utf8-as-utf8mb4 = true

# Maximum number of the splitting region, which is used by the split region statement.
split-region-max-num = 1000

[log]
# Log level: debug, info, warn, error, fatal.
level = "info"
Expand Down
2 changes: 2 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ unrecognized-option-test = true

_, err = f.WriteString(`
token-limit = 0
split-region-max-num=10000
[performance]
[tikv-client]
commit-timeout="41s"
Expand All @@ -78,6 +79,7 @@ max-batch-size=128
c.Assert(conf.TiKVClient.CommitTimeout, Equals, "41s")
c.Assert(conf.TiKVClient.MaxBatchSize, Equals, uint(128))
c.Assert(conf.TokenLimit, Equals, uint(1000))
c.Assert(conf.SplitRegionMaxNum, Equals, uint64(10000))
c.Assert(f.Close(), IsNil)
c.Assert(os.Remove(configFile), IsNil)

Expand Down
5 changes: 3 additions & 2 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/opcode"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/expression"
"github.com/pingcap/tidb/infoschema"
Expand Down Expand Up @@ -1774,8 +1775,6 @@ func (b *PlanBuilder) buildLoadStats(ld *ast.LoadStatsStmt) Plan {
return p
}

const maxSplitRegionNum = 1000

func (b *PlanBuilder) buildSplitRegion(node *ast.SplitRegionStmt) (Plan, error) {
if len(node.IndexName.L) != 0 {
return b.buildSplitIndexRegion(node)
Expand Down Expand Up @@ -1836,6 +1835,7 @@ func (b *PlanBuilder) buildSplitIndexRegion(node *ast.SplitRegionStmt) (Plan, er
p.Lower = lowerValues
p.Upper = upperValues

maxSplitRegionNum := int64(config.GetGlobalConfig().SplitRegionMaxNum)
if node.SplitOpt.Num > maxSplitRegionNum {
return nil, errors.Errorf("Split index region num exceeded the limit %v", maxSplitRegionNum)
} else if node.SplitOpt.Num < 1 {
Expand Down Expand Up @@ -1946,6 +1946,7 @@ func (b *PlanBuilder) buildSplitTableRegion(node *ast.SplitRegionStmt) (Plan, er
p.Lower = []types.Datum{lowerValues}
p.Upper = []types.Datum{upperValue}

maxSplitRegionNum := int64(config.GetGlobalConfig().SplitRegionMaxNum)
if node.SplitOpt.Num > maxSplitRegionNum {
return nil, errors.Errorf("Split table region num exceeded the limit %v", maxSplitRegionNum)
} else if node.SplitOpt.Num < 1 {
Expand Down

0 comments on commit 2ebecd4

Please sign in to comment.