Skip to content

Commit 560e92e

Browse files
authored
runaway: change tidb_runaway_watch time type to UTC (#54768)
ref #54434, close #54770
1 parent cdd7c9e commit 560e92e

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

pkg/domain/resourcegroup/runaway.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,13 @@ func GenRunawayQueriesStmt(records []*RunawayRecord) (string, []any) {
110110
type QuarantineRecord struct {
111111
ID int64
112112
ResourceGroupName string
113-
StartTime time.Time
114-
EndTime time.Time
115-
Watch rmpb.RunawayWatchType
116-
WatchText string
117-
Source string
118-
Action rmpb.RunawayAction
113+
// startTime and endTime are in UTC.
114+
StartTime time.Time
115+
EndTime time.Time
116+
Watch rmpb.RunawayWatchType
117+
WatchText string
118+
Source string
119+
Action rmpb.RunawayAction
119120
}
120121

121122
// GetRecordKey is used to get the key in ttl cache.

pkg/executor/infoschema_reader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3572,8 +3572,8 @@ func (e *memtableRetriever) setDataFromRunawayWatches(sctx sessionctx.Context) e
35723572
row := types.MakeDatums(
35733573
watch.ID,
35743574
watch.ResourceGroupName,
3575-
watch.StartTime.Local().Format(time.DateTime),
3576-
watch.EndTime.Local().Format(time.DateTime),
3575+
watch.StartTime.UTC().Format(time.DateTime),
3576+
watch.EndTime.UTC().Format(time.DateTime),
35773577
rmpb.RunawayWatchType_name[int32(watch.Watch)],
35783578
watch.WatchText,
35793579
watch.Source,

pkg/executor/internal/querywatch/query_watch_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ func TestQueryWatch(t *testing.T) {
104104
"rg2 d08bc323a934c39dc41948b0a073725be3398479b6fa4f6dd1db2a9b115f7f57 Kill Plan",
105105
), maxWaitDuration, tryInterval)
106106

107+
rs, err := tk.Exec("select SQL_NO_CACHE start_time from mysql.tidb_runaway_watch where resource_group_name = 'rg2'")
108+
require.NoError(t, err)
109+
require.NotNil(t, rs)
110+
// check start_time in `mysql.tidb_runaway_watch` and `information_schema.runaway_watches`
111+
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,
112+
tk.MustQuery("select SQL_NO_CACHE start_time from information_schema.runaway_watches where resource_group_name = 'rg2'").Rows(), maxWaitDuration, tryInterval)
113+
107114
// avoid the default resource group to be recorded.
108115
tk.MustExec("alter resource group default QUERY_LIMIT=(EXEC_ELAPSED='1000ms' ACTION=DRYRUN)")
109116

@@ -151,7 +158,7 @@ func TestQueryWatch(t *testing.T) {
151158
), maxWaitDuration, tryInterval)
152159

153160
// test remove
154-
rs, err := tk.Exec("query watch remove 1")
161+
rs, err = tk.Exec("query watch remove 1")
155162
require.NoError(t, err)
156163
require.Nil(t, rs)
157164
time.Sleep(1 * time.Second)

0 commit comments

Comments
 (0)