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

ttl: add ttl goroutine exit log #40416

Merged
merged 2 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2475,6 +2475,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.")
YangKeao marked this conversation as resolved.
Show resolved Hide resolved
}()

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