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 authored and ngaut committed Oct 22, 2018
1 parent 60364fe commit f6d68e6
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 f6d68e6

Please sign in to comment.