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

ddl: handle cluster state retrieval failure #53816

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Changes from 3 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
37 changes: 30 additions & 7 deletions pkg/ddl/job_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (s *jobScheduler) start() {
reorgCnt := min(max(runtime.GOMAXPROCS(0)/4, 1), reorgWorkerCnt)
s.reorgWorkerPool = newDDLWorkerPool(pools.NewResourcePool(workerFactory(addIdxWorker), reorgCnt, reorgCnt, 0), jobTypeReorg)
s.generalDDLWorkerPool = newDDLWorkerPool(pools.NewResourcePool(workerFactory(generalWorker), generalWorkerCnt, generalWorkerCnt, 0), jobTypeGeneral)
s.wg.RunWithLog(s.startDispatchLoop)
s.wg.RunWithLog(s.startDispatchLoopWithRetry)
s.wg.RunWithLog(func() {
s.schemaSyncer.SyncJobSchemaVerLoop(s.schCtx)
})
Expand Down Expand Up @@ -351,10 +351,33 @@ func (d *ddl) startLocalWorkerLoop() {
}
}

func (s *jobScheduler) startDispatchLoop() {
func (s *jobScheduler) startDispatchLoopWithRetry() {
tangenta marked this conversation as resolved.
Show resolved Hide resolved
const retryInterval = 3 * time.Second
for {
err := s.startDispatchLoop()
if err == nil {
return
}
tangenta marked this conversation as resolved.
Show resolved Hide resolved
if err == context.Canceled {
logutil.DDLLogger().Info("startDispatchLoop quit due to context canceled")
return
}
logutil.DDLLogger().Warn("startDispatchLoop failed, retrying",
zap.Error(err))

select {
case <-s.schCtx.Done():
logutil.DDLLogger().Info("startDispatchLoop quit due to context done")
return
case <-time.After(retryInterval):
}
}
}

func (s *jobScheduler) startDispatchLoop() error {
tangenta marked this conversation as resolved.
Show resolved Hide resolved
sessCtx, err := s.sessPool.Get()
if err != nil {
logutil.DDLLogger().Fatal("dispatch loop get session failed, it should not happen, please try restart TiDB", zap.Error(err))
return errors.Trace(err)
}
defer s.sessPool.Put(sessCtx)
se := sess.NewSession(sessCtx)
Expand All @@ -363,15 +386,15 @@ func (s *jobScheduler) startDispatchLoop() {
notifyDDLJobByEtcdCh = s.etcdCli.Watch(s.schCtx, addingDDLJobNotifyKey)
}
if err := s.checkAndUpdateClusterState(true); err != nil {
logutil.DDLLogger().Fatal("dispatch loop get cluster state failed, it should not happen, please try restart TiDB", zap.Error(err))
return errors.Trace(err)
}
ticker := time.NewTicker(dispatchLoopWaitingDuration)
defer ticker.Stop()
// TODO move waitSchemaSyncedController out of ddlCtx.
s.clearOnceMap()
for {
if s.schCtx.Err() != nil {
return
if err := s.schCtx.Err(); err != nil {
return err
}
failpoint.Inject("ownerResignAfterDispatchLoopCheck", func() {
if ingest.ResignOwnerForTest.Load() {
Expand All @@ -393,7 +416,7 @@ func (s *jobScheduler) startDispatchLoop() {
continue
}
case <-s.schCtx.Done():
return
return nil
tangenta marked this conversation as resolved.
Show resolved Hide resolved
}
if err := s.checkAndUpdateClusterState(false); err != nil {
continue
Expand Down