Skip to content

Commit

Permalink
lightning: when lightning exits while processing the task, it should …
Browse files Browse the repository at this point in the history
…return 1 (#53381)

close #53384
  • Loading branch information
zeminzhou committed May 21, 2024
1 parent 07508df commit aeafb18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lightning/cmd/tidb-lightning/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ func main() {
finished := true
if common.IsContextCanceledError(err) {
err = nil
finished = false
if app.TaskCanceled() {
finished = false
}
}
if err != nil {
logger.Error("tidb lightning encountered error stack info", zap.Error(err))
Expand All @@ -121,7 +123,7 @@ func main() {
}
}

if err != nil {
if err != nil || (globalCfg.App.ServerMode && !finished) {
exit(1)
}
}
Expand Down
10 changes: 10 additions & 0 deletions lightning/pkg/server/lightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ type Lightning struct {
cancelLock sync.Mutex
curTask *config.Config
cancel context.CancelFunc // for per task context, which maybe different from lightning context

taskCanceled bool
}

func initEnv(cfg *config.GlobalConfig) error {
Expand Down Expand Up @@ -604,6 +606,7 @@ func (l *Lightning) run(taskCtx context.Context, taskCfg *config.Config, o *opti
func (l *Lightning) Stop() {
l.cancelLock.Lock()
if l.cancel != nil {
l.taskCanceled = true
l.cancel()
}
l.cancelLock.Unlock()
Expand All @@ -613,6 +616,13 @@ func (l *Lightning) Stop() {
l.shutdown()
}

// TaskCanceled return whether the current task is canceled.
func (l *Lightning) TaskCanceled() bool {
l.cancelLock.Lock()
defer l.cancelLock.Unlock()
return l.taskCanceled
}

// Status return the sum size of file which has been imported to TiKV and the total size of source file.
func (l *Lightning) Status() (finished int64, total int64) {
finished = l.status.FinishedFileSize.Load()
Expand Down

0 comments on commit aeafb18

Please sign in to comment.