Skip to content

Commit

Permalink
domain: fix data race in the ttlJobManager (#41289)
Browse files Browse the repository at this point in the history
close #41288
  • Loading branch information
hawkingrei committed Feb 13, 2023
1 parent 6f99eba commit 707d3d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
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 @@ -903,6 +904,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
}
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 @@ -2543,12 +2557,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

0 comments on commit 707d3d5

Please sign in to comment.