Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#54768
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
HuSharp authored and ti-chi-bot committed Jul 23, 2024
1 parent 1cd80eb commit 70e8bc4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
13 changes: 7 additions & 6 deletions pkg/domain/resourcegroup/runaway.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@ func GenRunawayQueriesStmt(records []*RunawayRecord) (string, []interface{}) {
type QuarantineRecord struct {
ID int64
ResourceGroupName string
StartTime time.Time
EndTime time.Time
Watch rmpb.RunawayWatchType
WatchText string
Source string
Action rmpb.RunawayAction
// startTime and endTime are in UTC.
StartTime time.Time
EndTime time.Time
Watch rmpb.RunawayWatchType
WatchText string
Source string
Action rmpb.RunawayAction
}

// GetRecordKey is used to get the key in ttl cache.
Expand Down
4 changes: 2 additions & 2 deletions pkg/executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3291,8 +3291,8 @@ func (e *memtableRetriever) setDataFromRunawayWatches(sctx sessionctx.Context) e
row := types.MakeDatums(
watch.ID,
watch.ResourceGroupName,
watch.StartTime.Local().Format(time.DateTime),
watch.EndTime.Local().Format(time.DateTime),
watch.StartTime.UTC().Format(time.DateTime),
watch.EndTime.UTC().Format(time.DateTime),
rmpb.RunawayWatchType_name[int32(watch.Watch)],
watch.WatchText,
watch.Source,
Expand Down
27 changes: 26 additions & 1 deletion pkg/executor/internal/querywatch/query_watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,31 @@ func TestQueryWatch(t *testing.T) {
"default d08bc323a934c39dc41948b0a073725be3398479b6fa4f6dd1db2a9b115f7f57 Kill Plan",
"default 4ea0618129ffc6a7effbc0eff4bbcb41a7f5d4c53a6fa0b2e9be81c7010915b0 CoolDown Similar",
), maxWaitDuration, tryInterval)
<<<<<<< HEAD
=======

rs, err := tk.Exec("select SQL_NO_CACHE start_time from mysql.tidb_runaway_watch where resource_group_name = 'rg2'")
require.NoError(t, err)
require.NotNil(t, rs)
// check start_time in `mysql.tidb_runaway_watch` and `information_schema.runaway_watches`
tk.EventuallyMustQueryAndCheck("select SQL_NO_CACHE DATE_FORMAT(start_time, '%Y-%m-%d %H:%i:%s') as start_time from mysql.tidb_runaway_watch where resource_group_name = 'rg2'", nil,
tk.MustQuery("select SQL_NO_CACHE start_time from information_schema.runaway_watches where resource_group_name = 'rg2'").Rows(), maxWaitDuration, tryInterval)

// avoid the default resource group to be recorded.
tk.MustExec("alter resource group default QUERY_LIMIT=(EXEC_ELAPSED='1000ms' ACTION=DRYRUN)")

require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/store/copr/sleepCoprRequest", fmt.Sprintf("return(%d)", 60)))
err = tk.QueryToErr("select /*+ resource_group(rg1) */ * from t3")
require.ErrorContains(t, err, "[executor:8253]Query execution was interrupted, identified as runaway query")
tk.EventuallyMustQueryAndCheck("select SQL_NO_CACHE resource_group_name, original_sql, match_type from mysql.tidb_runaway_queries", nil,
testkit.Rows(
"rg1 select /*+ resource_group(rg1) */ * from t3 watch",
"rg1 select /*+ resource_group(rg1) */ * from t3 identify",
), maxWaitDuration, tryInterval)
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/store/copr/sleepCoprRequest"))

tk.MustExec("alter resource group default QUERY_LIMIT=(EXEC_ELAPSED='50ms' ACTION=DRYRUN)")
>>>>>>> 560e92ed721 (runaway: change `tidb_runaway_watch` time type to UTC (#54768))
tk.MustGetErrCode("select * from t3", mysql.ErrResourceGroupQueryRunawayQuarantine)
tk.MustQuery("select * from t2").Check(testkit.Rows("1"))
tk.MustQuery("select /*+ resource_group(rg1) */ * from t1").Check(testkit.Rows("1"))
Expand Down Expand Up @@ -119,7 +144,7 @@ func TestQueryWatch(t *testing.T) {
), maxWaitDuration, tryInterval)

// test remove
rs, err := tk.Exec("query watch remove 1")
rs, err = tk.Exec("query watch remove 1")
require.NoError(t, err)
require.Nil(t, rs)
time.Sleep(1 * time.Second)
Expand Down

0 comments on commit 70e8bc4

Please sign in to comment.