Skip to content

Commit

Permalink
runaway: change tidb_runaway_watch time type to UTC (#54768)
Browse files Browse the repository at this point in the history
ref #54434, close #54770
  • Loading branch information
HuSharp authored Jul 23, 2024
1 parent cdd7c9e commit 560e92e
Show file tree
Hide file tree
Showing 3 changed files with 17 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 @@ -110,12 +110,13 @@ func GenRunawayQueriesStmt(records []*RunawayRecord) (string, []any) {
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 @@ -3572,8 +3572,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
9 changes: 8 additions & 1 deletion pkg/executor/internal/querywatch/query_watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ func TestQueryWatch(t *testing.T) {
"rg2 d08bc323a934c39dc41948b0a073725be3398479b6fa4f6dd1db2a9b115f7f57 Kill Plan",
), maxWaitDuration, tryInterval)

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)")

Expand Down Expand Up @@ -151,7 +158,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 560e92e

Please sign in to comment.