From 1a689fe2a9c9550898e0e14e2209221fa44b1bfc Mon Sep 17 00:00:00 2001 From: 5kbpers Date: Thu, 29 Aug 2019 11:35:26 +0800 Subject: [PATCH 01/11] remove unused scripts Signed-off-by: 5kbpers --- run_test.sh | 14 -------------- show_test_table.sh | 7 ------- 2 files changed, 21 deletions(-) delete mode 100755 run_test.sh delete mode 100755 show_test_table.sh diff --git a/run_test.sh b/run_test.sh deleted file mode 100755 index d9eea00e4c360..0000000000000 --- a/run_test.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/zsh - -echo ">>>>>>>>>>>>>>>>>>>>>>> cleanup" -ssh 172.16.5.36 "rm /data3/tmh/1*" -mysql -u root -h 172.16.5.36 -P 42002 -p -e "use sbtest1; drop table sbtest1;" - -echo ">>>>>>>>>>>>>>>>>>>>>>> backup file" -./br backup full -u 172.16.5.36:42010 -s "local:///data3/tmh" - -echo ">>>>>>>>>>>>>>>>>>>>>>> restore file" -make build && ./br restore -r "root@tcp(172.16.5.36:42002)/sbtest" -d "root@tcp(172.16.5.36:42002)/sbtest1" -i 172.16.5.36:8287 -m backupmeta -t sbtest1 -u 172.16.5.36:42010 -c 1 - -echo ">>>>>>>>>>>>>>>>>>>>>>> show restored table" -mysql -u root -h 172.16.5.36 -P 42002 -p -e "use sbtest1; select * from sbtest1;" diff --git a/show_test_table.sh b/show_test_table.sh deleted file mode 100755 index 5d638a4ddfd51..0000000000000 --- a/show_test_table.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/zsh - -echo ">>>>>>>>>>>>>>>> source table" -mysql -u root -h 172.16.5.36 -P 42002 -p -e "use sbtest; select * from sbtest1;" - -echo ">>>>>>>>>>>>>>>> destination table" -mysql -u root -h 172.16.5.36 -P 42002 -p -e "use sbtest1; select * from sbtest1;" From 44737391e62c4b0e16694a659111a0c6a36fe6ac Mon Sep 17 00:00:00 2001 From: 5kbpers Date: Mon, 16 Sep 2019 16:27:46 +0800 Subject: [PATCH 02/11] fetch all schemas before backup Signed-off-by: 5kbpers --- cmd/raw.go | 4 ++++ pkg/raw/full.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/cmd/raw.go b/cmd/raw.go index 330fd6e8217e4..17dfed2d8fac2 100644 --- a/cmd/raw.go +++ b/cmd/raw.go @@ -42,6 +42,10 @@ func newFullBackupCommand() *cobra.Command { if err != nil { return err } + err = client.BackupAllSchemas(backupTS) + if err != nil { + return err + } err = client.BackupRange([]byte(""), []byte(""), u, backupTS, rate) if err != nil { return err diff --git a/pkg/raw/full.go b/pkg/raw/full.go index c6ea09c718a48..79322703c76c7 100644 --- a/pkg/raw/full.go +++ b/pkg/raw/full.go @@ -178,6 +178,53 @@ func buildTableRanges(tbl *model.TableInfo) []tableRange { return ranges } +// BackupAllSchemas fetches all schemas from TiDB. +func (bc *BackupClient) BackupAllSchemas(backupTS uint64) error { + SystemDatabases := [3]string{ + "INFORMATION_SCHEMA", + "PERFORMANCE_SCHEMA", + "mysql", + } + + session, err := session.CreateSession(bc.backer.GetTiKV()) + if err != nil { + return errors.Trace(err) + } + do := domain.GetDomain(session.(sessionctx.Context)) + info, err := do.GetSnapshotInfoSchema(backupTS) + if err != nil { + return errors.Trace(err) + } + + dbInfos := info.AllSchemas() +LoadDb: + for _, dbInfo := range dbInfos { + // skip system databases + for _, sysDbName := range SystemDatabases { + if sysDbName == dbInfo.Name.String() { + continue LoadDb + } + } + dbData, err := json.Marshal(dbInfo) + if err != nil { + return errors.Trace(err) + } + for _, tableInfo := range dbInfo.Tables { + tableData, err := json.Marshal(tableInfo) + if err != nil { + return errors.Trace(err) + } + // Save schema. + backupSchema := &backup.Schema{ + Db: dbData, + Table: tableData, + } + bc.backupMeta.Schemas = append(bc.backupMeta.Schemas, backupSchema) + } + } + return nil +} + // BackupRange make a backup of the given key range. func (bc *BackupClient) BackupRange( startKey, endKey []byte, From 09a4100ba973934dabb0115b56bb2464e5380942 Mon Sep 17 00:00:00 2001 From: 5kbpers Date: Mon, 16 Sep 2019 22:14:47 +0800 Subject: [PATCH 03/11] backup & restore auto inc id Signed-off-by: 5kbpers --- cmd/restore.go | 21 +++++-- pkg/raw/full.go | 31 ++++++++-- pkg/restore/client.go | 133 ++++++++++++++++++++++-------------------- pkg/restore/schema.go | 96 ++++++++++++++++++++---------- pkg/restore/util.go | 31 +++++----- 5 files changed, 193 insertions(+), 119 deletions(-) diff --git a/cmd/restore.go b/cmd/restore.go index 2cd82882b73f9..489e6a223bc00 100644 --- a/cmd/restore.go +++ b/cmd/restore.go @@ -3,8 +3,6 @@ package cmd import ( "context" "fmt" - "io/ioutil" - "github.com/gogo/protobuf/proto" "github.com/pingcap/br/pkg/restore" "github.com/pingcap/errors" @@ -12,6 +10,7 @@ import ( "github.com/pingcap/kvproto/pkg/import_sstpb" "github.com/spf13/cobra" flag "github.com/spf13/pflag" + "io/ioutil" ) // NewRestoreCommand returns a restore subcommand @@ -185,11 +184,23 @@ func newTableRestoreCommand() *cobra.Command { if err != nil { return errors.Trace(err) } - tables := db.GetTables(tableName) - if len(tables) <= 0 { + table := db.GetTable(tableName) + if table == nil { + return errors.Trace(fmt.Errorf("not exists table")) + } + err = restore.CreateTable(db.Schema.Name.String(), table, client.GetDbDSN()) + if err != nil { + return errors.Trace(err) + } + err = restore.AlterAutoIncID(db.Schema.Name.String(), table, client.GetDbDSN()) + if err != nil { + return errors.Trace(err) + } + fileGroups := db.GetFileGroups(tableName) + if len(fileGroups) <= 0 { return errors.Trace(fmt.Errorf("not exists table")) } - err = client.RestoreMultipleTables(tables, restoreTS) + err = client.RestoreMultipleTables(fileGroups, restoreTS) return errors.Trace(err) }, } diff --git a/pkg/raw/full.go b/pkg/raw/full.go index 79322703c76c7..0e0962c1b17e0 100644 --- a/pkg/raw/full.go +++ b/pkg/raw/full.go @@ -3,6 +3,7 @@ package raw import ( "context" "encoding/json" + "github.com/pingcap/tidb/meta/autoid" "io/ioutil" "sync" "time" @@ -92,11 +93,11 @@ func (bc *BackupClient) BackupTable( backupTS uint64, rateLimit uint64, ) error { - session, err := session.CreateSession(bc.backer.GetTiKV()) + dbSession, err := session.CreateSession(bc.backer.GetTiKV()) if err != nil { return errors.Trace(err) } - do := domain.GetDomain(session.(sessionctx.Context)) + do := domain.GetDomain(dbSession.(sessionctx.Context)) info, err := do.GetSnapshotInfoSchema(backupTS) if err != nil { return errors.Trace(err) @@ -111,10 +112,16 @@ func (bc *BackupClient) BackupTable( } cTableName := model.NewCIStr(tableName) table, err := info.TableByName(cDBName, cTableName) + if err != nil { + return errors.Trace(err) + } tableInfo = table.Meta() + idAlloc := autoid.NewAllocator(bc.backer.GetTiKV(), dbInfo.ID, false) + globalAutoID, err := idAlloc.NextGlobalAutoID(tableInfo.ID) if err != nil { return errors.Trace(err) } + tableInfo.AutoIncID = globalAutoID dbData, err := json.Marshal(dbInfo) if err != nil { @@ -131,6 +138,11 @@ func (bc *BackupClient) BackupTable( Db: dbData, Table: tableData, } + log.Info("save table schema", + zap.String("db", dbInfo.Name.String()), + zap.String("table", tableInfo.Name.String()), + zap.Int64("auto_inc_id", globalAutoID), + ) bc.backupMeta.Schemas = append(bc.backupMeta.Schemas, backupSchema) log.Info("backup table meta", zap.Reflect("Schema", dbInfo), @@ -186,11 +198,11 @@ func (bc *BackupClient) BackupAllSchemas(backupTS uint64) error { "mysql", } - session, err := session.CreateSession(bc.backer.GetTiKV()) + dbSession, err := session.CreateSession(bc.backer.GetTiKV()) if err != nil { return errors.Trace(err) } - do := domain.GetDomain(session.(sessionctx.Context)) + do := domain.GetDomain(dbSession.(sessionctx.Context)) info, err := do.GetSnapshotInfoSchema(backupTS) if err != nil { return errors.Trace(err) @@ -209,7 +221,13 @@ LoadDb: if err != nil { return errors.Trace(err) } + idAlloc := autoid.NewAllocator(bc.backer.GetTiKV(), dbInfo.ID, false) for _, tableInfo := range dbInfo.Tables { + globalAutoID, err := idAlloc.NextGlobalAutoID(tableInfo.ID) + if err != nil { + return errors.Trace(err) + } + tableInfo.AutoIncID = globalAutoID tableData, err := json.Marshal(tableInfo) if err != nil { return errors.Trace(err) @@ -219,6 +237,11 @@ LoadDb: Db: dbData, Table: tableData, } + log.Info("save table schema", + zap.String("db", dbInfo.Name.String()), + zap.String("table", tableInfo.Name.String()), + zap.Int64("auto_inc_id", globalAutoID), + ) bc.backupMeta.Schemas = append(bc.backupMeta.Schemas, backupSchema) } } diff --git a/pkg/restore/client.go b/pkg/restore/client.go index 2ff0489123b98..6e6e0124b2c8a 100644 --- a/pkg/restore/client.go +++ b/pkg/restore/client.go @@ -127,38 +127,33 @@ func (rc *Client) GetDatabase(name string) *Database { } // UploadTableFiles executes the job to restore files of a table -func (rc *Client) UploadTableFiles(client import_kvpb.ImportKVClient, table *Table, restoreTS uint64) error { - log.Info("start to upload files of table", - zap.String("table", table.Schema.Name.O), - zap.String("uuid", table.UUID.String()), - zap.String("db", table.Db.Name.O), +func (rc *Client) UploadTableFiles(client import_kvpb.ImportKVClient, group *FileGroup, restoreTS uint64) error { + log.Info("start to upload files of group", + zap.String("group", group.Schema.Name.String()), + zap.String("uuid", group.UUID.String()), + zap.String("db", group.Db.Name.String()), ) - dns := rc.dbDSN + table.Db.Name.O - returnErr := CreateTable(table, dns) + tableInfo, returnErr := FetchTableInfo(rc.statusAddr, group.Db.Name.String(), group.Schema.Name.String()) if returnErr != nil { return errors.Trace(returnErr) } - tableInfo, returnErr := FetchTableInfo(rc.statusAddr, table.Db.Name.O, table.Schema.Name.O) - if returnErr != nil { - return errors.Trace(returnErr) - } - tableIDs, indexIDs := GroupIDPairs(table.Schema, tableInfo) + tableIDs, indexIDs := GroupIDPairs(group.Schema, tableInfo) - returnErr = rc.OpenEngine(client, table.UUID.Bytes()) + returnErr = rc.OpenEngine(client, group.UUID.Bytes()) if returnErr != nil { log.Error("open engine failed", zap.Uint64("restore_ts", restoreTS), - zap.String("table", table.Schema.Name.O), - zap.String("uuid", table.UUID.String()), - zap.String("db", table.Db.Name.O), + zap.String("group", group.Schema.Name.String()), + zap.String("uuid", group.UUID.String()), + zap.String("db", group.Db.Name.String()), ) return errors.Trace(returnErr) } - errCh := make(chan error, len(table.Files)) + errCh := make(chan error, len(group.Files)) defer close(errCh) - for _, file := range table.Files { + for _, file := range group.Files { select { case <-rc.ctx.Done(): return nil @@ -172,14 +167,14 @@ func (rc *Client) UploadTableFiles(client import_kvpb.ImportKVClient, table *Tab TableIds: tableIDs, IndexIds: indexIDs, RestoreTs: restoreTS, - Uuid: table.UUID.Bytes(), + Uuid: group.UUID.Bytes(), } sendErr := func(err error) { log.Error("restore file failed", zap.Reflect("file", file), zap.Uint64("restore_ts", restoreTS), - zap.String("table", table.Schema.Name.O), - zap.String("db", table.Db.Name.O), + zap.String("group", group.Schema.Name.String()), + zap.String("db", group.Db.Name.String()), zap.Error(errors.Trace(err)), ) errCh <- errors.Trace(err) @@ -192,15 +187,15 @@ func (rc *Client) UploadTableFiles(client import_kvpb.ImportKVClient, table *Tab log.Debug("restore file success", zap.Reflect("file", file), zap.Uint64("restore_ts", restoreTS), - zap.String("table", table.Schema.Name.O), - zap.String("db", table.Db.Name.O), + zap.String("group", group.Schema.Name.String()), + zap.String("db", group.Db.Name.String()), ) errCh <- nil }(file) } } - for i := 0; i < len(table.Files); i++ { + for i := 0; i < len(group.Files); i++ { err := <-errCh if err != nil { returnErr = err @@ -210,45 +205,45 @@ func (rc *Client) UploadTableFiles(client import_kvpb.ImportKVClient, table *Tab return errors.Trace(returnErr) } - returnErr = rc.CloseEngine(client, table.UUID.Bytes()) + returnErr = rc.CloseEngine(client, group.UUID.Bytes()) if returnErr != nil { log.Error("close engine failed", zap.Uint64("restore_ts", restoreTS), - zap.String("table", table.Schema.Name.O), - zap.String("uuid", table.UUID.String()), - zap.String("db", table.Db.Name.O), + zap.String("group", group.Schema.Name.String()), + zap.String("uuid", group.UUID.String()), + zap.String("db", group.Db.Name.String()), ) return errors.Trace(returnErr) } - log.Info("upload table files finished", + log.Info("upload group files finished", zap.Uint64("restore_ts", restoreTS), - zap.String("table", table.Schema.Name.O), - zap.String("uuid", table.UUID.String()), - zap.String("db", table.Db.Name.O), + zap.String("group", group.Schema.Name.String()), + zap.String("uuid", group.UUID.String()), + zap.String("db", group.Db.Name.String()), ) return errors.Trace(returnErr) } type uploadJob struct { - Table *Table + Group *FileGroup } type importJob struct { - Table *Table + Group *FileGroup Client import_kvpb.ImportKVClient } // RestoreMultipleTables executes the job to restore multiple tables -func (rc *Client) RestoreMultipleTables(tables []*Table, restoreTS uint64) error { +func (rc *Client) RestoreMultipleTables(groups []*FileGroup, restoreTS uint64) error { log.Info("start to restore multiple table", - zap.Int("len", len(tables)), + zap.Int("len", len(groups)), ) var returnErr error - errCh := make(chan error, len(tables)) - uploadJobCh := make(chan uploadJob, len(tables)) - importJobCh := make(chan importJob, len(tables)) + errCh := make(chan error, len(groups)) + uploadJobCh := make(chan uploadJob, len(groups)) + importJobCh := make(chan importJob, len(groups)) defer close(errCh) defer close(uploadJobCh) defer close(importJobCh) @@ -260,14 +255,14 @@ func (rc *Client) RestoreMultipleTables(tables []*Table, restoreTS uint64) error for j := 0; j < rc.maxOpenEngines; j++ { go func(client import_kvpb.ImportKVClient, n int) { for job := range uploadJobCh { - log.Info("restore table", zap.Int("importer", n), zap.String("uuid", job.Table.UUID.String())) - err := rc.UploadTableFiles(client, job.Table, restoreTS) + log.Info("restore table", zap.Int("importer", n), zap.String("uuid", job.Group.UUID.String())) + err := rc.UploadTableFiles(client, job.Group, restoreTS) if err != nil { errCh <- errors.Trace(err) return } importJobCh <- importJob{ - Table: job.Table, + Group: job.Group, Client: client, } } @@ -278,42 +273,42 @@ func (rc *Client) RestoreMultipleTables(tables []*Table, restoreTS uint64) error for i := 0; i < rc.maxImportJobs; i++ { go func() { for job := range importJobCh { - table := job.Table - log.Info("start to import table", + group := job.Group + log.Info("start to import group", zap.Uint64("restore_ts", restoreTS), - zap.String("table", table.Schema.Name.O), - zap.String("uuid", table.UUID.String()), - zap.String("db", table.Db.Name.O), + zap.String("group", group.Schema.Name.String()), + zap.String("uuid", group.UUID.String()), + zap.String("db", group.Db.Name.String()), ) - err := rc.ImportEngine(job.Client, table.UUID.Bytes()) + err := rc.ImportEngine(job.Client, group.UUID.Bytes()) if err != nil { log.Error("import engine failed", zap.Uint64("restore_ts", restoreTS), - zap.String("table", table.Schema.Name.O), - zap.String("uuid", table.UUID.String()), - zap.String("db", table.Db.Name.O), + zap.String("group", group.Schema.Name.String()), + zap.String("uuid", group.UUID.String()), + zap.String("db", group.Db.Name.String()), zap.Error(err), ) errCh <- errors.Trace(err) return } - err = rc.CleanupEngine(job.Client, table.UUID.Bytes()) + err = rc.CleanupEngine(job.Client, group.UUID.Bytes()) if err != nil { log.Error("cleanup engine failed", zap.Uint64("restore_ts", restoreTS), - zap.String("table", table.Schema.Name.O), - zap.String("uuid", table.UUID.String()), - zap.String("db", table.Db.Name.O), + zap.String("group", group.Schema.Name.String()), + zap.String("uuid", group.UUID.String()), + zap.String("db", group.Db.Name.String()), zap.Error(err), ) errCh <- errors.Trace(err) return } - log.Info("import table finished", + log.Info("import group finished", zap.Uint64("restore_ts", restoreTS), - zap.String("table", table.Schema.Name.O), - zap.String("uuid", table.UUID.String()), - zap.String("db", table.Db.Name.O), + zap.String("group", group.Schema.Name.String()), + zap.String("uuid", group.UUID.String()), + zap.String("db", group.Db.Name.String()), ) errCh <- nil } @@ -321,19 +316,19 @@ func (rc *Client) RestoreMultipleTables(tables []*Table, restoreTS uint64) error } go func() { - for _, table := range tables { + for _, group := range groups { select { case <-rc.ctx.Done(): return default: uploadJobCh <- uploadJob{ - Table: table, + Group: group, } } } }() - for i := 0; i < len(tables); i++ { + for i := 0; i < len(groups); i++ { returnErr = <-errCh if returnErr != nil { return errors.Trace(returnErr) @@ -348,11 +343,21 @@ func (rc *Client) RestoreDatabase(db *Database, restoreTS uint64) error { if returnErr != nil { return returnErr } - returnErr = rc.RestoreMultipleTables(db.Tables, restoreTS) + for _, table := range db.Tables { + returnErr = CreateTable(db.Schema.Name.String(), table, rc.dbDSN) + if returnErr != nil { + return errors.Trace(returnErr) + } + returnErr = AlterAutoIncID(db.Schema.Name.String(), table, rc.dbDSN) + if returnErr != nil { + return errors.Trace(returnErr) + } + } + returnErr = rc.RestoreMultipleTables(db.FileGroups, restoreTS) if returnErr == nil { log.Info("restore database finished", zap.Uint64("restore_ts", restoreTS), - zap.String("db", db.Schema.Name.O), + zap.String("db", db.Schema.Name.String()), ) } return errors.Trace(returnErr) diff --git a/pkg/restore/schema.go b/pkg/restore/schema.go index fed4b33fa9f37..06a4368361ac3 100644 --- a/pkg/restore/schema.go +++ b/pkg/restore/schema.go @@ -4,6 +4,7 @@ import ( "bytes" "database/sql" "fmt" + "net/url" "strconv" "strings" @@ -19,8 +20,8 @@ import ( "go.uber.org/zap" ) -// Table wraps the schema and files of a table -type Table struct { +// FileGroup wraps the schema and files of a table +type FileGroup struct { UUID uuid.UUID Db *model.DBInfo Schema *model.TableInfo @@ -29,8 +30,9 @@ type Table struct { // Database wraps the schema and tables of a database type Database struct { - Schema *model.DBInfo - Tables []*Table + Schema *model.DBInfo + FileGroups []*FileGroup + Tables []*model.TableInfo } // FilePair wraps a default cf file & a write cf file @@ -39,31 +41,42 @@ type FilePair struct { Write *backup.File } -// GetTables returns a table instance by name -func (db *Database) GetTables(name string) []*Table { - tables := make([]*Table, 0) +// GetFileGroups returns file groups by name +func (db *Database) GetFileGroups(name string) []*FileGroup { + fileGroups := make([]*FileGroup, 0) + for _, group := range db.FileGroups { + if group.Schema.Name.String() == name { + fileGroups = append(fileGroups, group) + } + } + return fileGroups +} + +// GetTable returns a table info by name +func (db *Database) GetTable(name string) *model.TableInfo { for _, table := range db.Tables { - if table.Schema.Name.O == name { - tables = append(tables, table) + if table.Name.String() == name { + return table } } - return tables + return nil } // CreateTable executes a CREATE TABLE SQL -func CreateTable(table *Table, dns string) error { - db, err := sql.Open("mysql", dns) +func CreateTable(dbName string, table *model.TableInfo, dsn string) error { + dbDSN := dsn + url.QueryEscape(dbName) + db, err := sql.Open("mysql", dbDSN) if err != nil { - log.Error("open database failed", zap.String("addr", dns), zap.Error(err)) + log.Error("open database failed", zap.String("addr", dbDSN), zap.Error(err)) return errors.Trace(err) } - createSQL := GetCreateTableSQL(table.Schema) + createSQL := GetCreateTableSQL(table) _, err = db.Exec(createSQL) if err != nil { log.Error("create table failed", zap.String("SQL", createSQL), - zap.String("db", table.Db.Name.O), - zap.String("addr", dns), + zap.String("db", dbName), + zap.String("addr", dsn), zap.Error(err)) return errors.Trace(err) } @@ -71,10 +84,10 @@ func CreateTable(table *Table, dns string) error { } // CreateDatabase executes a CREATE DATABASE SQL -func CreateDatabase(schema *model.DBInfo, dns string) error { - db, err := sql.Open("mysql", dns) +func CreateDatabase(schema *model.DBInfo, dsn string) error { + db, err := sql.Open("mysql", dsn) if err != nil { - log.Error("open database failed", zap.String("addr", dns), zap.Error(err)) + log.Error("open database failed", zap.String("addr", dsn), zap.Error(err)) return errors.Trace(err) } createSQL := GetCreateDatabaseSQL(schema) @@ -87,25 +100,48 @@ func CreateDatabase(schema *model.DBInfo, dns string) error { } // AnalyzeTable executes a ANALYZE TABLE SQL -func AnalyzeTable(table *Table, dns string) error { - db, err := sql.Open("mysql", dns) +func AnalyzeTable(dbName string, table *model.TableInfo, dsn string) error { + dbDSN := dsn + url.QueryEscape(dbName) + db, err := sql.Open("mysql", dbDSN) if err != nil { - log.Error("open database failed", zap.String("addr", dns), zap.Error(err)) + log.Error("open database failed", zap.String("addr", dbDSN), zap.Error(err)) return errors.Trace(err) } - analyzeSQL := fmt.Sprintf("ANALYZE TABLE %s", table.Schema.Name.O) + analyzeSQL := fmt.Sprintf("ANALYZE TABLE %s", table.Name.String()) _, err = db.Exec(analyzeSQL) if err != nil { - log.Error("analyze table failed", zap.String("SQL", analyzeSQL), zap.String("db", table.Db.Name.O), zap.Error(err)) + log.Error("analyze table failed", zap.String("SQL", analyzeSQL), zap.String("db", dbName), zap.Error(err)) + return errors.Trace(err) + } + return nil +} + +// AlterAutoIncID alters max auto-increment id of table +func AlterAutoIncID(dbName string, table *model.TableInfo, dsn string) error { + dbDSN := dsn + url.QueryEscape(dbName) + db, err := sql.Open("mysql", dbDSN) + if err != nil { + log.Error("open database failed", zap.String("addr", dbDSN), zap.Error(err)) + return errors.Trace(err) + } + alterIDSQL := fmt.Sprintf("ALTER TABLE %s auto_increment = %d", table.Name.String(), table.AutoIncID) + _, err = db.Exec(alterIDSQL) + if err != nil { + log.Error("alter auto inc id failed", zap.String("SQL", alterIDSQL), zap.String("db", dbName), zap.Error(err)) return errors.Trace(err) } + log.Info("alter auto inc id", + zap.String("table", table.Name.String()), + zap.String("db", dbName), + zap.Int64("auto_inc_id", table.AutoIncID), + ) return nil } // GetCreateDatabaseSQL generates a CREATE DATABASE SQL from DBInfo func GetCreateDatabaseSQL(db *model.DBInfo) string { var buf bytes.Buffer - fmt.Fprintf(&buf, "CREATE DATABASE IF NOT EXISTS %s", db.Name.O) + fmt.Fprintf(&buf, "CREATE DATABASE IF NOT EXISTS %s", db.Name.String()) fmt.Fprintf(&buf, " CHARACTER SET %s COLLATE %s", db.Charset, db.Collate) buf.WriteString(";") @@ -121,7 +157,7 @@ func GetCreateTableSQL(t *model.TableInfo) string { fmt.Fprintf(&buf, "CREATE TABLE IF NOT EXISTS %s (\n", t.Name) var pkCol *model.ColumnInfo for i, col := range t.Columns { - fmt.Fprintf(&buf, " %s %s", col.Name.O, getColumnTypeDesc(col)) + fmt.Fprintf(&buf, " %s %s", col.Name.String(), getColumnTypeDesc(col)) if col.Charset != "binary" { if col.Charset != tblCharset || col.Collate != tblCollate { fmt.Fprintf(&buf, " CHARACTER SET %s COLLATE %s", col.Charset, col.Collate) @@ -187,7 +223,7 @@ func GetCreateTableSQL(t *model.TableInfo) string { if pkCol != nil { // If PKIsHandle, pk info is not in tb.Indices(). We should handle it here. buf.WriteString(",\n") - fmt.Fprintf(&buf, " PRIMARY KEY (%s)", pkCol.Name.O) + fmt.Fprintf(&buf, " PRIMARY KEY (%s)", pkCol.Name.String()) } publicIndices := make([]*model.IndexInfo, 0, len(t.Indices)) @@ -204,14 +240,14 @@ func GetCreateTableSQL(t *model.TableInfo) string { if idx.Primary { buf.WriteString(" PRIMARY KEY ") } else if idx.Unique { - fmt.Fprintf(&buf, " UNIQUE KEY %s ", idx.Name.O) + fmt.Fprintf(&buf, " UNIQUE KEY %s ", idx.Name.String()) } else { - fmt.Fprintf(&buf, " KEY %s ", idx.Name.O) + fmt.Fprintf(&buf, " KEY %s ", idx.Name.String()) } cols := make([]string, 0, len(idx.Columns)) for _, c := range idx.Columns { - colInfo := c.Name.O + colInfo := c.Name.String() if c.Length != types.UnspecifiedLength { colInfo = fmt.Sprintf("%s(%s)", colInfo, strconv.Itoa(c.Length)) } diff --git a/pkg/restore/util.go b/pkg/restore/util.go index f546977276d3c..885fe3f681baf 100644 --- a/pkg/restore/util.go +++ b/pkg/restore/util.go @@ -25,18 +25,6 @@ func LoadBackupTables(meta *backup.BackupMeta, partitionSize int) (map[string]*D databases := make(map[string]*Database) filePairs := groupFiles(meta.Files) - addTableToDb := func(t *Table) { - db, ok := databases[t.Db.Name.O] - if !ok { - db = &Database{ - Schema: t.Db, - Tables: make([]*Table, 0), - } - databases[t.Db.Name.O] = db - } - db.Tables = append(db.Tables, t) - } - for _, schema := range meta.Schemas { dbInfo := &model.DBInfo{} err := json.Unmarshal(schema.Db, dbInfo) @@ -52,6 +40,17 @@ func LoadBackupTables(meta *backup.BackupMeta, partitionSize int) (map[string]*D return nil, errors.Trace(err) } + db, ok := databases[dbInfo.Name.String()] + if !ok { + db = &Database{ + Schema: dbInfo, + FileGroups: make([]*FileGroup, 0), + Tables: make([]*model.TableInfo, 0), + } + databases[dbInfo.Name.String()] = db + } + db.Tables = append(db.Tables, tableInfo) + tableFiles := make([]*FilePair, 0) for _, pair := range filePairs { f := pair.Write @@ -64,25 +63,25 @@ func LoadBackupTables(meta *backup.BackupMeta, partitionSize int) (map[string]*D if startTableID == tableInfo.ID || endTableID == tableInfo.ID { tableFiles = append(tableFiles, pair) if len(tableFiles) >= partitionSize { - table := &Table{ + group := &FileGroup{ UUID: uuid.NewV4(), Db: dbInfo, Schema: tableInfo, Files: tableFiles, } - addTableToDb(table) + db.FileGroups = append(db.FileGroups, group) tableFiles = make([]*FilePair, 0) } } } if len(tableFiles) > 0 { - table := &Table{ + group := &FileGroup{ UUID: uuid.NewV4(), Db: dbInfo, Schema: tableInfo, Files: tableFiles, } - addTableToDb(table) + db.FileGroups = append(db.FileGroups, group) } } log.Info("load databases", zap.Reflect("db", databases)) From e6c75421c612581bd005e576b5c35c2b24a91d12 Mon Sep 17 00:00:00 2001 From: 5kbpers Date: Mon, 16 Sep 2019 22:23:49 +0800 Subject: [PATCH 04/11] format code Signed-off-by: 5kbpers --- cmd/restore.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/restore.go b/cmd/restore.go index 489e6a223bc00..b1c43c5619bdb 100644 --- a/cmd/restore.go +++ b/cmd/restore.go @@ -3,6 +3,8 @@ package cmd import ( "context" "fmt" + "io/ioutil" + "github.com/gogo/protobuf/proto" "github.com/pingcap/br/pkg/restore" "github.com/pingcap/errors" @@ -10,7 +12,6 @@ import ( "github.com/pingcap/kvproto/pkg/import_sstpb" "github.com/spf13/cobra" flag "github.com/spf13/pflag" - "io/ioutil" ) // NewRestoreCommand returns a restore subcommand From 608e34e4e182acfac7a20286662439a2c0050508 Mon Sep 17 00:00:00 2001 From: 5kbpers Date: Sun, 29 Sep 2019 17:28:21 +0800 Subject: [PATCH 05/11] add a test for Alter AutoIncID Signed-off-by: 5kbpers --- go.mod | 3 +- go.sum | 6 ++ pkg/restore/schema_test.go | 195 +++++++++++++++++++++++++++++++++++++ 3 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 pkg/restore/schema_test.go diff --git a/go.mod b/go.mod index f4e105ab7be30..91f98a49af949 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/pingcap/br go 1.12 require ( + github.com/beorn7/perks v1.0.1 // indirect github.com/coreos/go-semver v0.3.0 // indirect github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect github.com/cznic/sortutil v0.0.0-20181122101858-f5f958428db8 // indirect @@ -27,7 +28,7 @@ require ( github.com/pingcap/parser v0.0.0-20190912032624-978b8272c04e github.com/pingcap/pd v0.0.0-20190806095100-82f1dd11d823 github.com/pingcap/tidb v0.0.0-20190912055946-5c48d93368d4 - github.com/prometheus/client_golang v1.1.0 + github.com/prometheus/client_golang v0.9.0 github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 // indirect github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237 // indirect github.com/sirupsen/logrus v1.4.2 // indirect diff --git a/go.sum b/go.sum index b04e811fecf27..af87ec4752ba2 100644 --- a/go.sum +++ b/go.sum @@ -11,6 +11,7 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/blacktear23/go-proxyprotocol v0.0.0-20180807104634-af7a81e8dd0d h1:rQlvB2AYWme2bIB18r/SipGiMEVJYE9U0z+MGoU/LtQ= github.com/blacktear23/go-proxyprotocol v0.0.0-20180807104634-af7a81e8dd0d/go.mod h1:VKt7CNAQxpFpSDz3sXyj9hY/GbVsQCr0sB3w59nE7lU= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20171208011716-f6d7a1f6fbf3/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= @@ -228,6 +229,7 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_golang v0.9.0 h1:tXuTFVHC03mW0D+Ua1Q2d1EAVqLTuggX50V0VLICCzY= github.com/prometheus/client_golang v0.9.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= @@ -240,11 +242,13 @@ github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1: github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20180518154759-7600349dcfe1/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/common v0.0.0-20181020173914-7e9e6cabbd39 h1:Cto4X6SVMWRPBkJ/3YHn1iDGDGc/Z+sW+AEMKHMVvN4= github.com/prometheus/common v0.0.0-20181020173914-7e9e6cabbd39/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.6.0 h1:kRhiuYSXR3+uv2IbVbZhUxK5zVD/2pp3Gd2PpvPkpEo= github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= github.com/prometheus/procfs v0.0.0-20180612222113-7d6f385de8be/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d h1:GoAlyOgbOEIFdaDqxJVlbOQ1DtGmZWs/Qau0hIlk+WQ= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURmKE= @@ -287,6 +291,7 @@ github.com/struCoder/pidusage v0.1.2/go.mod h1:pWBlW3YuSwRl6h7R5KbvA4N8oOqe9LjaK github.com/syndtr/goleveldb v0.0.0-20180815032940-ae2bd5eed72d/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0= github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= +github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2 h1:mbAskLJ0oJfDRtkanvQPiooDH8HvJ2FBh+iKT/OmiQQ= github.com/tiancaiamao/appdash v0.0.0-20181126055449-889f96f722a2/go.mod h1:2PfKggNGDuadAa0LElHrByyrz4JPZ9fFx6Gs7nx7ZZU= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20171017195756-830351dc03c6/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= @@ -430,4 +435,5 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= sourcegraph.com/sourcegraph/appdash v0.0.0-20180531100431-4c381bd170b4 h1:VO9oZbbkvTwqLimlQt15QNdOOBArT2dw/bvzsMZBiqQ= sourcegraph.com/sourcegraph/appdash v0.0.0-20180531100431-4c381bd170b4/go.mod h1:hI742Nqp5OhwiqlzhgfbWU4mW4yO10fP+LoT9WOswdU= +sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 h1:e1sMhtVq9AfcEy8AXNb8eSg6gbzfdpYhoNqnPJa+GzI= sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67/go.mod h1:L5q+DGLGOQFpo1snNEkLOJT2d1YTW66rWNzatr3He1k= diff --git a/pkg/restore/schema_test.go b/pkg/restore/schema_test.go new file mode 100644 index 0000000000000..9294b044c33a9 --- /dev/null +++ b/pkg/restore/schema_test.go @@ -0,0 +1,195 @@ +package restore + +import ( + "database/sql" + "flag" + "fmt" + "github.com/go-sql-driver/mysql" + "github.com/pingcap/parser/model" + "io/ioutil" + "math" + "net/http" + "strconv" + "testing" + "time" + + . "github.com/pingcap/check" + "github.com/pingcap/log" + "github.com/pingcap/tidb/config" + "github.com/pingcap/tidb/domain" + "github.com/pingcap/tidb/kv" + "github.com/pingcap/tidb/meta/autoid" + "github.com/pingcap/tidb/server" + "github.com/pingcap/tidb/session" + "github.com/pingcap/tidb/store/mockstore" + "github.com/pingcap/tidb/store/mockstore/mocktikv" + "github.com/pingcap/tidb/util/testkit" + "github.com/pingcap/tidb/util/testleak" + "go.uber.org/zap" +) + +var _ = Suite(&testRestoreSchemaSuite{}) + +type testRestoreSchemaSuite struct { + server *server.Server + cluster *mocktikv.Cluster + mvccStore mocktikv.MVCCStore + store kv.Storage + tidbdrv *server.TiDBDriver + dom *domain.Domain +} + +func TestT(t *testing.T) { + TestingT(t) +} + +var mockTikv = flag.Bool("mockTikv", true, "use mock tikv store in executor test") + +func (s *testRestoreSchemaSuite) SetUpSuite(c *C) { + flag.Lookup("mockTikv") + useMockTikv := *mockTikv + if useMockTikv { + s.cluster = mocktikv.NewCluster() + mocktikv.BootstrapWithSingleStore(s.cluster) + s.mvccStore = mocktikv.MustNewMVCCStore() + store, err := mockstore.NewMockTikvStore( + mockstore.WithCluster(s.cluster), + mockstore.WithMVCCStore(s.mvccStore), + ) + c.Assert(err, IsNil) + s.store = store + session.SetSchemaLease(0) + session.DisableStats4Test() + } + var err error + s.dom, err = session.BootstrapSession(s.store) + c.Assert(err, IsNil) +} + +func (s *testRestoreSchemaSuite) TearDownSuite(c *C) { + testleak.AfterTest(c)() +} + +func (s *testRestoreSchemaSuite) startServer(c *C) { + mvccStore := mocktikv.MustNewMVCCStore() + var err error + s.store, err = mockstore.NewMockTikvStore(mockstore.WithMVCCStore(mvccStore)) + c.Assert(err, IsNil) + s.dom, err = session.BootstrapSession(s.store) + c.Assert(err, IsNil) + s.tidbdrv = server.NewTiDBDriver(s.store) + + cfg := config.NewConfig() + cfg.Port = 4001 + cfg.Store = "tikv" + cfg.Status.StatusPort = 10090 + cfg.Status.ReportStatus = true + + server, err := server.NewServer(cfg, s.tidbdrv) + c.Assert(err, IsNil) + s.server = server + go server.Run() + waitUntilServerOnline(cfg.Status.StatusPort) +} + +func (s *testRestoreSchemaSuite) stopServer(c *C) { + if s.dom != nil { + s.dom.Close() + } + if s.store != nil { + s.store.Close() + } + if s.server != nil { + s.server.Close() + } +} + +func (s *testRestoreSchemaSuite) TestRestoreAutoIncID(c *C) { + s.startServer(c) + defer s.stopServer(c) + + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t;") + tk.MustExec("create table t (a int);") + tk.MustExec("insert into t values (10);") + + // Query the current AutoIncID + autoIncID, err := strconv.ParseUint(tk.MustQuery("admin show t next_row_id").Rows()[0][3].(string), 10, 64) + c.Assert(err, IsNil, Commentf("Error query auto inc id: %s", err)) + + // Get schemas of db and table + info, err := s.dom.GetSnapshotInfoSchema(math.MaxUint64) + c.Assert(err, IsNil, Commentf("Error get snapshot info schema: %s", err)) + dbInfo, exists := info.SchemaByName(model.NewCIStr("test")) + c.Assert(exists, IsTrue, Commentf("Error get db info")) + tableInfo, err := info.TableByName(model.NewCIStr("test"), model.NewCIStr("t")) + c.Assert(err, IsNil, Commentf("Error get table info: %s", err)) + + // Get the next AutoIncID + idAlloc := autoid.NewAllocator(s.store, dbInfo.ID, false) + globalAutoID, err := idAlloc.NextGlobalAutoID(tableInfo.Meta().ID) + c.Assert(err, IsNil, Commentf("Error allocate next auto id")) + c.Assert(autoIncID == uint64(globalAutoID), IsTrue, Commentf("Error wrong next auto id: autoIncID=%d, globalAutoID=%d", autoIncID, globalAutoID)) + + // Alter AutoIncID to the next AutoIncID + 100 + tableInfo.Meta().AutoIncID = globalAutoID + 100 + err = AlterAutoIncID("test", tableInfo.Meta(), "root@tcp(127.0.0.1:4001)/") + c.Assert(err, IsNil, Commentf("Error alter auto inc id: %s", err)) + + // Check if AutoIncID is altered successfully + autoIncID, err = strconv.ParseUint(tk.MustQuery("admin show t next_row_id").Rows()[0][3].(string), 10, 64) + c.Assert(err, IsNil, Commentf("Error query auto inc id: %s", err)) + c.Assert(autoIncID == uint64(globalAutoID + 100), IsTrue, Commentf("Error alter auto inc id: autoIncID=%d, globalAutoID=%d", autoIncID, globalAutoID)) +} + +type configOverrider func(*mysql.Config) + +const retryTime = 100 + +var defaultDSNConfig = mysql.Config{ + User: "root", + Net: "tcp", + Addr: "127.0.0.1:4001", +} + +// getDSN generates a DSN string for MySQL connection. +func getDSN(overriders ...configOverrider) string { + var cfg = defaultDSNConfig + for _, overrider := range overriders { + if overrider != nil { + overrider(&cfg) + } + } + return cfg.FormatDSN() +} + +func waitUntilServerOnline(statusPort uint) { + // connect server + retry := 0 + for ; retry < retryTime; retry++ { + time.Sleep(time.Millisecond * 10) + db, err := sql.Open("mysql", getDSN()) + if err == nil { + db.Close() + break + } + } + if retry == retryTime { + log.Fatal("failed to connect DB in every 10 ms", zap.Int("retryTime", retryTime)) + } + // connect http status + statusURL := fmt.Sprintf("http://127.0.0.1:%d/status", statusPort) + for retry = 0; retry < retryTime; retry++ { + resp, err := http.Get(statusURL) + if err == nil { + ioutil.ReadAll(resp.Body) + resp.Body.Close() + break + } + time.Sleep(time.Millisecond * 10) + } + if retry == retryTime { + log.Fatal("failed to connect HTTP status in every 10 ms", zap.Int("retryTime", retryTime)) + } +} From 1694bc21c3da67690d1255cd0440d3c0f02b926d Mon Sep 17 00:00:00 2001 From: 5kbpers Date: Sun, 29 Sep 2019 17:33:18 +0800 Subject: [PATCH 06/11] format Signed-off-by: 5kbpers --- go.sum | 35 +++-------------------------------- pkg/restore/schema_test.go | 14 +++++++------- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/go.sum b/go.sum index af87ec4752ba2..e94a16b50d9dd 100644 --- a/go.sum +++ b/go.sum @@ -3,11 +3,9 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f h1:5ZfJxyXo8KyX8DgGXC5B7ILL8y51fci/qYz2B4j8iLY= github.com/StackExchange/wmi v0.0.0-20180725035823-b12b22c5341f/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= @@ -60,19 +58,14 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ERFA1PUxfmGpolnw2v0bKOREu5ew= github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32/go.mod h1:GIjDIg/heH5DOkXY3YJ/wNhfHsQHoXGjl8G8amsYQ1I= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= github.com/go-playground/overalls v0.0.0-20180201144345-22ec1a223b7c/go.mod h1:UqxAgEOt89sCiXlrc/ycnx00LVvUO/eS8tMUkWX4R7w= github.com/go-sql-driver/mysql v0.0.0-20170715192408-3955978caca4/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/gogo/protobuf v0.0.0-20180717141946-636bf0302bc9/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.0.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= -github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE= github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= @@ -96,8 +89,6 @@ github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Z github.com/google/btree v1.0.0 h1:0udJVsspx3VBr5FwtLhQQtuAsVc79tTq0ocGIPAU6qo= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE= github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= @@ -127,12 +118,10 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jonboulle/clockwork v0.1.0 h1:VKV+ZcuP6l3yW9doeqz6ziZGgcynBVQO+obU0+0hcPo= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= +github.com/json-iterator/go v1.1.6 h1:MrUvLMLTMxbqFJ9kzlvat/rYZqZnW3u4wkLzWTaFwKs= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.7 h1:KfgG9LzI+pYjr4xvmz/5H4FXjokeP+rlHLhv3iH62Fo= -github.com/json-iterator/go v1.1.7/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/juju/ratelimit v1.0.1 h1:+7AIFJVQ0EQgq/K9+0Krm7m530Du7tIz0METWzN0RgY= github.com/juju/ratelimit v1.0.1/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5 h1:2U0HzY8BJ8hVwDKIzp7y4voR9CX/nvcfymLmg2UiOio= @@ -140,7 +129,6 @@ github.com/klauspost/cpuid v0.0.0-20170728055534-ae7887de9fa5/go.mod h1:Pj4uuM52 github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.0.0/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -157,17 +145,14 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0j github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/montanaflynn/stats v0.0.0-20151014174947-eeaced052adb/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/montanaflynn/stats v0.0.0-20180911141734-db72e6cae808/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/montanaflynn/stats v0.5.0 h1:2EkzeTSqBB4V4bJwWrt5gIIrZmpJBcoIRGS2kWLgzmk= github.com/montanaflynn/stats v0.5.0/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/myesui/uuid v1.0.0 h1:xCBmH4l5KuvLYc5L7AS7SZg9/jKdIFubM7OVoLqaQUI= github.com/myesui/uuid v1.0.0/go.mod h1:2CDfNgU0LR8mIdO8vdWd8i9gWWxLlcoIGGpSNgafq84= github.com/ngaut/pools v0.0.0-20180318154953-b7bc8c42aac7 h1:7KAv7KMGTTqSmYZtNdcNTgsos+vFzULLwyElndwn+5c= @@ -231,28 +216,17 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.0 h1:tXuTFVHC03mW0D+Ua1Q2d1EAVqLTuggX50V0VLICCzY= github.com/prometheus/client_golang v0.9.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.1.0 h1:BQ53HtBmfOitExawJ6LokA4x8ov/z0SYYb0+HxJfRI8= -github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g= github.com/prometheus/client_model v0.0.0-20170216185247-6f3806018612/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20171117100541-99fa1f4be8e5/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/prometheus/common v0.0.0-20180518154759-7600349dcfe1/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= github.com/prometheus/common v0.0.0-20181020173914-7e9e6cabbd39 h1:Cto4X6SVMWRPBkJ/3YHn1iDGDGc/Z+sW+AEMKHMVvN4= github.com/prometheus/common v0.0.0-20181020173914-7e9e6cabbd39/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= -github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.6.0 h1:kRhiuYSXR3+uv2IbVbZhUxK5zVD/2pp3Gd2PpvPkpEo= -github.com/prometheus/common v0.6.0/go.mod h1:eBmuwkDJBwy6iBfxCBob6t6dR6ENT/y+J+Zk0j9GMYc= github.com/prometheus/procfs v0.0.0-20180612222113-7d6f385de8be/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d h1:GoAlyOgbOEIFdaDqxJVlbOQ1DtGmZWs/Qau0hIlk+WQ= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.0.3 h1:CTwfnzjQ+8dS6MhHHu4YswVAD99sL2wjPqP+VkURmKE= -github.com/prometheus/procfs v0.0.3/go.mod h1:4A/X28fw3Fc593LaREMrKMqOKvUAntwMDaekg4FpcdQ= github.com/remyoudompheng/bigfft v0.0.0-20190512091148-babf20351dd7/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237 h1:HQagqIiBmr8YXawX/le3+O26N+vPPC1PtjaF3mwnook= github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= @@ -261,7 +235,9 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR github.com/sergi/go-diff v1.0.1-0.20180205163309-da645544ed44/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/shirou/gopsutil v2.18.10+incompatible h1:cy84jW6EVRPa5g9HAHrlbxMSIjBhDSX0OFYyMYminYs= github.com/shirou/gopsutil v2.18.10+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371 h1:SWV2fHctRpRrp49VXJ6UZja7gU9QLHwRpIPBN89SKEo= github.com/shurcooL/httpfs v0.0.0-20171119174359-809beceb2371/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg= +github.com/shurcooL/vfsgen v0.0.0-20181020040650-a97a25d856ca h1:3fECS8atRjByijiI8yYiuwLwQ2ZxXobW7ua/8GRB3pI= github.com/shurcooL/vfsgen v0.0.0-20181020040650-a97a25d856ca/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw= github.com/sirupsen/logrus v1.0.5/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= @@ -350,13 +326,11 @@ golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73r golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190909003024-a7b16738d86b h1:XfVGCX+0T4WOStkaOsJRllbsiImhB2jgVBGc9L0lPGc= golang.org/x/net v0.0.0-20190909003024-a7b16738d86b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -369,13 +343,11 @@ golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190910064555-bbd175535a8b h1:3S2h5FadpNr0zUUCVZjlKIEYF+KaX/OBplTGo89CYHI= golang.org/x/sys v0.0.0-20190910064555-bbd175535a8b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -411,7 +383,6 @@ google.golang.org/grpc v1.23.0 h1:AzbTB6ux+okLTzP8Ru1Xs41C303zdcfEht7MQnYJt5A= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U= gopkg.in/alecthomas/gometalinter.v2 v2.0.12/go.mod h1:NDRytsqEZyolNuAgTzJkZMkSQM7FIKyzVzGhjB/qfYo= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c/go.mod h1:3HH7i1SgMqlzxCcBmUHW657sD4Kvv9sC3HpL3YukzwA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= diff --git a/pkg/restore/schema_test.go b/pkg/restore/schema_test.go index 9294b044c33a9..9f243c3a2fc80 100644 --- a/pkg/restore/schema_test.go +++ b/pkg/restore/schema_test.go @@ -85,10 +85,10 @@ func (s *testRestoreSchemaSuite) startServer(c *C) { cfg.Status.StatusPort = 10090 cfg.Status.ReportStatus = true - server, err := server.NewServer(cfg, s.tidbdrv) + svr, err := server.NewServer(cfg, s.tidbdrv) c.Assert(err, IsNil) - s.server = server - go server.Run() + s.server = svr + go svr.Run() waitUntilServerOnline(cfg.Status.StatusPort) } @@ -140,7 +140,7 @@ func (s *testRestoreSchemaSuite) TestRestoreAutoIncID(c *C) { // Check if AutoIncID is altered successfully autoIncID, err = strconv.ParseUint(tk.MustQuery("admin show t next_row_id").Rows()[0][3].(string), 10, 64) c.Assert(err, IsNil, Commentf("Error query auto inc id: %s", err)) - c.Assert(autoIncID == uint64(globalAutoID + 100), IsTrue, Commentf("Error alter auto inc id: autoIncID=%d, globalAutoID=%d", autoIncID, globalAutoID)) + c.Assert(autoIncID == uint64(globalAutoID+100), IsTrue, Commentf("Error alter auto inc id: autoIncID=%d, globalAutoID=%d", autoIncID, globalAutoID)) } type configOverrider func(*mysql.Config) @@ -148,9 +148,9 @@ type configOverrider func(*mysql.Config) const retryTime = 100 var defaultDSNConfig = mysql.Config{ - User: "root", - Net: "tcp", - Addr: "127.0.0.1:4001", + User: "root", + Net: "tcp", + Addr: "127.0.0.1:4001", } // getDSN generates a DSN string for MySQL connection. From c6b8cfd16ec637e14f9db6d23830db3f25eac560 Mon Sep 17 00:00:00 2001 From: 5kbpers Date: Sun, 29 Sep 2019 17:41:59 +0800 Subject: [PATCH 07/11] format Signed-off-by: 5kbpers --- cmd/raw.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/raw.go b/cmd/raw.go index fd4cf7b075b7a..5e76124b3f39c 100644 --- a/cmd/raw.go +++ b/cmd/raw.go @@ -62,8 +62,8 @@ func newFullBackupCommand() *cobra.Command { if concurrency == 0 { return errors.New("at least one thread required") } - - err = client.BackupAllSchemas(backupTS) + + err = client.BackupAllSchemas(backupTS) if err != nil { return err } From 7579799b753e077ecb06038a332f425b542fe71f Mon Sep 17 00:00:00 2001 From: 5kbpers Date: Mon, 30 Sep 2019 11:36:24 +0800 Subject: [PATCH 08/11] re-group import items Signed-off-by: 5kbpers --- pkg/restore/client.go | 4 +++- pkg/restore/schema_test.go | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/restore/client.go b/pkg/restore/client.go index 6e6e0124b2c8a..d4f70de4bdc1a 100644 --- a/pkg/restore/client.go +++ b/pkg/restore/client.go @@ -2,7 +2,10 @@ package restore import ( "context" + "strings" + "github.com/pingcap/br/pkg/meta" + "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/backup" "github.com/pingcap/kvproto/pkg/import_kvpb" @@ -11,7 +14,6 @@ import ( pd "github.com/pingcap/pd/client" "go.uber.org/zap" "google.golang.org/grpc" - "strings" ) // Client sends requests to importer to restore files diff --git a/pkg/restore/schema_test.go b/pkg/restore/schema_test.go index 9f243c3a2fc80..33225a06dd37a 100644 --- a/pkg/restore/schema_test.go +++ b/pkg/restore/schema_test.go @@ -4,8 +4,6 @@ import ( "database/sql" "flag" "fmt" - "github.com/go-sql-driver/mysql" - "github.com/pingcap/parser/model" "io/ioutil" "math" "net/http" @@ -13,8 +11,10 @@ import ( "testing" "time" + "github.com/go-sql-driver/mysql" . "github.com/pingcap/check" "github.com/pingcap/log" + "github.com/pingcap/parser/model" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/kv" From d779eecc15ae637e023d74f5895b0eefdfa94e11 Mon Sep 17 00:00:00 2001 From: 5kbpers <20279863+5kbpers@users.noreply.github.com> Date: Mon, 30 Sep 2019 16:21:17 +0800 Subject: [PATCH 09/11] Apply suggestions from code review Co-Authored-By: kennytm --- cmd/restore.go | 4 +-- pkg/raw/full.go | 8 ++--- pkg/restore/client.go | 60 +++++++++++++++++++------------------- pkg/restore/schema.go | 2 +- pkg/restore/schema_test.go | 4 +-- 5 files changed, 39 insertions(+), 39 deletions(-) diff --git a/cmd/restore.go b/cmd/restore.go index b1c43c5619bdb..7d59edb4bfe6f 100644 --- a/cmd/restore.go +++ b/cmd/restore.go @@ -187,7 +187,7 @@ func newTableRestoreCommand() *cobra.Command { } table := db.GetTable(tableName) if table == nil { - return errors.Trace(fmt.Errorf("not exists table")) + return errors.New("not exists table") } err = restore.CreateTable(db.Schema.Name.String(), table, client.GetDbDSN()) if err != nil { @@ -199,7 +199,7 @@ func newTableRestoreCommand() *cobra.Command { } fileGroups := db.GetFileGroups(tableName) if len(fileGroups) <= 0 { - return errors.Trace(fmt.Errorf("not exists table")) + return errors.New("not exists table") } err = client.RestoreMultipleTables(fileGroups, restoreTS) return errors.Trace(err) diff --git a/pkg/raw/full.go b/pkg/raw/full.go index 7addf88678d35..22eeeae19311f 100644 --- a/pkg/raw/full.go +++ b/pkg/raw/full.go @@ -160,8 +160,8 @@ func (bc *BackupClient) BackupTable( Table: tableData, } log.Info("save table schema", - zap.String("db", dbInfo.Name.String()), - zap.String("table", tableInfo.Name.String()), + zap.Stringer("db", dbInfo.Name), + zap.Stringer("table", tableInfo.Name), zap.Int64("auto_inc_id", globalAutoID), ) bc.backupMeta.Schemas = append(bc.backupMeta.Schemas, backupSchema) @@ -259,8 +259,8 @@ LoadDb: Table: tableData, } log.Info("save table schema", - zap.String("db", dbInfo.Name.String()), - zap.String("table", tableInfo.Name.String()), + zap.Stringer("db", dbInfo.Name), + zap.Stringer("table", tableInfo.Name), zap.Int64("auto_inc_id", globalAutoID), ) bc.backupMeta.Schemas = append(bc.backupMeta.Schemas, backupSchema) diff --git a/pkg/restore/client.go b/pkg/restore/client.go index d4f70de4bdc1a..5d0011511de9f 100644 --- a/pkg/restore/client.go +++ b/pkg/restore/client.go @@ -131,9 +131,9 @@ func (rc *Client) GetDatabase(name string) *Database { // UploadTableFiles executes the job to restore files of a table func (rc *Client) UploadTableFiles(client import_kvpb.ImportKVClient, group *FileGroup, restoreTS uint64) error { log.Info("start to upload files of group", - zap.String("group", group.Schema.Name.String()), - zap.String("uuid", group.UUID.String()), - zap.String("db", group.Db.Name.String()), + zap.Stringer("group", group.Schema.Name), + zap.Stringer("uuid", group.UUID), + zap.Stringer("db", group.Db.Name), ) tableInfo, returnErr := FetchTableInfo(rc.statusAddr, group.Db.Name.String(), group.Schema.Name.String()) @@ -146,9 +146,9 @@ func (rc *Client) UploadTableFiles(client import_kvpb.ImportKVClient, group *Fil if returnErr != nil { log.Error("open engine failed", zap.Uint64("restore_ts", restoreTS), - zap.String("group", group.Schema.Name.String()), - zap.String("uuid", group.UUID.String()), - zap.String("db", group.Db.Name.String()), + zap.Stringer("group", group.Schema.Name), + zap.Stringer("uuid", group.UUID), + zap.Stringer("db", group.Db.Name), ) return errors.Trace(returnErr) } @@ -175,8 +175,8 @@ func (rc *Client) UploadTableFiles(client import_kvpb.ImportKVClient, group *Fil log.Error("restore file failed", zap.Reflect("file", file), zap.Uint64("restore_ts", restoreTS), - zap.String("group", group.Schema.Name.String()), - zap.String("db", group.Db.Name.String()), + zap.Stringer("group", group.Schema.Name), + zap.Stringer("db", group.Db.Name), zap.Error(errors.Trace(err)), ) errCh <- errors.Trace(err) @@ -189,8 +189,8 @@ func (rc *Client) UploadTableFiles(client import_kvpb.ImportKVClient, group *Fil log.Debug("restore file success", zap.Reflect("file", file), zap.Uint64("restore_ts", restoreTS), - zap.String("group", group.Schema.Name.String()), - zap.String("db", group.Db.Name.String()), + zap.Stringer("group", group.Schema.Name), + zap.Stringer("db", group.Db.Name), ) errCh <- nil }(file) @@ -211,18 +211,18 @@ func (rc *Client) UploadTableFiles(client import_kvpb.ImportKVClient, group *Fil if returnErr != nil { log.Error("close engine failed", zap.Uint64("restore_ts", restoreTS), - zap.String("group", group.Schema.Name.String()), - zap.String("uuid", group.UUID.String()), - zap.String("db", group.Db.Name.String()), + zap.Stringer("group", group.Schema.Name), + zap.Stringer("uuid", group.UUID), + zap.Stringer("db", group.Db.Name), ) return errors.Trace(returnErr) } log.Info("upload group files finished", zap.Uint64("restore_ts", restoreTS), - zap.String("group", group.Schema.Name.String()), - zap.String("uuid", group.UUID.String()), - zap.String("db", group.Db.Name.String()), + zap.Stringer("group", group.Schema.Name), + zap.Stringer("uuid", group.UUID), + zap.Stringer("db", group.Db.Name), ) return errors.Trace(returnErr) @@ -257,7 +257,7 @@ func (rc *Client) RestoreMultipleTables(groups []*FileGroup, restoreTS uint64) e for j := 0; j < rc.maxOpenEngines; j++ { go func(client import_kvpb.ImportKVClient, n int) { for job := range uploadJobCh { - log.Info("restore table", zap.Int("importer", n), zap.String("uuid", job.Group.UUID.String())) + log.Info("restore table", zap.Int("importer", n), zap.Stringer("uuid", job.Group.UUID)) err := rc.UploadTableFiles(client, job.Group, restoreTS) if err != nil { errCh <- errors.Trace(err) @@ -278,17 +278,17 @@ func (rc *Client) RestoreMultipleTables(groups []*FileGroup, restoreTS uint64) e group := job.Group log.Info("start to import group", zap.Uint64("restore_ts", restoreTS), - zap.String("group", group.Schema.Name.String()), - zap.String("uuid", group.UUID.String()), - zap.String("db", group.Db.Name.String()), + zap.Stringer("group", group.Schema.Name), + zap.Stringer("uuid", group.UUID), + zap.Stringer("db", group.Db.Name), ) err := rc.ImportEngine(job.Client, group.UUID.Bytes()) if err != nil { log.Error("import engine failed", zap.Uint64("restore_ts", restoreTS), - zap.String("group", group.Schema.Name.String()), - zap.String("uuid", group.UUID.String()), - zap.String("db", group.Db.Name.String()), + zap.Stringer("group", group.Schema.Name), + zap.Stringer("uuid", group.UUID), + zap.Stringer("db", group.Db.Name), zap.Error(err), ) errCh <- errors.Trace(err) @@ -298,9 +298,9 @@ func (rc *Client) RestoreMultipleTables(groups []*FileGroup, restoreTS uint64) e if err != nil { log.Error("cleanup engine failed", zap.Uint64("restore_ts", restoreTS), - zap.String("group", group.Schema.Name.String()), - zap.String("uuid", group.UUID.String()), - zap.String("db", group.Db.Name.String()), + zap.Stringer("group", group.Schema.Name), + zap.Stringer("uuid", group.UUID), + zap.Stringer("db", group.Db.Name), zap.Error(err), ) errCh <- errors.Trace(err) @@ -308,9 +308,9 @@ func (rc *Client) RestoreMultipleTables(groups []*FileGroup, restoreTS uint64) e } log.Info("import group finished", zap.Uint64("restore_ts", restoreTS), - zap.String("group", group.Schema.Name.String()), - zap.String("uuid", group.UUID.String()), - zap.String("db", group.Db.Name.String()), + zap.Stringer("group", group.Schema.Name), + zap.Stringer("uuid", group.UUID), + zap.Stringer("db", group.Db.Name), ) errCh <- nil } @@ -359,7 +359,7 @@ func (rc *Client) RestoreDatabase(db *Database, restoreTS uint64) error { if returnErr == nil { log.Info("restore database finished", zap.Uint64("restore_ts", restoreTS), - zap.String("db", db.Schema.Name.String()), + zap.Stringer("db", db.Schema.Name), ) } return errors.Trace(returnErr) diff --git a/pkg/restore/schema.go b/pkg/restore/schema.go index 06a4368361ac3..8da4df04ec7e5 100644 --- a/pkg/restore/schema.go +++ b/pkg/restore/schema.go @@ -131,7 +131,7 @@ func AlterAutoIncID(dbName string, table *model.TableInfo, dsn string) error { return errors.Trace(err) } log.Info("alter auto inc id", - zap.String("table", table.Name.String()), + zap.Stringer("table", table.Name), zap.String("db", dbName), zap.Int64("auto_inc_id", table.AutoIncID), ) diff --git a/pkg/restore/schema_test.go b/pkg/restore/schema_test.go index 33225a06dd37a..313f8fd7cc202 100644 --- a/pkg/restore/schema_test.go +++ b/pkg/restore/schema_test.go @@ -130,7 +130,7 @@ func (s *testRestoreSchemaSuite) TestRestoreAutoIncID(c *C) { idAlloc := autoid.NewAllocator(s.store, dbInfo.ID, false) globalAutoID, err := idAlloc.NextGlobalAutoID(tableInfo.Meta().ID) c.Assert(err, IsNil, Commentf("Error allocate next auto id")) - c.Assert(autoIncID == uint64(globalAutoID), IsTrue, Commentf("Error wrong next auto id: autoIncID=%d, globalAutoID=%d", autoIncID, globalAutoID)) + c.Assert(autoIncID, Equals, uint64(globalAutoID)) // Alter AutoIncID to the next AutoIncID + 100 tableInfo.Meta().AutoIncID = globalAutoID + 100 @@ -140,7 +140,7 @@ func (s *testRestoreSchemaSuite) TestRestoreAutoIncID(c *C) { // Check if AutoIncID is altered successfully autoIncID, err = strconv.ParseUint(tk.MustQuery("admin show t next_row_id").Rows()[0][3].(string), 10, 64) c.Assert(err, IsNil, Commentf("Error query auto inc id: %s", err)) - c.Assert(autoIncID == uint64(globalAutoID+100), IsTrue, Commentf("Error alter auto inc id: autoIncID=%d, globalAutoID=%d", autoIncID, globalAutoID)) + c.Assert(autoIncID, Equals, uint64(globalAutoID+100)) } type configOverrider func(*mysql.Config) From d469c14a5ba76834e3e1af69641260a6433ad40b Mon Sep 17 00:00:00 2001 From: 5kbpers Date: Mon, 30 Sep 2019 17:56:37 +0800 Subject: [PATCH 10/11] address comments Signed-off-by: 5kbpers --- pkg/raw/full.go | 9 ++++++--- pkg/restore/schema.go | 20 ++++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/pkg/raw/full.go b/pkg/raw/full.go index 7addf88678d35..5bb1378d1461a 100644 --- a/pkg/raw/full.go +++ b/pkg/raw/full.go @@ -3,14 +3,15 @@ package raw import ( "context" "encoding/json" - "github.com/pingcap/tidb/meta/autoid" "io/ioutil" + "strings" "sync" "time" + "github.com/pingcap/tidb/meta/autoid" + "github.com/gogo/protobuf/proto" "github.com/google/btree" - "github.com/pingcap/br/pkg/meta" "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/backup" "github.com/pingcap/kvproto/pkg/metapb" @@ -24,6 +25,8 @@ import ( "github.com/pingcap/tidb/tablecodec" "github.com/pingcap/tidb/util/codec" "go.uber.org/zap" + + "github.com/pingcap/br/pkg/meta" ) // Maximum total sleep time(in ms) for kv/cop commands. @@ -234,7 +237,7 @@ LoadDb: for _, dbInfo := range dbInfos { // skip system databases for _, sysDbName := range SystemDatabases { - if sysDbName == dbInfo.Name.String() { + if strings.ToLower(sysDbName) == dbInfo.Name.L { continue LoadDb } } diff --git a/pkg/restore/schema.go b/pkg/restore/schema.go index 06a4368361ac3..8bb5b6c93bcaa 100644 --- a/pkg/restore/schema.go +++ b/pkg/restore/schema.go @@ -107,7 +107,7 @@ func AnalyzeTable(dbName string, table *model.TableInfo, dsn string) error { log.Error("open database failed", zap.String("addr", dbDSN), zap.Error(err)) return errors.Trace(err) } - analyzeSQL := fmt.Sprintf("ANALYZE TABLE %s", table.Name.String()) + analyzeSQL := fmt.Sprintf("ANALYZE TABLE %s", encloseName(table.Name.String())) _, err = db.Exec(analyzeSQL) if err != nil { log.Error("analyze table failed", zap.String("SQL", analyzeSQL), zap.String("db", dbName), zap.Error(err)) @@ -124,7 +124,7 @@ func AlterAutoIncID(dbName string, table *model.TableInfo, dsn string) error { log.Error("open database failed", zap.String("addr", dbDSN), zap.Error(err)) return errors.Trace(err) } - alterIDSQL := fmt.Sprintf("ALTER TABLE %s auto_increment = %d", table.Name.String(), table.AutoIncID) + alterIDSQL := fmt.Sprintf("ALTER TABLE %s auto_increment = %d", encloseName(table.Name.String()), table.AutoIncID) _, err = db.Exec(alterIDSQL) if err != nil { log.Error("alter auto inc id failed", zap.String("SQL", alterIDSQL), zap.String("db", dbName), zap.Error(err)) @@ -141,7 +141,7 @@ func AlterAutoIncID(dbName string, table *model.TableInfo, dsn string) error { // GetCreateDatabaseSQL generates a CREATE DATABASE SQL from DBInfo func GetCreateDatabaseSQL(db *model.DBInfo) string { var buf bytes.Buffer - fmt.Fprintf(&buf, "CREATE DATABASE IF NOT EXISTS %s", db.Name.String()) + fmt.Fprintf(&buf, "CREATE DATABASE IF NOT EXISTS %s", encloseName(db.Name.String())) fmt.Fprintf(&buf, " CHARACTER SET %s COLLATE %s", db.Charset, db.Collate) buf.WriteString(";") @@ -157,7 +157,7 @@ func GetCreateTableSQL(t *model.TableInfo) string { fmt.Fprintf(&buf, "CREATE TABLE IF NOT EXISTS %s (\n", t.Name) var pkCol *model.ColumnInfo for i, col := range t.Columns { - fmt.Fprintf(&buf, " %s %s", col.Name.String(), getColumnTypeDesc(col)) + fmt.Fprintf(&buf, " %s %s", encloseName(col.Name.String()), getColumnTypeDesc(col)) if col.Charset != "binary" { if col.Charset != tblCharset || col.Collate != tblCollate { fmt.Fprintf(&buf, " CHARACTER SET %s COLLATE %s", col.Charset, col.Collate) @@ -223,7 +223,7 @@ func GetCreateTableSQL(t *model.TableInfo) string { if pkCol != nil { // If PKIsHandle, pk info is not in tb.Indices(). We should handle it here. buf.WriteString(",\n") - fmt.Fprintf(&buf, " PRIMARY KEY (%s)", pkCol.Name.String()) + fmt.Fprintf(&buf, " PRIMARY KEY (%s)", encloseName(pkCol.Name.String())) } publicIndices := make([]*model.IndexInfo, 0, len(t.Indices)) @@ -240,9 +240,9 @@ func GetCreateTableSQL(t *model.TableInfo) string { if idx.Primary { buf.WriteString(" PRIMARY KEY ") } else if idx.Unique { - fmt.Fprintf(&buf, " UNIQUE KEY %s ", idx.Name.String()) + fmt.Fprintf(&buf, " UNIQUE KEY %s ", encloseName(idx.Name.String())) } else { - fmt.Fprintf(&buf, " KEY %s ", idx.Name.String()) + fmt.Fprintf(&buf, " KEY %s ", encloseName(idx.Name.String())) } cols := make([]string, 0, len(idx.Columns)) @@ -330,7 +330,7 @@ func appendPartitionInfo(partitionInfo *model.PartitionInfo, buf *bytes.Buffer) } for i, def := range partitionInfo.Definitions { lessThans := strings.Join(def.LessThan, ",") - fmt.Fprintf(buf, " PARTITION %s VALUES LESS THAN (%s)", def.Name, lessThans) + fmt.Fprintf(buf, " PARTITION %s VALUES LESS THAN (%s)", encloseName(def.Name.String()), lessThans) if i < len(partitionInfo.Definitions)-1 { buf.WriteString(",\n") } else { @@ -339,3 +339,7 @@ func appendPartitionInfo(partitionInfo *model.PartitionInfo, buf *bytes.Buffer) } buf.WriteString(")") } + +func encloseName(name string) string { + return "`" + strings.ReplaceAll(name, "`", "``") + "`" +} From fcb6c8d80333f82a0260f2c1da0e6fb97c274270 Mon Sep 17 00:00:00 2001 From: 5kbpers Date: Tue, 8 Oct 2019 10:10:51 +0800 Subject: [PATCH 11/11] address comments Signed-off-by: 5kbpers --- pkg/raw/full.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/raw/full.go b/pkg/raw/full.go index 833411fd71aca..295d5dcaf33c5 100644 --- a/pkg/raw/full.go +++ b/pkg/raw/full.go @@ -4,7 +4,6 @@ import ( "context" "encoding/json" "io/ioutil" - "strings" "sync" "time" @@ -217,8 +216,8 @@ func buildTableRanges(tbl *model.TableInfo) []tableRange { // BackupAllSchemas fetches all schemas from TiDB. func (bc *BackupClient) BackupAllSchemas(backupTS uint64) error { SystemDatabases := [3]string{ - "INFORMATION_SCHEMA", - "PERFORMANCE_SCHEMA", + "information_schema", + "performance_schema", "mysql", } @@ -237,7 +236,7 @@ LoadDb: for _, dbInfo := range dbInfos { // skip system databases for _, sysDbName := range SystemDatabases { - if strings.ToLower(sysDbName) == dbInfo.Name.L { + if sysDbName == dbInfo.Name.L { continue LoadDb } }