Skip to content

Commit

Permalink
domain: close slow query channel after closing session pool (pingcap#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao committed Oct 20, 2018
1 parent e48149e commit fa9846d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,12 @@ func (do *Domain) Reload() error {

// LogSlowQuery keeps topN recent slow queries in domain.
func (do *Domain) LogSlowQuery(query *SlowQueryInfo) {
do.slowQuery.mu.RLock()
defer do.slowQuery.mu.RUnlock()
if do.slowQuery.mu.closed {
return
}

select {
case do.slowQuery.ch <- query:
default:
Expand Down Expand Up @@ -459,8 +465,8 @@ func (do *Domain) Close() {
if do.etcdClient != nil {
terror.Log(errors.Trace(do.etcdClient.Close()))
}
do.slowQuery.Close()
do.sysSessionPool.Close()
do.slowQuery.Close()
do.wg.Wait()
log.Info("[domain] close")
}
Expand Down
9 changes: 9 additions & 0 deletions domain/topn_slow_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ type topNSlowQueries struct {
period time.Duration
ch chan *SlowQueryInfo
msgCh chan *showSlowMessage

mu struct {
sync.RWMutex
closed bool
}
}

func newTopNSlowQueries(topN int, period time.Duration, queueSize int) *topNSlowQueries {
Expand Down Expand Up @@ -196,6 +201,10 @@ func (q *topNSlowQueries) QueryTop(count int, kind ast.ShowSlowKind) []*SlowQuer
}

func (q *topNSlowQueries) Close() {
q.mu.Lock()
q.mu.closed = true
q.mu.Unlock()

close(q.ch)
}

Expand Down

0 comments on commit fa9846d

Please sign in to comment.