Skip to content

Commit

Permalink
revert time window rounding & fix ut
Browse files Browse the repository at this point in the history
Signed-off-by: mornyx <mornyx.z@gmail.com>
  • Loading branch information
mornyx committed Feb 9, 2023
1 parent 583d619 commit 4548bfb
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 19 deletions.
2 changes: 1 addition & 1 deletion util/stmtsummary/v2/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ func (r *MemReader) Rows() [][]types.Datum {
if r.s == nil {
return nil
}
end := timeNow().Unix()
r.s.windowLock.Lock()
w := r.s.window
end := w.begin.Unix() + int64(r.s.RefreshInterval())
if !r.checker.isTimeValid(w.begin.Unix(), end) {
r.s.windowLock.Unlock()
return nil
Expand Down
8 changes: 1 addition & 7 deletions util/stmtsummary/v2/stmtsummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ func NewStmtSummary(cfg *Config) (*StmtSummary, error) {
return nil, errors.New("stmtsummary: empty filename")
}

now := timeNow().Unix()
now -= now % defaultRefreshInterval

ctx, cancel := context.WithCancel(context.Background())
s := &StmtSummary{
ctx: ctx,
Expand All @@ -108,7 +105,7 @@ func NewStmtSummary(cfg *Config) (*StmtSummary, error) {
optMaxStmtCount: atomic2.NewUint32(defaultMaxStmtCount),
optMaxSQLLength: atomic2.NewUint32(defaultMaxSQLLength),
optRefreshInterval: atomic2.NewUint32(defaultRefreshInterval),
window: newStmtWindow(time.Unix(now, 0), uint(defaultMaxStmtCount)),
window: newStmtWindow(timeNow(), uint(defaultMaxStmtCount)),
storage: newStmtLogStorage(&log.Config{
File: log.FileLogConfig{
Filename: cfg.Filename,
Expand Down Expand Up @@ -373,9 +370,6 @@ func (s *StmtSummary) rotateLoop() {
w := s.window
// The current window has expired and needs to be refreshed and persisted.
if now.After(w.begin.Add(time.Duration(s.RefreshInterval()) * time.Second)) {
nowTs := now.Unix()
nowTs -= nowTs % int64(s.RefreshInterval())
now = time.Unix(nowTs, 0)
s.window = newStmtWindow(now, uint(s.MaxStmtCount()))
size := w.lru.Size()
if size > 0 {
Expand Down
11 changes: 0 additions & 11 deletions util/stmtsummary/v2/stmtsummary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,6 @@ func TestStmtSummary(t *testing.T) {
require.Equal(t, 2, w.lru.Size())
require.Equal(t, 0, w.evicted.count())

ss.SetEnableInternalQuery(false)
internalInfo := GenerateStmtExecInfo4Test("digest8")
internalInfo.IsInternal = true
ss.Add(internalInfo)
require.Equal(t, 2, w.lru.Size())
ss.SetEnableInternalQuery(true)
ss.Add(internalInfo)
require.Equal(t, 3, w.lru.Size())
require.Equal(t, 0, w.evicted.count())
ss.ClearInternal()
require.Equal(t, 2, w.lru.Size())
ss.Clear()
require.Equal(t, 0, w.lru.Size())
}
Expand Down

0 comments on commit 4548bfb

Please sign in to comment.