From b3595726f8923ffd11aae2907ea7c4141abc1471 Mon Sep 17 00:00:00 2001 From: cbcwestwolf <1004626265@qq.com> Date: Thu, 28 Jul 2022 20:57:03 +0800 Subject: [PATCH 1/4] *: move config file option oom-use-tmp-storage to sysvar --- config/config.go | 7 +++++-- config/config.toml.example | 7 ++----- config/config_test.go | 5 +---- executor/aggregate.go | 4 ++-- executor/cte.go | 6 +++--- executor/cte_test.go | 8 ++------ executor/executor.go | 2 +- executor/executor_pkg_test.go | 5 ----- executor/join.go | 4 ++-- executor/join_test.go | 7 ------- executor/merge_join.go | 4 ++-- executor/merge_join_test.go | 6 ------ executor/sort.go | 4 ++-- executor/sort_test.go | 2 -- planner/core/plan_cost.go | 6 +++--- session/bootstrap.go | 13 ++++++++++++- sessionctx/variable/sysvar.go | 6 ++++++ sessionctx/variable/tidb_vars.go | 7 ++++++- tidb-server/main.go | 4 ++-- util/chunk/disk_test.go | 2 +- util/chunk/main_test.go | 2 +- 21 files changed, 53 insertions(+), 58 deletions(-) diff --git a/config/config.go b/config/config.go index 193beee961f63..cf37b8248dd18 100644 --- a/config/config.go +++ b/config/config.go @@ -169,9 +169,8 @@ type Config struct { RunDDL bool `toml:"run-ddl" json:"run-ddl"` SplitTable bool `toml:"split-table" json:"split-table"` TokenLimit uint `toml:"token-limit" json:"token-limit"` - OOMUseTmpStorage bool `toml:"oom-use-tmp-storage" json:"oom-use-tmp-storage"` TempStoragePath string `toml:"tmp-storage-path" json:"tmp-storage-path"` - // TempStorageQuota describe the temporary storage Quota during query exector when OOMUseTmpStorage is enabled + // TempStorageQuota describe the temporary storage Quota during query exector when TiDBEnableTmpStorageOnOOM is enabled // If the quota exceed the capacity of the TempStoragePath, the tidb-server would exit with fatal error TempStorageQuota int64 `toml:"tmp-storage-quota" json:"tmp-storage-quota"` // Bytes TxnLocalLatches tikvcfg.TxnLocalLatches `toml:"-" json:"-"` @@ -268,6 +267,9 @@ type Config struct { MemQuotaQuery int64 `toml:"mem-quota-query" json:"mem-quota-query"` OOMAction string `toml:"oom-action" json:"oom-action"` + // OOMUseTmpStorage unused since bootstrap v91 + OOMUseTmpStorage bool `toml:"oom-use-tmp-storage" json:"oom-use-tmp-storage"` + // CheckMb4ValueInUTF8, EnableCollectExecutionInfo, Plugin are deprecated. CheckMb4ValueInUTF8 AtomicBool `toml:"check-mb4-value-in-utf8" json:"check-mb4-value-in-utf8"` EnableCollectExecutionInfo bool `toml:"enable-collect-execution-info" json:"enable-collect-execution-info"` @@ -1026,6 +1028,7 @@ var removedConfig = map[string]struct{}{ "plugin.dir": {}, // use plugin_dir "performance.feedback-probability": {}, // This feature is deprecated "performance.query-feedback-limit": {}, + "oom-use-tmp-storage": {}, // use tidb_enable_tmp_storage_on_oom } // isAllRemovedConfigItems returns true if all the items that couldn't validate diff --git a/config/config.toml.example b/config/config.toml.example index e30ebdb3c4b37..d08d154159cce 100644 --- a/config/config.toml.example +++ b/config/config.toml.example @@ -31,15 +31,12 @@ split-table = true # The limit of concurrent executed sessions. token-limit = 1000 -# Controls whether to enable the temporary storage for some operators when a single SQL statement exceeds the memory quota specified by the memory quota. -oom-use-tmp-storage = true - # Specifies the temporary storage path for some operators when a single SQL statement exceeds the memory quota specified by the memory quota. # It defaults to a generated directory in `/_tidb/` if it is unset. -# It only takes effect when `oom-use-tmp-storage` is `true`. +# It only takes effect when `tidb_enable_tmp_storage_on_oom` is `true`. # tmp-storage-path = "/tmp/_tidb/MC4wLjAuMDo0MDAwLzAuMC4wLjA6MTAwODA=/tmp-storage" -# Specifies the maximum use of temporary storage (bytes) for all active queries when `oom-use-tmp-storage` is enabled. +# Specifies the maximum use of temporary storage (bytes) for all active queries when `tidb_enable_tmp_storage_on_oom` is enabled. # If the `tmp-storage-quota` exceeds the capacity of the temporary storage directory, tidb-server would return an error and exit. # The default value of tmp-storage-quota is under 0 which means tidb-server wouldn't check the capacity. tmp-storage-quota = -1 diff --git a/config/config_test.go b/config/config_test.go index 27d2ebbec2111..9657da30de2f0 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -212,14 +212,11 @@ token-limit = 1000 # The maximum memory available for a single SQL statement. Default: 1GB mem-quota-query = 1073741824 -# Controls whether to enable the temporary storage for some operators when a single SQL statement exceeds the memory quota specified by mem-quota-query. -oom-use-tmp-storage = true - # Specifies the temporary storage path for some operators when a single SQL statement exceeds the memory quota specified by mem-quota-query. # # tmp-storage-path = "/tmp/_tidb/MC4wLjAuMDo0MDAwLzAuMC4wLjA6MTAwODA=/tmp-storage" -# Specifies the maximum use of temporary storage (bytes) for all active queries when oom-use-tmp-storage is enabled. +# Specifies the maximum use of temporary storage (bytes) for all active queries when tidb_enable_tmp_storage_on_oom is enabled. # If the tmp-storage-quota exceeds the capacity of the temporary storage directory, tidb-server would return an error and exit. # The default value of tmp-storage-quota is under 0 which means tidb-server wouldn't check the capacity. tmp-storage-quota = -1 diff --git a/executor/aggregate.go b/executor/aggregate.go index 9d37966fd499c..74a8205148061 100644 --- a/executor/aggregate.go +++ b/executor/aggregate.go @@ -24,13 +24,13 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/failpoint" - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/executor/aggfuncs" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/parser/terror" "github.com/pingcap/tidb/sessionctx" "github.com/pingcap/tidb/sessionctx/stmtctx" + "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/types/json" "github.com/pingcap/tidb/util/chunk" @@ -334,7 +334,7 @@ func (e *HashAggExec) initForUnparallelExec() { e.executed, e.isChildDrained = false, false e.listInDisk = chunk.NewListInDisk(retTypes(e.children[0])) e.tmpChkForSpill = newFirstChunk(e.children[0]) - if e.ctx.GetSessionVars().TrackAggregateMemoryUsage && config.GetGlobalConfig().OOMUseTmpStorage { + if e.ctx.GetSessionVars().TrackAggregateMemoryUsage && variable.EnableTmpStorageOnOOM.Load() { e.diskTracker = disk.NewTracker(e.id, -1) e.diskTracker.AttachTo(e.ctx.GetSessionVars().StmtCtx.DiskTracker) e.listInDisk.GetDiskTracker().AttachTo(e.diskTracker) diff --git a/executor/cte.go b/executor/cte.go index abce5fb7a4c3f..3e1d1db069315 100644 --- a/executor/cte.go +++ b/executor/cte.go @@ -19,8 +19,8 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/failpoint" - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/sessionctx" + "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/codec" "github.com/pingcap/tidb/util/cteutil" @@ -160,7 +160,7 @@ func (e *CTEExec) Next(ctx context.Context, req *chunk.Chunk) (err error) { } failpoint.Inject("testCTEStorageSpill", func(val failpoint.Value) { - if val.(bool) && config.GetGlobalConfig().OOMUseTmpStorage { + if val.(bool) && variable.EnableTmpStorageOnOOM.Load() { defer resAction.WaitForTest() defer iterInAction.WaitForTest() if iterOutAction != nil { @@ -429,7 +429,7 @@ func setupCTEStorageTracker(tbl cteutil.Storage, ctx sessionctx.Context, parentM diskTracker.SetLabel(memory.LabelForCTEStorage) diskTracker.AttachTo(parentDiskTracker) - if config.GetGlobalConfig().OOMUseTmpStorage { + if variable.EnableTmpStorageOnOOM.Load() { actionSpill = tbl.ActionSpill() failpoint.Inject("testCTEStorageSpill", func(val failpoint.Value) { if val.(bool) { diff --git a/executor/cte_test.go b/executor/cte_test.go index 50db46e4bc17f..fe0e1b028cfd3 100644 --- a/executor/cte_test.go +++ b/executor/cte_test.go @@ -20,7 +20,6 @@ import ( "testing" "github.com/pingcap/failpoint" - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/parser/terror" "github.com/pingcap/tidb/testkit" "github.com/pingcap/tidb/types" @@ -354,15 +353,12 @@ func TestCTEWithLimit(t *testing.T) { } func TestSpillToDisk(t *testing.T) { - defer config.RestoreFunc()() - config.UpdateGlobal(func(conf *config.Config) { - conf.OOMUseTmpStorage = true - }) - store, clean := testkit.CreateMockStore(t) defer clean() tk := testkit.NewTestKit(t, store) + tk.MustExec("SET GLOBAL tidb_enable_tmp_storage_on_oom = 1") + defer tk.MustExec("SET GLOBAL tidb_enable_tmp_storage_on_oom = 0") tk.MustExec("use test;") require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/executor/testCTEStorageSpill", "return(true)")) diff --git a/executor/executor.go b/executor/executor.go index c122a4c2f4a2e..c832a59fb588f 100644 --- a/executor/executor.go +++ b/executor/executor.go @@ -1932,7 +1932,7 @@ func ResetContextOfStmt(ctx sessionctx.Context, s ast.StmtNode) (err error) { sc.InitDiskTracker(memory.LabelForSQLText, -1) globalConfig := config.GetGlobalConfig() - if globalConfig.OOMUseTmpStorage && GlobalDiskUsageTracker != nil { + if variable.EnableTmpStorageOnOOM.Load() && GlobalDiskUsageTracker != nil { sc.DiskTracker.AttachToGlobalTracker(GlobalDiskUsageTracker) } switch variable.OOMAction.Load() { diff --git a/executor/executor_pkg_test.go b/executor/executor_pkg_test.go index 7e26a1f0fa603..858c079d2f79c 100644 --- a/executor/executor_pkg_test.go +++ b/executor/executor_pkg_test.go @@ -24,7 +24,6 @@ import ( "unsafe" "github.com/pingcap/failpoint" - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/executor/aggfuncs" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" @@ -437,10 +436,6 @@ func TestLoadDataWithDifferentEscapeChar(t *testing.T) { } func TestSortSpillDisk(t *testing.T) { - defer config.RestoreFunc()() - config.UpdateGlobal(func(conf *config.Config) { - conf.OOMUseTmpStorage = true - }) require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/executor/testSortedRowContainerSpill", "return(true)")) defer func() { require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/executor/testSortedRowContainerSpill")) diff --git a/executor/join.go b/executor/join.go index b2076d459d82c..becb00c519d4c 100644 --- a/executor/join.go +++ b/executor/join.go @@ -26,11 +26,11 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/failpoint" - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/parser/terror" plannercore "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/sessionctx" + "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util" "github.com/pingcap/tidb/util/bitmap" @@ -779,7 +779,7 @@ func (e *HashJoinExec) buildHashTableForList(buildSideResultCh <-chan *chunk.Chu e.rowContainer.GetMemTracker().SetLabel(memory.LabelForBuildSideResult) e.rowContainer.GetDiskTracker().AttachTo(e.diskTracker) e.rowContainer.GetDiskTracker().SetLabel(memory.LabelForBuildSideResult) - if config.GetGlobalConfig().OOMUseTmpStorage { + if variable.EnableTmpStorageOnOOM.Load() { actionSpill := e.rowContainer.ActionSpill() failpoint.Inject("testRowContainerSpill", func(val failpoint.Value) { if val.(bool) { diff --git a/executor/join_test.go b/executor/join_test.go index 3b86c21636979..f96ec1c1ac5e5 100644 --- a/executor/join_test.go +++ b/executor/join_test.go @@ -23,7 +23,6 @@ import ( "time" "github.com/pingcap/failpoint" - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/executor" plannercore "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/session" @@ -57,12 +56,6 @@ func TestJoinPanic2(t *testing.T) { } func TestJoinInDisk(t *testing.T) { - origin := config.RestoreFunc() - defer origin() - config.UpdateGlobal(func(conf *config.Config) { - conf.OOMUseTmpStorage = true - }) - store, dom, clean := testkit.CreateMockStoreAndDomain(t) defer clean() tk := testkit.NewTestKit(t, store) diff --git a/executor/merge_join.go b/executor/merge_join.go index 7ba07335af865..cb2a495f09765 100644 --- a/executor/merge_join.go +++ b/executor/merge_join.go @@ -18,9 +18,9 @@ import ( "context" "github.com/pingcap/failpoint" - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/sessionctx/stmtctx" + "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/disk" "github.com/pingcap/tidb/util/memory" @@ -93,7 +93,7 @@ func (t *mergeJoinTable) init(exec *MergeJoinExec) { t.rowContainer.GetMemTracker().SetLabel(memory.LabelForInnerTable) t.rowContainer.GetDiskTracker().AttachTo(exec.diskTracker) t.rowContainer.GetDiskTracker().SetLabel(memory.LabelForInnerTable) - if config.GetGlobalConfig().OOMUseTmpStorage { + if variable.EnableTmpStorageOnOOM.Load() { actionSpill := t.rowContainer.ActionSpill() failpoint.Inject("testMergeJoinRowContainerSpill", func(val failpoint.Value) { if val.(bool) { diff --git a/executor/merge_join_test.go b/executor/merge_join_test.go index 2a46243c6e6cc..3a40c42078c87 100644 --- a/executor/merge_join_test.go +++ b/executor/merge_join_test.go @@ -239,11 +239,6 @@ func checkPlanAndRun(tk *testkit.TestKit, t *testing.T, plan string, sql string) } func TestShuffleMergeJoinInDisk(t *testing.T) { - defer config.RestoreFunc()() - config.UpdateGlobal(func(conf *config.Config) { - conf.OOMUseTmpStorage = true - }) - require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/executor/testMergeJoinRowContainerSpill", "return(true)")) defer func() { require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/executor/testMergeJoinRowContainerSpill")) @@ -281,7 +276,6 @@ func TestMergeJoinInDisk(t *testing.T) { restore := config.RestoreFunc() defer restore() config.UpdateGlobal(func(conf *config.Config) { - conf.OOMUseTmpStorage = true conf.TempStoragePath = t.TempDir() }) diff --git a/executor/sort.go b/executor/sort.go index 49215a4d5cb0c..d89c1a71f0a92 100644 --- a/executor/sort.go +++ b/executor/sort.go @@ -20,10 +20,10 @@ import ( "errors" "github.com/pingcap/failpoint" - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/expression" plannercore "github.com/pingcap/tidb/planner/core" "github.com/pingcap/tidb/planner/util" + "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/util/chunk" "github.com/pingcap/tidb/util/disk" "github.com/pingcap/tidb/util/mathutil" @@ -181,7 +181,7 @@ func (e *SortExec) fetchRowChunks(ctx context.Context) error { e.rowChunks = chunk.NewSortedRowContainer(fields, e.maxChunkSize, byItemsDesc, e.keyColumns, e.keyCmpFuncs) e.rowChunks.GetMemTracker().AttachTo(e.memTracker) e.rowChunks.GetMemTracker().SetLabel(memory.LabelForRowChunks) - if config.GetGlobalConfig().OOMUseTmpStorage { + if variable.EnableTmpStorageOnOOM.Load() { e.spillAction = e.rowChunks.ActionSpill() failpoint.Inject("testSortedRowContainerSpill", func(val failpoint.Value) { if val.(bool) { diff --git a/executor/sort_test.go b/executor/sort_test.go index 4951f2025399b..be07d6570a778 100644 --- a/executor/sort_test.go +++ b/executor/sort_test.go @@ -38,7 +38,6 @@ func testSortInDisk(t *testing.T, removeDir bool) { restore := config.RestoreFunc() defer restore() config.UpdateGlobal(func(conf *config.Config) { - conf.OOMUseTmpStorage = true conf.TempStoragePath = t.TempDir() }) require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/executor/testSortedRowContainerSpill", "return(true)")) @@ -98,7 +97,6 @@ func testSortInDisk(t *testing.T, removeDir bool) { func TestIssue16696(t *testing.T) { defer config.RestoreFunc()() config.UpdateGlobal(func(conf *config.Config) { - conf.OOMUseTmpStorage = true conf.TempStoragePath = t.TempDir() }) alarmRatio := variable.MemoryUsageAlarmRatio.Load() diff --git a/planner/core/plan_cost.go b/planner/core/plan_cost.go index a47682d049e1c..64f9590484fc4 100644 --- a/planner/core/plan_cost.go +++ b/planner/core/plan_cost.go @@ -18,11 +18,11 @@ import ( "math" "github.com/pingcap/errors" - "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/expression" "github.com/pingcap/tidb/kv" "github.com/pingcap/tidb/parser/model" "github.com/pingcap/tidb/planner/property" + "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/statistics" "github.com/pingcap/tidb/util/paging" ) @@ -877,7 +877,7 @@ func (p *PhysicalHashJoin) GetCost(lCnt, rCnt float64, isMPP bool, costFlag uint build = p.children[1] } sessVars := p.ctx.GetSessionVars() - oomUseTmpStorage := config.GetGlobalConfig().OOMUseTmpStorage + oomUseTmpStorage := variable.EnableTmpStorageOnOOM.Load() memQuota := sessVars.StmtCtx.MemTracker.GetBytesLimit() // sessVars.MemQuotaQuery && hint rowSize := getAvgRowSize(build.statsInfo(), build.Schema()) spill := oomUseTmpStorage && memQuota > 0 && rowSize*buildCnt > float64(memQuota) && p.storeTp != kv.TiFlash @@ -1074,7 +1074,7 @@ func (p *PhysicalSort) GetCost(count float64, schema *expression.Schema) float64 cpuCost := count * math.Log2(count) * sessVars.GetCPUFactor() memoryCost := count * sessVars.GetMemoryFactor() - oomUseTmpStorage := config.GetGlobalConfig().OOMUseTmpStorage + oomUseTmpStorage := variable.EnableTmpStorageOnOOM.Load() memQuota := sessVars.StmtCtx.MemTracker.GetBytesLimit() // sessVars.MemQuotaQuery && hint rowSize := getAvgRowSize(p.statsInfo(), schema) spill := oomUseTmpStorage && memQuota > 0 && rowSize*count > float64(memQuota) diff --git a/session/bootstrap.go b/session/bootstrap.go index 918103c66932b..4d3eb49c8d313 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -622,11 +622,13 @@ const ( version91 = 91 // version92 for concurrent ddl. version92 = 92 + // version93 converts oom-use-tmp-storage to a sysvar + version93 = 93 ) // currentBootstrapVersion is defined as a variable, so we can modify its value for testing. // please make sure this is the largest version -var currentBootstrapVersion int64 = version92 +var currentBootstrapVersion int64 = version93 var ( bootstrapVersion = []func(Session, int64){ @@ -721,6 +723,7 @@ var ( upgradeToVer89, upgradeToVer90, upgradeToVer91, + upgradeToVer93, } ) @@ -1899,6 +1902,14 @@ func upgradeToVer91(s Session, ver int64) { importConfigOption(s, "prepared-plan-cache.memory-guard-ratio", variable.TiDBPrepPlanCacheMemoryGuardRatio, valStr) } +func upgradeToVer93(s Session, ver int64) { + if ver >= version93 { + return + } + valStr := variable.BoolToOnOff(config.GetGlobalConfig().OOMUseTmpStorage) + importConfigOption(s, "oom-use-tmp-storage", variable.TiDBEnableTmpStorageOnOOM, valStr) +} + func writeOOMAction(s Session) { comment := "oom-action is `log` by default in v3.0.x, `cancel` by default in v4.0.11+" mustExecute(s, `INSERT HIGH_PRIORITY INTO %n.%n VALUES (%?, %?, %?) ON DUPLICATE KEY UPDATE VARIABLE_VALUE= %?`, diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index d243379978d42..b04ed2979ef73 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -839,6 +839,12 @@ var defaultSysVars = []*SysVar{ }, GetGlobal: func(s *SessionVars) (string, error) { return BoolToOnOff(memory.EnableGCAwareMemoryTrack.Load()), nil }}, + {Scope: ScopeGlobal, Name: TiDBEnableTmpStorageOnOOM, Value: BoolToOnOff(DefTiDBEnableTmpStorageOnOOM), Type: TypeBool, SetGlobal: func(s *SessionVars, val string) error { + EnableTmpStorageOnOOM.Store(TiDBOptOn(val)) + return nil + }, GetGlobal: func(s *SessionVars) (string, error) { + return BoolToOnOff(EnableTmpStorageOnOOM.Load()), nil + }}, /* The system variables below have GLOBAL and SESSION scope */ {Scope: ScopeGlobal | ScopeSession, Name: SQLSelectLimit, Value: "18446744073709551615", Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxUint64, SetSession: func(s *SessionVars, val string) error { diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index aab049f4e7afb..67e2716261300 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -762,7 +762,7 @@ const ( TiDBMemQuotaAnalyze = "tidb_mem_quota_analyze" // TiDBEnableAutoAnalyze determines whether TiDB executes automatic analysis. TiDBEnableAutoAnalyze = "tidb_enable_auto_analyze" - //TiDBMemOOMAction indicates what operation TiDB perform when a single SQL statement exceeds + // TiDBMemOOMAction indicates what operation TiDB perform when a single SQL statement exceeds // the memory quota specified by tidb_mem_quota_query and cannot be spilled to disk. TiDBMemOOMAction = "tidb_mem_oom_action" // TiDBEnablePrepPlanCache indicates whether to enable prepared plan cache @@ -784,6 +784,9 @@ const ( TiDBGenerateBinaryPlan = "tidb_generate_binary_plan" // TiDBEnableGCAwareMemoryTrack indicates whether to turn-on GC-aware memory track. TiDBEnableGCAwareMemoryTrack = "tidb_enable_gc_aware_memory_track" + // TiDBEnableTmpStorageOnOOM controls whether to enable the temporary storage for some operators + // when a single SQL statement exceeds the memory quota specified by the memory quota. + TiDBEnableTmpStorageOnOOM = "tidb_enable_tmp_storage_on_oom" ) // TiDB intentional limits @@ -996,6 +999,7 @@ const ( DefTiDBGenerateBinaryPlan = true DefEnableTiDBGCAwareMemoryTrack = true DefTiDBDefaultStrMatchSelectivity = 0.8 + DefTiDBEnableTmpStorageOnOOM = true ) // Process global variables. @@ -1006,6 +1010,7 @@ var ( QueryLogMaxLen = atomic.NewInt32(DefTiDBQueryLogMaxLen) EnablePProfSQLCPU = atomic.NewBool(false) EnableBatchDML = atomic.NewBool(false) + EnableTmpStorageOnOOM = atomic.NewBool(DefTiDBEnableTmpStorageOnOOM) ddlReorgWorkerCounter int32 = DefTiDBDDLReorgWorkerCount ddlReorgBatchSize int32 = DefTiDBDDLReorgBatchSize ddlErrorCountlimit int64 = DefTiDBDDLErrorCountLimit diff --git a/tidb-server/main.go b/tidb-server/main.go index 5a4ef5b62fae2..8f4d693f10286 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -179,7 +179,7 @@ func main() { } registerStores() registerMetrics() - if config.GetGlobalConfig().OOMUseTmpStorage { + if variable.EnableTmpStorageOnOOM.Load() { config.GetGlobalConfig().UpdateTempStoragePath() err := disk.InitializeTempDir() terror.MustNil(err) @@ -238,7 +238,7 @@ func syncLog() { } func checkTempStorageQuota() { - // check capacity and the quota when OOMUseTmpStorage is enabled + // check capacity and the quota when EnableTmpStorageOnOOM is enabled c := config.GetGlobalConfig() if c.TempStorageQuota < 0 { // means unlimited, do nothing diff --git a/util/chunk/disk_test.go b/util/chunk/disk_test.go index 3b25b6de1c1eb..80d255a45a8f8 100644 --- a/util/chunk/disk_test.go +++ b/util/chunk/disk_test.go @@ -80,7 +80,7 @@ func TestListInDisk(t *testing.T) { err := l.Add(chk) assert.NoError(t, err) } - require.True(t, strings.HasPrefix(l.dataFile.disk.Name(), filepath.Join(os.TempDir(), "oom-use-tmp-storage"))) + require.True(t, strings.HasPrefix(l.dataFile.disk.Name(), filepath.Join(os.TempDir(), "tidb_enable_tmp_storage_on_oom"))) assert.Equal(t, numChk, l.NumChunks()) assert.Greater(t, l.GetDiskTracker().BytesConsumed(), int64(0)) diff --git a/util/chunk/main_test.go b/util/chunk/main_test.go index 12a2ac966e298..811141e79fcef 100644 --- a/util/chunk/main_test.go +++ b/util/chunk/main_test.go @@ -26,7 +26,7 @@ import ( func TestMain(m *testing.M) { testsetup.SetupForCommonTest() - path, _ := os.MkdirTemp("", "oom-use-tmp-storage") + path, _ := os.MkdirTemp("", "tidb_enable_tmp_storage_on_oom") config.UpdateGlobal(func(conf *config.Config) { conf.TempStoragePath = path }) From 72c29a1f83edafb15df6a50ba7ab370f8ad45129 Mon Sep 17 00:00:00 2001 From: cbcwestwolf <1004626265@qq.com> Date: Thu, 28 Jul 2022 21:07:04 +0800 Subject: [PATCH 2/4] Fix --- config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index cf37b8248dd18..503277d9013dc 100644 --- a/config/config.go +++ b/config/config.go @@ -267,7 +267,7 @@ type Config struct { MemQuotaQuery int64 `toml:"mem-quota-query" json:"mem-quota-query"` OOMAction string `toml:"oom-action" json:"oom-action"` - // OOMUseTmpStorage unused since bootstrap v91 + // OOMUseTmpStorage unused since bootstrap v93 OOMUseTmpStorage bool `toml:"oom-use-tmp-storage" json:"oom-use-tmp-storage"` // CheckMb4ValueInUTF8, EnableCollectExecutionInfo, Plugin are deprecated. From f5afc60222aae00c4e906167d61076191bcb78ca Mon Sep 17 00:00:00 2001 From: cbcwestwolf <1004626265@qq.com> Date: Mon, 1 Aug 2022 20:50:03 +0800 Subject: [PATCH 3/4] Fix --- testkit/BUILD.bazel | 1 - 1 file changed, 1 deletion(-) diff --git a/testkit/BUILD.bazel b/testkit/BUILD.bazel index a75834b392644..71f4cc5ada865 100644 --- a/testkit/BUILD.bazel +++ b/testkit/BUILD.bazel @@ -31,7 +31,6 @@ go_library( "@com_github_pingcap_failpoint//:failpoint", "@com_github_stretchr_testify//assert", "@com_github_stretchr_testify//require", - "@com_github_tikv_client_go_v2//oracle", "@com_github_tikv_client_go_v2//tikv", "@com_github_tikv_client_go_v2//tikvrpc", "@org_golang_x_exp//slices", From 23b57c4e143735458b6e9b459d1ecd9faba02d3e Mon Sep 17 00:00:00 2001 From: cbcwestwolf <1004626265@qq.com> Date: Tue, 2 Aug 2022 10:31:03 +0800 Subject: [PATCH 4/4] Fix bazel --- ddl/schematracker/BUILD.bazel | 1 + session/BUILD.bazel | 1 + testkit/BUILD.bazel | 1 + 3 files changed, 3 insertions(+) diff --git a/ddl/schematracker/BUILD.bazel b/ddl/schematracker/BUILD.bazel index 0cea0cd4b93a4..2151c89b10e22 100644 --- a/ddl/schematracker/BUILD.bazel +++ b/ddl/schematracker/BUILD.bazel @@ -25,6 +25,7 @@ go_library( "//sessionctx", "//sessionctx/variable", "//statistics/handle", + "//store/mockstore", "//table", "//table/tables", "//tidb-binlog/pump_client", diff --git a/session/BUILD.bazel b/session/BUILD.bazel index 628c8d9cad3e3..df53cd8ca0bf1 100644 --- a/session/BUILD.bazel +++ b/session/BUILD.bazel @@ -19,6 +19,7 @@ go_library( "//config", "//ddl", "//ddl/placement", + "//ddl/schematracker", "//domain", "//errno", "//executor", diff --git a/testkit/BUILD.bazel b/testkit/BUILD.bazel index 71f4cc5ada865..4c804dafc97e1 100644 --- a/testkit/BUILD.bazel +++ b/testkit/BUILD.bazel @@ -14,6 +14,7 @@ go_library( importpath = "github.com/pingcap/tidb/testkit", visibility = ["//visibility:public"], deps = [ + "//ddl/schematracker", "//domain", "//kv", "//parser/ast",