diff --git a/dumpling/export/dump.go b/dumpling/export/dump.go index 8523460d648ad..a3f6c1b9f531d 100755 --- a/dumpling/export/dump.go +++ b/dumpling/export/dump.go @@ -1020,7 +1020,20 @@ func prepareTableListToDump(tctx *tcontext.Context, conf *Config, db *sql.Conn) if !conf.NoViews { tableTypes = append(tableTypes, TableTypeView) } - conf.Tables, err = ListAllDatabasesTables(tctx, db, databases, getListTableTypeByConf(conf), tableTypes...) + + ifSeqExists, err := CheckIfSeqExists(db) + if err != nil { + return err + } + var listType listTableType + if ifSeqExists { + tctx.L().Warn("dumpling tableType `sequence` is unsupported for now") + listType = listTableByShowFullTables + } else { + listType = getListTableTypeByConf(conf) + } + + conf.Tables, err = ListAllDatabasesTables(tctx, db, databases, listType, tableTypes...) if err != nil { return err } diff --git a/dumpling/export/prepare.go b/dumpling/export/prepare.go index fcc49cc6d7569..777b366c65a78 100644 --- a/dumpling/export/prepare.go +++ b/dumpling/export/prepare.go @@ -116,6 +116,9 @@ const ( TableTypeBase TableType = iota // TableTypeView represents the view table TableTypeView + // TableTypeSequence represents the view table + // TODO: need to be supported + TableTypeSequence ) const ( @@ -123,6 +126,8 @@ const ( TableTypeBaseStr = "BASE TABLE" // TableTypeViewStr represents the view table string TableTypeViewStr = "VIEW" + // TableTypeSequenceStr represents the view table string + TableTypeSequenceStr = "SEQUENCE" ) func (t TableType) String() string { @@ -131,6 +136,8 @@ func (t TableType) String() string { return TableTypeBaseStr case TableTypeView: return TableTypeViewStr + case TableTypeSequence: + return TableTypeSequenceStr default: return "UNKNOWN" } @@ -143,6 +150,8 @@ func ParseTableType(s string) (TableType, error) { return TableTypeBase, nil case TableTypeViewStr: return TableTypeView, nil + case TableTypeSequenceStr: + return TableTypeSequence, nil default: return TableTypeBase, errors.Errorf("unknown table type %s", s) } diff --git a/dumpling/export/sql.go b/dumpling/export/sql.go index aa05fa8d9c2b4..60e9d08589632 100644 --- a/dumpling/export/sql.go +++ b/dumpling/export/sql.go @@ -725,6 +725,19 @@ func CheckTiDBWithTiKV(db *sql.DB) (bool, error) { return count > 0, nil } +// CheckIfSeqExists use sql to check whether sequence exists +func CheckIfSeqExists(db *sql.Conn) (bool, error) { + var count int + const query = "SELECT COUNT(1) as c FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='SEQUENCE'" + row := db.QueryRowContext(context.Background(), query) + err := row.Scan(&count) + if err != nil { + return false, errors.Annotatef(err, "sql: %s", query) + } + + return count > 0, nil +} + // CheckTiDBEnableTableLock use sql variable to check whether current TiDB has TiKV func CheckTiDBEnableTableLock(db *sql.Conn) (bool, error) { tidbConfig, err := getTiDBConfig(db) diff --git a/dumpling/export/sql_test.go b/dumpling/export/sql_test.go index 8606775e6b32c..44ba39ec01d8c 100644 --- a/dumpling/export/sql_test.go +++ b/dumpling/export/sql_test.go @@ -1747,6 +1747,35 @@ func TestPickupPossibleField(t *testing.T) { } } +func TestCheckIfSeqExists(t *testing.T) { + t.Parallel() + + db, mock, err := sqlmock.New() + require.NoError(t, err) + defer func() { + require.NoError(t, db.Close()) + }() + + conn, err := db.Conn(context.Background()) + require.NoError(t, err) + + mock.ExpectQuery("SELECT COUNT"). + WillReturnRows(sqlmock.NewRows([]string{"c"}). + AddRow("1")) + + exists, err := CheckIfSeqExists(conn) + require.NoError(t, err) + require.Equal(t, true, exists) + + mock.ExpectQuery("SELECT COUNT"). + WillReturnRows(sqlmock.NewRows([]string{"c"}). + AddRow("0")) + + exists, err = CheckIfSeqExists(conn) + require.NoError(t, err) + require.Equal(t, false, exists) +} + func TestGetCharsetAndDefaultCollation(t *testing.T) { t.Parallel() db, mock, err := sqlmock.New() diff --git a/dumpling/tests/basic/run.sh b/dumpling/tests/basic/run.sh index d801970643b75..516fffeff2c30 100644 --- a/dumpling/tests/basic/run.sh +++ b/dumpling/tests/basic/run.sh @@ -88,6 +88,12 @@ actual=$(sed -n '2p' ${DUMPLING_OUTPUT_DIR}/result.000000000.csv) echo "expected 2, actual ${actual}" [ "$actual" = 2 ] +# Test for dump with sequence +run_dumpling | tee ${DUMPLING_OUTPUT_DIR}/dumpling.log +actual=$(grep -w "dump failed" ${DUMPLING_OUTPUT_DIR}/dumpling.log|wc -l) +echo "expected 0, actual ${actual}" +[ "$actual" = 0 ] + # Test for tidb_mem_quota_query configuration export GO_FAILPOINTS="github.com/pingcap/tidb/dumpling/export/PrintTiDBMemQuotaQuery=1*return" run_dumpling | tee ${DUMPLING_OUTPUT_DIR}/dumpling.log