This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
restore: fix error lost in create schema #530
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9d3d45f
restore: fix error lost in create schema
3pointer 4cf8d4f
add test
3pointer 8a27178
Merge branch 'master' into lost_err
glorv aa8de14
fix test
3pointer e75ceed
address comment
3pointer 449ed1a
Merge branch 'master' into lost_err
3pointer 5bea642
address comment
3pointer 9a62c40
address comment
3pointer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,13 @@ import ( | |
"context" | ||
"database/sql" | ||
"fmt" | ||
"sort" | ||
"strconv" | ||
"strings" | ||
|
||
tmysql "github.com/go-sql-driver/mysql" | ||
"github.com/pingcap/errors" | ||
"github.com/pingcap/failpoint" | ||
"github.com/pingcap/parser" | ||
"github.com/pingcap/parser/ast" | ||
"github.com/pingcap/parser/format" | ||
|
@@ -154,7 +156,15 @@ func InitSchema(ctx context.Context, g glue.Glue, database string, tablesSchema | |
|
||
task := logger.Begin(zap.InfoLevel, "create tables") | ||
var sqlCreateStmts []string | ||
for tbl, sqlCreateTable := range tablesSchema { | ||
tables := make([]string, 0, len(tablesSchema)) | ||
for tbl := range tablesSchema { | ||
tables = append(tables, tbl) | ||
} | ||
// sort tables for failpoint test | ||
sort.Strings(tables) | ||
loopCreate: | ||
for i, tbl := range tables { | ||
sqlCreateTable := tablesSchema[tbl] | ||
task.Debug("create table", zap.String("schema", sqlCreateTable)) | ||
|
||
sqlCreateStmts, err = createTableIfNotExistsStmt(g.GetParser(), sqlCreateTable, database, tbl) | ||
|
@@ -170,8 +180,15 @@ func InitSchema(ctx context.Context, g glue.Glue, database string, tablesSchema | |
"create table", | ||
logger.With(zap.String("table", common.UniqueTable(database, tbl))), | ||
) | ||
failpoint.Inject("sqlCreateStmts", func() { | ||
if i == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the count matters, I think you can add an int parameter to this fail-point to determine at which condition, it should return an error. So maybe we can test with the error returns at first, middle or last position. |
||
err = errors.Errorf("create %s failed", tbl) | ||
} else { | ||
err = nil | ||
kennytm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}) | ||
if err != nil { | ||
break | ||
break loopCreate | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better solution is to use regexp to match the execute result in failpoint test