-
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
sessionctx/binloginfo: fix uncomment pre_split_regions ddl-querys in binlog #11762
Conversation
/run-all-tests |
Codecov Report
@@ Coverage Diff @@
## master #11762 +/- ##
================================================
- Coverage 81.4796% 81.4506% -0.0291%
================================================
Files 434 434
Lines 93627 93475 -152
================================================
- Hits 76287 76136 -151
- Misses 11880 11888 +8
+ Partials 5460 5451 -9 |
/run-all-tests |
sessionctx/binloginfo/binloginfo.go
Outdated
if strings.Contains(ddlQuery, specialPrefix) { | ||
return ddlQuery | ||
} | ||
loc := shardPat.FindStringIndex(strings.ToUpper(ddlQuery)) | ||
if loc == nil { | ||
ddlQuery = addSpecialCommentByRegexp(ddlQuery, shardPat) |
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.
Rather than adding special comments, then combining them by extracting in regexp pattern, how about firstly storing all them in some struct, say, a slice
and then generating the final comment at once?
The latter approach has 2 advantages:
- It has better performance with less regexp matching.
- If we have more special comments in the future, they will be easy to handle
sessionctx/binloginfo/binloginfo.go
Outdated
upperQuery := strings.ToUpper(ddlQuery) | ||
var specialComments []string | ||
minIdx := math.MaxInt64 | ||
for _, reg := range regs { |
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.
For SQL : create table t6 (id int ) shard_row_id_bits=2 shard_row_id_bits=2 pre_split_regions=2;
If it comes with the same Regexps
in SQL, will the comments duplicate here?
Should do the check and test.
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.
Good catch. Done.
/Rest LGTM |
/rebuild |
/run-all-tests |
1 similar comment
/run-all-tests |
sessionctx/binloginfo/binloginfo.go
Outdated
var shardPat = regexp.MustCompile(`SHARD_ROW_ID_BITS\s*=\s*\d+`) | ||
var shardPat = regexp.MustCompile(`SHARD_ROW_ID_BITS\s*=\s*\d+\s*`) | ||
var preSplitPat = regexp.MustCompile(`PRE_SPLIT_REGIONS\s*=\s*\d+\s*`) | ||
var redundantCommentPat = regexp.MustCompile(` \*\/\s*\/\*!90000`) |
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.
Now this variable is redudant
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.
done. thanks
hi @crazycs520 , CI failed with the following message:
PTAL, thanks |
/run-all-tests |
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.
LGTM
return addSpecialCommentByRegexps(ddlQuery, shardPat, preSplitPat) | ||
} | ||
|
||
func addSpecialCommentByRegexps(ddlQuery string, regs ...*regexp.Regexp) string { |
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.
Please add some comments for this function.
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.
The code is write-only..
LGTM
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.
LGTM
/run-all-tests |
What problem does this PR solve?
When tidb write binlog query, TiDB should comment some special syntax for compatibility. eg:
SHARD_ROW_ID_BITS
,PRE_SPLIT_REGIONS
.But before this PR, TiDB won't comment
PRE_SPLIT_REGIONS
, This PR use to fix this problem.Before :
This PR
What is changed and how it works?
Check List
Tests
Code changes
Side effects
Related changes
Release note
pre_split_regions
was uncommented increate table
statement when write binlog query. This may be cause downstream database error.