Skip to content

Commit

Permalink
runaway: only check statements with a non-empty plan digest (#57582) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Dec 16, 2024
1 parent 8704a0a commit 13a7da4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/domain/resourcegroup/runaway.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,22 @@ func (rm *RunawayManager) MarkSyncerInitialized() {
rm.syncerInitialized.Store(true)
}

// IsSyncerInitialized is used to check whether the syncer is initialized.
func (rm *RunawayManager) IsSyncerInitialized() bool {
return rm.syncerInitialized.Load()
}

// DeriveChecker derives a RunawayChecker from the given resource group
func (rm *RunawayManager) DeriveChecker(resourceGroupName, originalSQL, sqlDigest, planDigest string) *RunawayChecker {
group, err := rm.resourceGroupCtl.GetResourceGroup(resourceGroupName)
if err != nil || group == nil {
logutil.BgLogger().Warn("cannot setup up runaway checker", zap.Error(err))
return nil
}
// Only check the normal statement.
if len(planDigest) == 0 {
return nil
}
rm.activeLock.RLock()
defer rm.activeLock.RUnlock()
if group.RunawaySettings == nil && rm.activeGroup[resourceGroupName] == 0 {
Expand Down
1 change: 1 addition & 0 deletions pkg/executor/internal/querywatch/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ go_test(
"//pkg/meta/autoid",
"//pkg/testkit",
"//pkg/testkit/testsetup",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_stretchr_testify//require",
"@com_github_tikv_client_go_v2//tikv",
"@org_uber_go_goleak//:goleak",
Expand Down
20 changes: 20 additions & 0 deletions pkg/executor/internal/querywatch/query_watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"testing"
"time"

"github.com/pingcap/failpoint"
mysql "github.com/pingcap/tidb/pkg/errno"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/testkit"
Expand Down Expand Up @@ -132,3 +133,22 @@ func TestQueryWatch(t *testing.T) {
time.Sleep(1 * time.Second)
tk.MustGetErrCode("select * from test.t1", mysql.ErrResourceGroupQueryRunawayQuarantine)
}

func TestQueryWatchIssue56897(t *testing.T) {
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/resourcegroup/runaway/FastRunawayGC", `return(true)`))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/resourcegroup/runaway/FastRunawayGC"))
}()
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
require.Eventually(t, func() bool {
return dom.RunawayManager().IsSyncerInitialized()
}, 20*time.Second, 300*time.Millisecond)
tk.MustQuery("QUERY WATCH ADD ACTION KILL SQL TEXT SIMILAR TO 'use test';").Check((testkit.Rows("1")))
time.Sleep(1 * time.Second)
_, err := tk.Exec("use test")
require.Nil(t, err)
_, err = tk.Exec("use mysql")
require.Nil(t, err)
}

0 comments on commit 13a7da4

Please sign in to comment.