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: fix data race in the ttlJobManager #41289

Merged
merged 4 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions domain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ go_library(
"//util/etcd",
"//util/execdetails",
"//util/expensivequery",
"//util/intest",
"//util/logutil",
"//util/memory",
"//util/memoryusagealarm",
Expand Down
20 changes: 14 additions & 6 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import (
"github.com/pingcap/tidb/util/engine"
"github.com/pingcap/tidb/util/etcd"
"github.com/pingcap/tidb/util/expensivequery"
"github.com/pingcap/tidb/util/intest"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/memory"
"github.com/pingcap/tidb/util/memoryusagealarm"
Expand Down Expand Up @@ -902,6 +903,19 @@ func (do *Domain) Close() {
do.info.RemoveServerInfo()
do.info.RemoveMinStartTS()
}
ttlJobManager := do.ttlJobManager.Load()
if ttlJobManager != nil {
ttlJobManager.Stop()
err := ttlJobManager.WaitStopped(context.Background(), func() time.Duration {
if intest.InTest {
return 10 * time.Second
Copy link
Member Author

Choose a reason for hiding this comment

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

timeout is too long for the test. so it is changed to 10s.

}
return 30 * time.Second
}())
if err != nil {
logutil.BgLogger().Warn("fail to wait until the ttl job manager stop", zap.Error(err))
}
}
close(do.exit)
if do.etcdClient != nil {
terror.Log(errors.Trace(do.etcdClient.Close()))
Expand Down Expand Up @@ -2542,12 +2556,6 @@ func (do *Domain) StartTTLJobManager() {
ttlJobManager.Start()

<-do.exit

ttlJobManager.Stop()
err := ttlJobManager.WaitStopped(context.Background(), 30*time.Second)
if err != nil {
logutil.BgLogger().Warn("fail to wait until the ttl job manager stop", zap.Error(err))
}
}, "ttlJobManager")
}

Expand Down