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: simply refactor the code called "needCheckClusterState" #45660

Merged
merged 1 commit into from
Jul 31, 2023
Merged
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
22 changes: 8 additions & 14 deletions ddl/job_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func (d *ddl) startDispatchLoop() {
notifyDDLJobByEtcdCh = d.etcdCli.Watch(d.ctx, addingDDLJobConcurrent)
}
ticker := time.NewTicker(dispatchLoopWaitingDuration)
if err := d.doCheckClusterState(false); err != nil {
if err := d.checkAndUpdateClusterState(true); err != nil {
logutil.BgLogger().Fatal("dispatch loop get cluster state failed, it should not happen, please try restart TiDB", zap.Error(err))
}
defer ticker.Stop()
Expand Down Expand Up @@ -294,7 +294,7 @@ func (d *ddl) startDispatchLoop() {
case <-d.ctx.Done():
return
}
if err := d.needCheckClusterState(isOnce); err != nil {
if err := d.checkAndUpdateClusterState(isOnce); err != nil {
continue
}
isOnce = false
Expand All @@ -303,23 +303,17 @@ func (d *ddl) startDispatchLoop() {
}
}

func (d *ddl) needCheckClusterState(mustCheck bool) error {
func (d *ddl) checkAndUpdateClusterState(needUpdate bool) error {
select {
case _, ok := <-d.stateSyncer.WatchChan():
return d.doCheckClusterState(!ok)
if !ok {
d.stateSyncer.Rewatch(d.ctx)
}
default:
if mustCheck {
return d.doCheckClusterState(false)
if !needUpdate {
return nil
}
}
return nil
}

func (d *ddl) doCheckClusterState(needRewatch bool) error {
if needRewatch {
d.stateSyncer.Rewatch(d.ctx)
return nil
}

oldState := d.stateSyncer.IsUpgradingState()
stateInfo, err := d.stateSyncer.GetGlobalState(d.ctx)
Expand Down