-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dumpling: improve error hint when fail to set snapshot in the incorrect consistency #40977
Merged
Merged
Changes from 2 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
deb3b3b
fix check has tikv problem
lichunzhu 69393bd
Merge branch 'master' into fix40932
lichunzhu 3fb858c
update bazel
lichunzhu 31c9acf
Merge branch 'fix40932' of https://github.com/lichunzhu/tidb into fix…
lichunzhu 8a9612b
tmp
lichunzhu da0f531
Revert "update bazel"
lichunzhu 1f5d1a5
revert changes
lichunzhu 9865695
revert changes
lichunzhu 7ed18cd
address comment
lichunzhu f64b74f
fix bazel
lichunzhu a7db1e7
Merge branch 'master' into fix40932
lichunzhu d2e3196
Merge branch 'master' into fix40932
ti-chi-bot d0f0204
Merge branch 'master' into fix40932
ti-chi-bot 0b5b9dd
Merge branch 'master' into fix40932
purelind 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
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
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 |
---|---|---|
|
@@ -827,13 +827,16 @@ func getSnapshot(db *sql.Conn) (string, error) { | |
return str[snapshotFieldIndex], nil | ||
} | ||
|
||
func isUnknownSystemVariableErr(err error) bool { | ||
return strings.Contains(err.Error(), "Unknown system variable") | ||
func isUnknownSystemVariableErr(err error, ignorableSnapshot bool) bool { | ||
errStr := err.Error() | ||
return strings.Contains(err.Error(), "Unknown system variable") || | ||
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. Another possible solution is to ignore all set session tidb_snapshot error when ignorableSnapshot is true. Because I'm not so sure whether tidb's error will change in the future or not. |
||
(ignorableSnapshot && strings.Contains(errStr, "can not get 'tikv_gc_safe_point'")) | ||
} | ||
|
||
// resetDBWithSessionParams will return a new sql.DB as a replacement for input `db` with new session parameters. | ||
// If returned error is nil, the input `db` will be closed. | ||
func resetDBWithSessionParams(tctx *tcontext.Context, db *sql.DB, cfg *mysql.Config, params map[string]interface{}) (*sql.DB, error) { | ||
func resetDBWithSessionParams(tctx *tcontext.Context, db *sql.DB, cfg *mysql.Config, | ||
params map[string]interface{}, ignorableSnapshot bool) (*sql.DB, error) { | ||
support := make(map[string]interface{}) | ||
for k, v := range params { | ||
var pv interface{} | ||
|
@@ -851,7 +854,7 @@ func resetDBWithSessionParams(tctx *tcontext.Context, db *sql.DB, cfg *mysql.Con | |
s := fmt.Sprintf("SET SESSION %s = ?", k) | ||
_, err := db.ExecContext(tctx, s, pv) | ||
if err != nil { | ||
if isUnknownSystemVariableErr(err) { | ||
if isUnknownSystemVariableErr(err, ignorableSnapshot) { | ||
tctx.L().Info("session variable is not supported by db", zap.String("variable", k), zap.Reflect("value", v)) | ||
continue | ||
} | ||
|
@@ -876,6 +879,9 @@ func resetDBWithSessionParams(tctx *tcontext.Context, db *sql.DB, cfg *mysql.Con | |
} | ||
cfg.Params[k] = s | ||
} | ||
failpoint.Inject("SkipResetDB", func(_ failpoint.Value) { | ||
failpoint.Return(db, nil) | ||
}) | ||
|
||
db.Close() | ||
c, err := mysql.NewConnector(cfg) | ||
|
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.
Here we can't distinguish the snapshot is set by user or dumpling?
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.
No we can't. But we can do this by check conf.Snapshot before adjusting.
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 for user specified snapshot, we can report the error that this TiDB can't set snapshot of that time. For dumpling's automatic snapshot we can fallback to no snapshot and also change the rebuild connection strategy to non-retryable.
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 it a second time. I think changing retry strategy is too complex. If we fail to set snapshot for ConsistencySnapshot, we can continue to ConsistencyNone or ConsistencyLock and notify the users in log. Or, we can directly return an error and give a proper prompt to users to notify them to manually switch consistency to none/lock instead of auto/snapshot. Changing retry strategy may confuse our users and is more difficult to maintain to me. WDYT? @lance6716
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.
yes a simple fix like automatically fallback to consistency none, or output a message is ok. Let's ask another reviewer @gozssky