Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

domain: close slow query channel after closing session pool #7847

Merged
merged 5 commits into from
Oct 11, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it enough to put “do.slowQuery.Close()” after line462?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do.slowQuery.Close() will make goroutine exit and WaitGroup count -1.
If this line is moved to line 462,do.wg.Wait() would wait forever.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think it's useless. After this function is executed, "updateStatsWorker" may still be called by another goroutine. This problem still exists.
Maybe we can replace "ctx"(the updateStatsWorker's argument) with the session created in the sysSessionPool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean after session pool is closed, updateStatsWorker will be still executing ? @zimulala

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ye. Because the session used in statistic bootstrap is not get from session pool. @tiancaiamao

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current session pool implementation will block waiting resource to be put back, so after the pool is closed, there won't be system session running. @crazycs520 @zimulala

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about use atomic instead of mutex.

Copy link
Contributor Author

@tiancaiamao tiancaiamao Oct 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atomic can't protect multiple operations. @crazycs520

modify atomic flag
close(ch)

check atomic flag
ch <-

Take this order for example:

  1. check atomic flag = success
  2. modify atomic flag = closed
  3. close(ch)
  4. <-ch panic!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great~

}
}

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