This is a very valuable question. Given that there are several statements in the official documentation, it is prudent to refer to the source code.
The core process of the Lightning service operation is as follows:
https://github.com/pingcap/tidb/blob/master/br/cmd/tidb-lightning/main.go#L76-L111
Focus on the parts related to log printing:
finished := true
if common.IsContextCanceledError(err) {
err = nil
finished = false
}
if err != nil {
logger.Error("tidb lightning encountered error stack info", zap.Error(err))
fmt.Fprintln(os.Stderr, "tidb lightning encountered error:", err)
} else {
logger.Info("tidb lightning exit", zap.Bool("finished", finished))
exitMsg := "tidb lightning exit successfully"
if (!finished) {
exitMsg = "tidb lightning canceled"
}
fmt.Fprintln(os.Stdout, exitMsg)
}
In other words, Lightning should print two logs when it runs normally:
Log file output: [tidb lightning exit] [finished=true]
Console output: tidb lightning exit successfully
Next, let’s see how the whole procedure completed
comes about. The code:
https://github.com/pingcap/tidb/blob/master/br/pkg/lightning/importer/import.go#L526-L572
is the entire logic of Lightning import, divided into the following stages:
rc.setGlobalVariables,
rc.restoreSchema,
rc.preCheckRequirements,
rc.initCheckpoint,
rc.importTables,
rc.fullCompact,
rc.cleanCheckpoints,
Before the process starts, a task called “the whole procedure” is initiated, and after the process ends, it is concluded with task.End(zap.ErrorLevel, err)
. The task has three final states:
https://github.com/pingcap/tidb/blob/master/br/pkg/lightning/log/log.go#L233-L256
var verb string
switch {
case err == nil:
level = task.level
verb = " completed"
case IsContextCanceledError(err):
level = zap.DebugLevel
verb = " canceled"
extraFields = nil
default:
verb = " failed"
extraFields = nil
}
From this, it can be determined that when the log outputs “the whole procedure completed,” it indicates that the entire import is complete, and the time taken will be appended. Finally, back in the main function, the two logs mentioned earlier will be printed.
To summarize the success indicators of Lightning:
1. Log file prints [“the whole procedure completed”] [taketime=xxxx]
2. Log file prints [tidb lightning exit] [finished=true]
3. Console prints tidb lightning exit successfully