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) (#12080)
  • Loading branch information
crazycs520 authored and ngaut committed Sep 9, 2019
1 parent 73b1b78 commit f396ce1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type Config struct {
// 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"`
Plugin Plugin `toml:"plugin" json:"plugin"`
SplitRegionMaxNum uint64 `toml:"split-region-max-num" json:"split-region-max-num"`
}

// Log is the log section of config.
Expand Down Expand Up @@ -301,6 +302,7 @@ var defaultConf = Config{
EnableBatchDML: false,
CheckMb4ValueInUTF8: true,
TreatOldVersionUTF8AsUTF8MB4: true,
SplitRegionMaxNum: 1000,
TxnLocalLatches: TxnLocalLatches{
Enabled: false,
Capacity: 10240000,
Expand Down
3 changes: 3 additions & 0 deletions config/config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,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 @@ -61,6 +61,7 @@ unrecognized-option-test = true

_, err = f.WriteString(`
token-limit = 0
split-region-max-num=10000
[performance]
txn-entry-count-limit=2000
txn-total-size-limit=2000
Expand All @@ -82,6 +83,7 @@ commit-timeout="41s"
c.Assert(conf.Performance.TxnTotalSizeLimit, Equals, uint64(2000))

c.Assert(conf.TiKVClient.CommitTimeout, Equals, "41s")
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 @@ -26,6 +26,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 @@ -1596,8 +1597,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 @@ -1658,6 +1657,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 @@ -1768,6 +1768,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 f396ce1

Please sign in to comment.