Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 12 additions & 12 deletions dumpling/export/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (d *Dumper) Dump() (dumpErr error) {
// for consistency none, the binlog pos in metadata might be earlier than dumped data. We need to enable safe-mode to assure data safety.
err = m.recordGlobalMetaData(metaConn, conf.ServerInfo.ServerType, false)
if err != nil {
tctx.L().Info("get global metadata failed", zap.Error(err))
tctx.L().Info("get global metadata failed", log.ShortError(err))
}

//init charset and default collation map
Expand All @@ -167,7 +167,7 @@ func (d *Dumper) Dump() (dumpErr error) {
}
}
if err = d.renewSelectTableRegionFuncForLowerTiDB(tctx); err != nil {
tctx.L().Info("cannot update select table region info for TiDB", zap.Error(err))
tctx.L().Info("cannot update select table region info for TiDB", log.ShortError(err))
}

atomic.StoreInt64(&d.totalTables, int64(calculateTableCount(conf.Tables)))
Expand Down Expand Up @@ -220,7 +220,7 @@ func (d *Dumper) Dump() (dumpErr error) {
// record again, to provide a location to exit safe mode for DM
err = m.recordGlobalMetaData(metaConn, conf.ServerInfo.ServerType, true)
if err != nil {
tctx.L().Info("get global metadata (after connection pool established) failed", zap.Error(err))
tctx.L().Info("get global metadata (after connection pool established) failed", log.ShortError(err))
}
}

Expand Down Expand Up @@ -362,7 +362,7 @@ func (d *Dumper) dumpDatabases(tctx *tcontext.Context, metaConn *sql.Conn, taskC
for _, table := range tables {
tctx.L().Debug("start dumping table...", zap.String("database", dbName),
zap.String("table", table.Name))
meta, err := dumpTableMeta(conf, metaConn, dbName, table)
meta, err := dumpTableMeta(tctx, conf, metaConn, dbName, table)
if err != nil {
return errors.Trace(err)
}
Expand Down Expand Up @@ -977,7 +977,7 @@ func selectTiDBTableRegion(tctx *tcontext.Context, conn *sql.Conn, meta TableMet
pkVal, err2 := extractTiDBRowIDFromDecodedKey(tidbRowID, decodedKey.String)
if err2 != nil {
logger.Debug("cannot extract pkVal from decoded start key",
zap.Int("rowID", rowID), zap.String("startKey", startKey.String), zap.String("decodedKey", decodedKey.String), zap.Error(err2))
zap.Int("rowID", rowID), zap.String("startKey", startKey.String), zap.String("decodedKey", decodedKey.String), log.ShortError(err2))
} else {
pkVals = append(pkVals, []string{pkVal})
}
Expand Down Expand Up @@ -1013,7 +1013,7 @@ func selectTiDBPartitionRegion(tctx *tcontext.Context, conn *sql.Conn, dbName, t
pkVal, err2 := extractTiDBRowIDFromDecodedKey(regionRowKey, startKey)
if err2 != nil {
logger.Debug("show table region start key doesn't have rowID",
zap.Int("rowID", rowID), zap.String("startKey", startKey), zap.Error(err2))
zap.Int("rowID", rowID), zap.String("startKey", startKey), log.ShortError(err2))
} else {
pkVals = append(pkVals, []string{pkVal})
}
Expand Down Expand Up @@ -1075,7 +1075,7 @@ func prepareTableListToDump(tctx *tcontext.Context, conf *Config, db *sql.Conn)
return nil
}

func dumpTableMeta(conf *Config, conn *sql.Conn, db string, table *TableInfo) (TableMeta, error) {
func dumpTableMeta(tctx *tcontext.Context, conf *Config, conn *sql.Conn, db string, table *TableInfo) (TableMeta, error) {
tbl := table.Name
selectField, selectLen, err := buildSelectField(conn, db, tbl, conf.CompleteInsert)
if err != nil {
Expand All @@ -1088,7 +1088,7 @@ func dumpTableMeta(conf *Config, conn *sql.Conn, db string, table *TableInfo) (T
if conf.ServerInfo.ServerType == version.ServerTypeTiDB {
hasImplicitRowID, err = SelectTiDBRowID(conn, db, tbl)
if err != nil {
return nil, err
tctx.L().Info("check implicit rowID failed", zap.String("database", db), zap.String("table", tbl), log.ShortError(err))
}
}

Expand Down Expand Up @@ -1366,7 +1366,7 @@ func updateServiceSafePoint(tctx *tcontext.Context, pdClient pd.Client, ttl int6
if err == nil {
break
}
tctx.L().Debug("update PD safePoint failed", zap.Error(err), zap.Int("retryTime", retryCnt))
tctx.L().Debug("update PD safePoint failed", log.ShortError(err), zap.Int("retryTime", retryCnt))
select {
case <-tctx.Done():
return
Expand Down Expand Up @@ -1459,7 +1459,7 @@ func (d *Dumper) renewSelectTableRegionFuncForLowerTiDB(tctx *tcontext.Context)

key, err := hex.DecodeString(region.StartKey)
if err != nil {
d.L().Debug("invalid region start key", zap.Error(err), zap.String("key", region.StartKey))
d.L().Debug("invalid region start key", log.ShortError(err), zap.String("key", region.StartKey))
continue
}
// Auto decode byte if needed.
Expand All @@ -1470,13 +1470,13 @@ func (d *Dumper) renewSelectTableRegionFuncForLowerTiDB(tctx *tcontext.Context)
// Try to decode it as a record key.
tableID, handle, err := tablecodec.DecodeRecordKey(key)
if err != nil {
d.L().Debug("cannot decode region start key", zap.Error(err), zap.String("key", region.StartKey), zap.Int64("tableID", tableID))
d.L().Debug("cannot decode region start key", log.ShortError(err), zap.String("key", region.StartKey), zap.Int64("tableID", tableID))
continue
}
if handle.IsInt() {
tableInfoMap[db][tbl] = append(tableInfoMap[db][tbl], handle.IntValue())
} else {
d.L().Debug("not an int handle", zap.Error(err), zap.Stringer("handle", handle))
d.L().Debug("not an int handle", log.ShortError(err), zap.Stringer("handle", handle))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion dumpling/export/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestDumpTableMeta(t *testing.T) {
}
mock.ExpectQuery(fmt.Sprintf("SELECT \\* FROM `%s`.`%s`", database, table)).
WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(1))
meta, err := dumpTableMeta(conf, conn, database, &TableInfo{Type: TableTypeBase, Name: table})
meta, err := dumpTableMeta(tctx, conf, conn, database, &TableInfo{Type: TableTypeBase, Name: table})
require.NoError(t, err)
require.Equal(t, database, meta.DatabaseName())
require.Equal(t, table, meta.TableName())
Expand Down
2 changes: 1 addition & 1 deletion dumpling/export/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func buildOrderByClause(conf *Config, db *sql.Conn, database, table string, hasI
// SelectTiDBRowID checks whether this table has _tidb_rowid column
func SelectTiDBRowID(db *sql.Conn, database, table string) (bool, error) {
const errBadFieldCode = 1054
tiDBRowIDQuery := fmt.Sprintf("SELECT _tidb_rowid from `%s`.`%s` LIMIT 0", escapeString(database), escapeString(table))
tiDBRowIDQuery := fmt.Sprintf("SELECT _tidb_rowid from `%s`.`%s` LIMIT 1", escapeString(database), escapeString(table))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to change it to 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because I found that limit 0 can't explain the row_id status at some time.

mysql> SELECT _tidb_rowid FROM `INFORMATION_SCHEMA`.`CLUSTER_DEADLOCKS` limit 1;
ERROR 1105 (HY000): other error: Column ID -1 of table cluster_deadlocks not found
mysql> SELECT _tidb_rowid FROM `INFORMATION_SCHEMA`.`CLUSTER_DEADLOCKS` limit 0;
Empty set (0.00 sec)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be a bug. 🥲

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dumpling need to keep compatible with this to avoid failure.

_, err := db.ExecContext(context.Background(), tiDBRowIDQuery)
if err != nil {
errMsg := strings.ToLower(err.Error())
Expand Down