diff --git a/domain/sysvar_cache.go b/domain/sysvar_cache.go index cc77855f2f9a0..9b60f4090e9a4 100644 --- a/domain/sysvar_cache.go +++ b/domain/sysvar_cache.go @@ -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)) diff --git a/executor/set_test.go b/executor/set_test.go index 49dd321f074f0..d26e872fd22a3 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -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") diff --git a/go.mod b/go.mod index e3c62e83978e5..b44762a2e571b 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 21958902d31d5..8106de35c6732 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 3c5cf5f59d84b..25ac52238960f 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -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 { diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 83f0e5299dbf2..e70322be246ca 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -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"