Skip to content

Commit

Permalink
util, executor: fix analyze stmts be killed unexpectedly (#41826)
Browse files Browse the repository at this point in the history
close #41825
  • Loading branch information
XuHuaiyu committed Mar 2, 2023
1 parent 3e5518d commit 8a96edc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions executor/analyzetest/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3087,13 +3087,12 @@ func TestGlobalMemoryControlForAnalyze(t *testing.T) {
sql := "analyze table t with 1.0 samplerate;" // Need about 100MB
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/util/memory/ReadMemStats", `return(536870912)`))
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/executor/mockAnalyzeMergeWorkerSlowConsume", `return(100)`))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/util/memory/ReadMemStats"))
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/executor/mockAnalyzeMergeWorkerSlowConsume"))
}()
_, err := tk0.Exec(sql)
require.True(t, strings.Contains(err.Error(), "Out Of Memory Quota!"))
runtime.GC()
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/util/memory/ReadMemStats"))
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/executor/mockAnalyzeMergeWorkerSlowConsume"))
tk0.MustExec(sql)
}

func TestGlobalMemoryControlForAutoAnalyze(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion util/memory/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (t *Tracker) Detach() {
t.DetachFromGlobalTracker()
return
}
if parent.IsRootTrackerOfSess && t.label == LabelForSQLText {
if parent.IsRootTrackerOfSess && t.label != LabelForMemDB {
parent.actionMuForHardLimit.Lock()
parent.actionMuForHardLimit.actionOnExceed = nil
parent.actionMuForHardLimit.Unlock()
Expand Down

0 comments on commit 8a96edc

Please sign in to comment.