Skip to content

Commit

Permalink
lightning: output a clearer exit message (pingcap#28492) (pingcap#36606)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Jul 27, 2022
1 parent 9b21ed1 commit d674b64
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 21 deletions.
14 changes: 12 additions & 2 deletions br/cmd/tidb-lightning/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"syscall"

"github.com/pingcap/tidb/br/pkg/lightning"
"github.com/pingcap/tidb/br/pkg/lightning/common"
"github.com/pingcap/tidb/br/pkg/lightning/config"
"github.com/pingcap/tidb/br/pkg/lightning/log"
"go.uber.org/zap"
Expand Down Expand Up @@ -89,12 +90,21 @@ func main() {
return app.RunOnce(context.Background(), cfg, nil)
}()

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")
fmt.Fprintln(os.Stdout, "tidb lightning exit")
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)
}

// call Sync() with log to stdout may return error in some case, so just skip it
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/lightning/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (param *MySQLConnectParam) ToDSN() string {
param.SQLMode, param.MaxAllowedPacket, param.TLS)

for k, v := range param.Vars {
dsn += fmt.Sprintf("&%s=%s", k, url.QueryEscape(v))
dsn += fmt.Sprintf("&%s='%s'", k, url.QueryEscape(v))
}

return dsn
Expand Down
5 changes: 3 additions & 2 deletions br/pkg/lightning/common/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ func (s *utilSuite) TestToDSN(c *C) {
"tidb_distsql_scan_concurrency": "1",
},
}
c.Assert(param.ToDSN(), Equals, "root:123456@tcp(127.0.0.1:4000)/?charset=utf8mb4&sql_mode='strict'&maxAllowedPacket=1234&tls=cluster&tidb_distsql_scan_concurrency=1")
c.Assert(param.ToDSN(), Equals, "root:123456@tcp(127.0.0.1:4000)/?charset=utf8mb4&sql_mode='strict'&maxAllowedPacket=1234&tls=cluster&tidb_distsql_scan_concurrency='1'")

c.Assert(param.ToDSN(), Equals, "root:123456@tcp(127.0.0.1:4000)/?charset=utf8mb4&sql_mode='strict'&maxAllowedPacket=1234&tls=cluster&tidb_distsql_scan_concurrency='1'")
param.Host = "::1"
c.Assert(param.ToDSN(), Equals, "root:123456@tcp([::1]:4000)/?charset=utf8mb4&sql_mode='strict'&maxAllowedPacket=1234&tls=cluster&tidb_distsql_scan_concurrency=1")
c.Assert(param.ToDSN(), Equals, "root:123456@tcp([::1]:4000)/?charset=utf8mb4&sql_mode='strict'&maxAllowedPacket=1234&tls=cluster&tidb_distsql_scan_concurrency='1'")
}

func (s *utilSuite) TestIsContextCanceledError(c *C) {
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/lightning/lightning.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (l *Lightning) RunServer() error {
return err
}
err = l.run(context.Background(), task, nil)
if err != nil {
if err != nil && !common.IsContextCanceledError(err) {
restore.DeliverPauser.Pause() // force pause the progress on error
log.L().Error("tidb lightning encountered error", zap.Error(err))
}
Expand Down
15 changes: 1 addition & 14 deletions br/pkg/lightning/restore/check_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package restore

import (
"fmt"
"strings"

"github.com/jedib0t/go-pretty/v6/table"
Expand Down Expand Up @@ -124,17 +123,5 @@ func (c *SimpleTemplate) Output() string {
}
return nil
})
res := c.t.Render()
summary := "\n"
if c.criticalFailedCount > 0 {
summary += fmt.Sprintf("%d critical check failed", c.criticalFailedCount)
}
if c.warnFailedCount > 0 {
msg := fmt.Sprintf("%d performance check failed", c.warnFailedCount)
if len(summary) > 1 {
msg = "," + msg
}
summary += msg
}
return res + summary
return c.t.Render() + "\n"
}
1 change: 0 additions & 1 deletion br/pkg/lightning/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ outside:
case err == nil:
case log.IsContextCanceledError(err):
logger.Info("task canceled")
err = nil
break outside
default:
logger.Error("run failed")
Expand Down

0 comments on commit d674b64

Please sign in to comment.