@@ -13,6 +13,7 @@ import (
1313 "strings"
1414
1515 tcontext "github.com/pingcap/dumpling/v4/context"
16+ "github.com/pingcap/dumpling/v4/log"
1617
1718 "github.com/go-sql-driver/mysql"
1819 "github.com/pingcap/errors"
@@ -585,23 +586,21 @@ func GetPdAddrs(tctx *tcontext.Context, db *sql.DB) ([]string, error) {
585586 query := "SELECT * FROM information_schema.cluster_info where type = 'pd';"
586587 rows , err := db .QueryContext (tctx , query )
587588 if err != nil {
588- tctx .L ().Warn ("can't execute query from db" ,
589- zap .String ("query" , query ), zap .Error (err ))
590589 return []string {}, errors .Annotatef (err , "sql: %s" , query )
591590 }
592- return GetSpecifiedColumnValueAndClose (rows , "STATUS_ADDRESS" )
591+ pdAddrs , err := GetSpecifiedColumnValueAndClose (rows , "STATUS_ADDRESS" )
592+ return pdAddrs , errors .Annotatef (err , "sql: %s" , query )
593593}
594594
595595// GetTiDBDDLIDs gets DDL IDs from TiDB
596596func GetTiDBDDLIDs (tctx * tcontext.Context , db * sql.DB ) ([]string , error ) {
597597 query := "SELECT * FROM information_schema.tidb_servers_info;"
598598 rows , err := db .QueryContext (tctx , query )
599599 if err != nil {
600- tctx .L ().Warn ("can't execute query from db" ,
601- zap .String ("query" , query ), zap .Error (err ))
602600 return []string {}, errors .Annotatef (err , "sql: %s" , query )
603601 }
604- return GetSpecifiedColumnValueAndClose (rows , "DDL_ID" )
602+ ddlIDs , err := GetSpecifiedColumnValueAndClose (rows , "DDL_ID" )
603+ return ddlIDs , errors .Annotatef (err , "sql: %s" , query )
605604}
606605
607606// CheckTiDBWithTiKV use sql to check whether current TiDB has TiKV
@@ -611,7 +610,9 @@ func CheckTiDBWithTiKV(db *sql.DB) (bool, error) {
611610 row := db .QueryRow (query )
612611 err := row .Scan (& count )
613612 if err != nil {
614- return false , errors .Annotatef (err , "sql: %s" , query )
613+ // still return true here. Because sometimes users may not have privileges for MySQL.TiDB database
614+ // In most production cases TiDB has TiKV
615+ return true , errors .Annotatef (err , "sql: %s" , query )
615616 }
616617 return count > 0 , nil
617618}
@@ -995,22 +996,22 @@ func estimateCount(tctx *tcontext.Context, dbName, tableName string, db *sql.Con
995996func detectEstimateRows (tctx * tcontext.Context , db * sql.Conn , query string , fieldNames []string ) uint64 {
996997 rows , err := db .QueryContext (tctx , query )
997998 if err != nil {
998- tctx .L ().Warn ("can't execute query from db" ,
999- zap .String ("query" , query ), zap . Error (err ))
999+ tctx .L ().Warn ("can't detect estimate rows from db" ,
1000+ zap .String ("query" , query ), log . ShortError (err ))
10001001 return 0
10011002 }
10021003 defer rows .Close ()
10031004 rows .Next ()
10041005 columns , err := rows .Columns ()
10051006 if err != nil {
10061007 tctx .L ().Warn ("can't get columns from db" ,
1007- zap .String ("query" , query ), zap . Error (err ))
1008+ zap .String ("query" , query ), log . ShortError (err ))
10081009 return 0
10091010 }
10101011 err = rows .Err ()
10111012 if err != nil {
10121013 tctx .L ().Warn ("rows meet some error during the query" ,
1013- zap .String ("query" , query ), zap . Error (err ))
1014+ zap .String ("query" , query ), log . ShortError (err ))
10141015 return 0
10151016 }
10161017 addr := make ([]interface {}, len (columns ))
@@ -1031,14 +1032,14 @@ found:
10311032 err = rows .Scan (addr ... )
10321033 if err != nil || fieldIndex < 0 {
10331034 tctx .L ().Warn ("can't get estimate count from db" ,
1034- zap .String ("query" , query ), zap . Error (err ))
1035+ zap .String ("query" , query ), log . ShortError (err ))
10351036 return 0
10361037 }
10371038
10381039 estRows , err := strconv .ParseFloat (oneRow [fieldIndex ].String , 64 )
10391040 if err != nil {
10401041 tctx .L ().Warn ("can't get parse rows from db" ,
1041- zap .String ("query" , query ), zap . Error (err ))
1042+ zap .String ("query" , query ), log . ShortError (err ))
10421043 return 0
10431044 }
10441045 return uint64 (estRows )
0 commit comments