Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into fix-default-binary
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta committed Dec 31, 2021
2 parents 41b5313 + 48fce5e commit ac22beb
Show file tree
Hide file tree
Showing 50 changed files with 2,766 additions and 1,129 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
9 changes: 1 addition & 8 deletions br/pkg/lightning/backend/kv/kv2sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package kv
import (
"fmt"

"github.com/pingcap/tidb/br/pkg/lightning/metric"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/table"
Expand All @@ -38,15 +37,10 @@ func (t *TableKVDecoder) Name() string {
return t.tableName
}

func (t *TableKVDecoder) DecodeHandleFromTable(key []byte) (kv.Handle, error) {
func (t *TableKVDecoder) DecodeHandleFromRowKey(key []byte) (kv.Handle, error) {
return tablecodec.DecodeRowKey(key)
}

func (t *TableKVDecoder) EncodeHandleKey(tableID int64, h kv.Handle) kv.Key {
// do not ever ever use tbl.Meta().ID, we need to deal with partitioned tables!
return tablecodec.EncodeRowKeyWithHandle(tableID, h)
}

func (t *TableKVDecoder) DecodeHandleFromIndex(indexInfo *model.IndexInfo, key []byte, value []byte) (kv.Handle, error) {
cols := tables.BuildRowcodecColInfoForIndexColumns(indexInfo, t.tbl.Meta())
return tablecodec.DecodeIndexHandle(key, value, len(cols))
Expand Down Expand Up @@ -111,7 +105,6 @@ func (t *TableKVDecoder) IterRawIndexKeys(h kv.Handle, rawRow []byte, fn func([]
}

func NewTableKVDecoder(tbl table.Table, tableName string, options *SessionOptions) (*TableKVDecoder, error) {
metric.KvEncoderCounter.WithLabelValues("open").Inc()
se := newSession(options)
cols := tbl.Cols()
// Set CommonAddRecordCtx to session to reuse the slices and BufStore in AddRecord
Expand Down
4 changes: 2 additions & 2 deletions br/pkg/lightning/backend/kv/sql2kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (s *kvSuite) TestDecode(c *C) {
Key: []byte{0x74, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x5f, 0x72, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},
Val: []byte{0x8, 0x2, 0x8, 0x2},
}
h, err := decoder.DecodeHandleFromTable(p.Key)
h, err := decoder.DecodeHandleFromRowKey(p.Key)
c.Assert(err, IsNil)
c.Assert(p.Val, NotNil)
rows, _, err := decoder.DecodeRawRowData(h, p.Val)
Expand Down Expand Up @@ -215,7 +215,7 @@ func (s *kvSuite) TestDecodeIndex(c *C) {
Timestamp: 1234567890,
})
c.Assert(err, IsNil)
h1, err := decoder.DecodeHandleFromTable(data.pairs[0].Key)
h1, err := decoder.DecodeHandleFromRowKey(data.pairs[0].Key)
c.Assert(err, IsNil)
h2, err := decoder.DecodeHandleFromIndex(tbl.Indices()[0].Meta(), data.pairs[1].Key, data.pairs[1].Val)
c.Assert(err, IsNil)
Expand Down
Loading

0 comments on commit ac22beb

Please sign in to comment.