Skip to content

Commit

Permalink
*: make txnCommitBatchSize adjustable by SQL (#33507)
Browse files Browse the repository at this point in the history
close #33508
  • Loading branch information
jackysp authored Mar 30, 2022
1 parent 191a2dc commit d4ec947
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions domain/sysvar_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ func (do *Domain) checkEnableServerGlobalVar(name, sVal string) {
variable.StatsLoadSyncWait.Store(val)
case variable.TiDBStatsLoadPseudoTimeout:
variable.StatsLoadPseudoTimeout.Store(variable.TiDBOptOn(sVal))
case variable.TiDBTxnCommitBatchSize:
storekv.TxnCommitBatchSize.Store(uint64(variable.TidbOptInt64(sVal, int64(storekv.DefTxnCommitBatchSize))))
}
if err != nil {
logutil.BgLogger().Error(fmt.Sprintf("load global variable %s error", name), zap.Error(err))
Expand Down
8 changes: 8 additions & 0 deletions executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ func TestSetVar(t *testing.T) {
tk.MustExec("set global tidb_store_limit = 100")
tk.MustQuery("select @@global.tidb_store_limit;").Check(testkit.Rows("100"))

tk.MustQuery("select @@global.tidb_txn_commit_batch_size;").Check(testkit.Rows("16384"))
tk.MustExec("set @@global.tidb_txn_commit_batch_size = 100")
tk.MustQuery("select @@global.tidb_txn_commit_batch_size;").Check(testkit.Rows("100"))
tk.MustExec("set @@global.tidb_txn_commit_batch_size = 0")
tk.MustQuery("select @@global.tidb_txn_commit_batch_size;").Check(testkit.Rows("1"))
tk.MustExec("set global tidb_txn_commit_batch_size = 100")
tk.MustQuery("select @@global.tidb_txn_commit_batch_size;").Check(testkit.Rows("100"))

tk.MustQuery("select @@session.tidb_metric_query_step;").Check(testkit.Rows("60"))
tk.MustExec("set @@session.tidb_metric_query_step = 120")
tk.MustExec("set @@session.tidb_metric_query_step = 9")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2
github.com/tikv/client-go/v2 v2.0.1-0.20220328083738-8489c3e8c3d9
github.com/tikv/client-go/v2 v2.0.1-0.20220329092050-6bf6951325ad
github.com/tikv/pd/client v0.0.0-20220307081149-841fa61e9710
github.com/twmb/murmur3 v1.1.3
github.com/uber/jaeger-client-go v2.22.1+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJfDRtkanvQPiooDH8HvJ2FBh+iKT/OmiQQ=
github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU=
github.com/tikv/client-go/v2 v2.0.1-0.20220328083738-8489c3e8c3d9 h1:TgSywPECh84B5S6Z97jhMdQVrezPwUbOKbCZFie2kPI=
github.com/tikv/client-go/v2 v2.0.1-0.20220328083738-8489c3e8c3d9/go.mod h1:0scaG+seu7L56apm+Gjz9vckyO7ABIzM6T7n00mrIXs=
github.com/tikv/client-go/v2 v2.0.1-0.20220329092050-6bf6951325ad h1:Imm87gW7/Pra/NdUc7D3wkdtlZgo/iw0lSLIWZPiMS0=
github.com/tikv/client-go/v2 v2.0.1-0.20220329092050-6bf6951325ad/go.mod h1:0scaG+seu7L56apm+Gjz9vckyO7ABIzM6T7n00mrIXs=
github.com/tikv/pd/client v0.0.0-20220307081149-841fa61e9710 h1:jxgmKOscXSjaFEKQGRyY5qOpK8hLqxs2irb/uDJMtwk=
github.com/tikv/pd/client v0.0.0-20220307081149-841fa61e9710/go.mod h1:AtvppPwkiyUgQlR1W9qSqfTB+OsOIu19jDCOxOsPkmU=
github.com/tklauser/go-sysconf v0.3.9 h1:JeUVdAOWhhxVcU6Eqr/ATFHgXk/mmiItdKeJPev3vTo=
Expand Down
8 changes: 8 additions & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,14 @@ var defaultSysVars = []*SysVar{
tikvstore.StoreLimit.Store(TidbOptInt64(val, DefTiDBStoreLimit))
return nil
}},
{Scope: ScopeGlobal, Name: TiDBTxnCommitBatchSize, Value: strconv.FormatUint(tikvstore.DefTxnCommitBatchSize, 10), Type: TypeUnsigned, MinValue: 1, MaxValue: 1 << 30,
GetGlobal: func(sv *SessionVars) (string, error) {
return strconv.FormatUint(tikvstore.TxnCommitBatchSize.Load(), 10), nil
},
SetGlobal: func(s *SessionVars, val string) error {
tikvstore.TxnCommitBatchSize.Store(uint64(TidbOptInt64(val, int64(tikvstore.DefTxnCommitBatchSize))))
return nil
}},
{Scope: ScopeGlobal, Name: TiDBRestrictedReadOnly, Value: BoolToOnOff(DefTiDBRestrictedReadOnly), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error {
on := TiDBOptOn(val)
if on {
Expand Down
7 changes: 7 additions & 0 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,15 @@ const (

// TiDBEnableLocalTxn indicates whether to enable Local Txn.
TiDBEnableLocalTxn = "tidb_enable_local_txn"

// TiDBTSOClientBatchMaxWaitTime indicates the max value of the TSO Batch Wait interval time of PD client.
TiDBTSOClientBatchMaxWaitTime = "tidb_tso_client_batch_max_wait_time"

// TiDBTxnCommitBatchSize is used to control the batch size of transaction commit related requests sent by TiDB to TiKV.
// If a single transaction has a large amount of writes, you can increase the batch size to improve the batch effect,
// setting too large will exceed TiKV's raft-entry-max-size limit and cause commit failure.
TiDBTxnCommitBatchSize = "tidb_txn_commit_batch_size"

// TiDBEnableTSOFollowerProxy indicates whether to enable the TSO Follower Proxy feature of PD client.
TiDBEnableTSOFollowerProxy = "tidb_enable_tso_follower_proxy"

Expand Down

0 comments on commit d4ec947

Please sign in to comment.