Skip to content

Commit

Permalink
runaway: change tidb_runaway_watch time type to UTC (#54768) (#54834)
Browse files Browse the repository at this point in the history
ref #54434, close #54770
  • Loading branch information
ti-chi-bot authored Aug 7, 2024
1 parent 70bfd90 commit 01b4f05
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 @@ -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
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 @@ -118,8 +118,15 @@ func TestQueryWatch(t *testing.T) {
"default 4ea0618129ffc6a7effbc0eff4bbcb41a7f5d4c53a6fa0b2e9be81c7010915b0 CoolDown Similar",
), 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)

// 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 01b4f05

Please sign in to comment.