Skip to content

Commit

Permalink
ttl: add ttl goroutine exit log (#40416)
Browse files Browse the repository at this point in the history
close #40415
  • Loading branch information
YangKeao authored Jan 9, 2023
1 parent 199bb38 commit 7dbf1a5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2479,6 +2479,10 @@ func (do *Domain) serverIDKeeper() {
// StartTTLJobManager creates and starts the ttl job manager
func (do *Domain) StartTTLJobManager() {
do.wg.Run(func() {
defer func() {
logutil.BgLogger().Info("ttlJobManager exited.")
}()

ttlJobManager := ttlworker.NewJobManager(do.ddl.GetID(), do.sysSessionPool, do.store)
do.ttlJobManager = ttlJobManager
ttlJobManager.Start()
Expand Down
5 changes: 4 additions & 1 deletion ttl/ttlworker/del.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,10 @@ func newDeleteWorker(delCh <-chan *ttlDeleteTask, sessPool sessionPool) *ttlDele

func (w *ttlDeleteWorker) loop() error {
tracer := metrics.NewDeleteWorkerPhaseTracer()
defer tracer.EndPhase()
defer func() {
tracer.EndPhase()
logutil.BgLogger().Info("ttlDeleteWorker loop exited.")
}()

tracer.EnterPhase(metrics.PhaseOther)
se, err := getSession(w.sessionPool)
Expand Down
4 changes: 3 additions & 1 deletion ttl/ttlworker/job_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (m *JobManager) jobLoop() error {
defer func() {
err = multierr.Combine(err, multierr.Combine(m.resizeScanWorkers(0), m.resizeDelWorkers(0)))
se.Close()
logutil.Logger(m.ctx).Info("ttlJobManager loop exited.")
}()

scheduleTicker := time.Tick(jobManagerLoopTickerInterval)
Expand Down Expand Up @@ -247,7 +248,8 @@ func (m *JobManager) resizeWorkers(workers []worker, count int, factory func() w
}

var errs error
ctx, cancel := context.WithTimeout(m.ctx, 30*time.Second)
// don't use `m.ctx` here, because when shutdown the server, `m.ctx` has already been cancelled
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
for _, w := range workers[count:] {
err := w.WaitStopped(ctx, 30*time.Second)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion ttl/ttlworker/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,10 @@ func (w *ttlScanWorker) PollTaskResult() *ttlScanTaskExecResult {
func (w *ttlScanWorker) loop() error {
ctx := w.baseWorker.ctx
tracer := metrics.NewScanWorkerPhaseTracer()
defer tracer.EndPhase()
defer func() {
tracer.EndPhase()
logutil.BgLogger().Info("ttlScanWorker loop exited.")
}()

ticker := time.Tick(time.Second * 5)
for w.Status() == workerStatusRunning {
Expand Down
5 changes: 5 additions & 0 deletions ttl/ttlworker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"time"

"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/logutil"
"go.uber.org/zap"
)

type workerStatus int
Expand Down Expand Up @@ -122,6 +124,9 @@ func (w *baseWorker) Send() chan<- interface{} {
func (w *baseWorker) loop() {
var err error
defer func() {
if r := recover(); r != nil {
logutil.BgLogger().Info("ttl worker panic", zap.Any("recover", r))
}
w.Lock()
w.toStopped(err)
w.Unlock()
Expand Down

0 comments on commit 7dbf1a5

Please sign in to comment.