Skip to content
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

txn: respect txn-total-size-limit if it is manually set #39550

Merged
merged 9 commits into from
Dec 1, 2022
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ const (
// DefTxnEntrySizeLimit is the default value of TxnEntrySizeLimit.
DefTxnEntrySizeLimit = 6 * 1024 * 1024
// DefTxnTotalSizeLimit is the default value of TxnTxnTotalSizeLimit.
DefTxnTotalSizeLimit = 100 * 1024 * 1024
DefTxnTotalSizeLimit = 100 * 1024 * 1024
SuperLargeTxnSize uint64 = 100 * 1024 * 1024 * 1024 * 1024 // 100T, we expect a txn can never be this large
// DefMaxIndexLength is the maximum index length(in bytes). This value is consistent with MySQL.
DefMaxIndexLength = 3072
// DefMaxOfMaxIndexLength is the maximum index length(in bytes) for TiDB v3.0.7 and previous version.
Expand Down
5 changes: 5 additions & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3684,6 +3684,11 @@ func (s *session) GetStmtStats() *stmtstats.StatementStats {
// SetMemoryFootprintChangeHook sets the hook that is called when the memdb changes its size.
// Call this after s.txn becomes valid, since TxnInfo is initialized when the txn becomes valid.
func (s *session) SetMemoryFootprintChangeHook() {
if config.GetGlobalConfig().Performance.TxnTotalSizeLimit != config.DefTxnTotalSizeLimit {
// if the user manually specifies the config, don't involve the new memory tracker mechanism, let the old config
// work as before.
return
}
hook := func(mem uint64) {
if s.sessionVars.MemDBFootprint == nil {
tracker := memory.NewTracker(memory.LabelForMemDB, -1)
Expand Down
7 changes: 6 additions & 1 deletion tidb-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,12 @@ func setGlobalVars() {
}
plannercore.AllowCartesianProduct.Store(cfg.Performance.CrossJoin)
privileges.SkipWithGrant = cfg.Security.SkipGrantTable
kv.TxnTotalSizeLimit = cfg.Performance.TxnTotalSizeLimit
if cfg.Performance.TxnTotalSizeLimit == config.DefTxnTotalSizeLimit {
// practically deprecate the config, let the new session memory tracker take charge of it.
kv.TxnTotalSizeLimit = config.SuperLargeTxnSize
} else {
kv.TxnTotalSizeLimit = cfg.Performance.TxnTotalSizeLimit
}
if cfg.Performance.TxnEntrySizeLimit > 120*1024*1024 {
log.Fatal("cannot set txn entry size limit larger than 120M")
}
Expand Down