Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

restore: don't switch mode in tidb backend #368

Merged
merged 3 commits into from
Aug 13, 2020
Merged
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
25 changes: 16 additions & 9 deletions lightning/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,21 @@ func (rc *RestoreController) listenCheckpointUpdates() {
rc.checkpointsWg.Done()
}

func (rc *RestoreController) runPeriodicActions(ctx context.Context, stop <-chan struct{}) {
switchModeTicker := time.NewTicker(rc.cfg.Cron.SwitchMode.Duration)
func (rc *RestoreController) runPeriodicActions(ctx context.Context, stop <-chan struct{}, shouldSwitchMode bool) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i prefer removing the shouldSwitchMode parameter and check rc.cfg.TikvImporter.Backend inside this function


logProgressTicker := time.NewTicker(rc.cfg.Cron.LogProgress.Duration)
defer func() {
switchModeTicker.Stop()
logProgressTicker.Stop()
}()
defer logProgressTicker.Stop()

rc.switchToImportMode(ctx)
var switchModeChan <-chan time.Time
if shouldSwitchMode {
switchModeTicker := time.NewTicker(rc.cfg.Cron.SwitchMode.Duration)
defer switchModeTicker.Stop()
switchModeChan = switchModeTicker.C

rc.switchToImportMode(ctx)
} else {
switchModeChan = make(chan time.Time)
}

start := time.Now()

Expand All @@ -481,7 +487,7 @@ func (rc *RestoreController) runPeriodicActions(ctx context.Context, stop <-chan
log.L().Info("everything imported, stopping periodic actions")
return

case <-switchModeTicker.C:
case <-switchModeChan:
// periodically switch to import mode, as requested by TiKV 3.0
rc.switchToImportMode(ctx)

Expand Down Expand Up @@ -588,7 +594,8 @@ func (rc *RestoreController) restoreTables(ctx context.Context) error {
var restoreErr common.OnceError

stopPeriodicActions := make(chan struct{})
go rc.runPeriodicActions(ctx, stopPeriodicActions)
shouldSwitchMode := rc.cfg.TikvImporter.Backend != config.BackendTiDB
go rc.runPeriodicActions(ctx, stopPeriodicActions, shouldSwitchMode)

type task struct {
tr *TableRestore
Expand Down