-
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
meta: make auto increment id can be adjust. #10978
Conversation
Codecov Report
@@ Coverage Diff @@
## master #10978 +/- ##
===============================================
- Coverage 80.9317% 80.9007% -0.031%
===============================================
Files 418 418
Lines 89253 89192 -61
===============================================
- Hits 72234 72157 -77
- Misses 11785 11797 +12
- Partials 5234 5238 +4 |
Codecov Report
@@ Coverage Diff @@
## master #10978 +/- ##
================================================
- Coverage 80.9364% 80.9305% -0.0059%
================================================
Files 418 418
Lines 89212 89237 +25
================================================
+ Hits 72205 72220 +15
- Misses 11777 11785 +8
- Partials 5230 5232 +2 |
/run-all-tests |
meta/autoid/autoid.go
Outdated
@@ -214,14 +223,17 @@ func (alloc *allocator) alloc4Unsigned(tableID int64) (int64, error) { | |||
if alloc.base == alloc.end { // step | |||
var newBase, newEnd int64 | |||
startTime := time.Now() | |||
consumeDur := startTime.Sub(alloc.lastAllocTime) | |||
alloc.step = NextStep(alloc.step, consumeDur) | |||
alloc.lastAllocTime = startTime |
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.
We should store the time after we run the transaction.
@imtbkcat |
meta/autoid/autoid.go
Outdated
@@ -29,6 +30,12 @@ import ( | |||
"go.uber.org/zap" | |||
) | |||
|
|||
const ( | |||
minStep = 5000 |
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.
Can we make minStep lower like 1000?
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
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.
1000 is too small, let's say we want 200000 insert QPS in a single tidb server, how many transaction do we need? what if we met transaction conflict while updating the allocated meta.
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 minStep
only matters when the insert QPS is very low.
meta/autoid/autoid.go
Outdated
} | ||
}) | ||
|
||
if consumeDur.Nanoseconds() == 0 { |
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.
When will consumeDur be 0?
meta/autoid/autoid.go
Outdated
if consumeDur.Nanoseconds() == 0 { | ||
return curStep | ||
} | ||
y := defaultComsumeTime.Seconds() / consumeDur.Seconds() |
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.
We need a better name than y
.
ddl/db_test.go
Outdated
@@ -2170,6 +2171,10 @@ func (s *testDBSuite4) TestComment(c *C) { | |||
} | |||
|
|||
func (s *testDBSuite5) TestRebaseAutoID(c *C) { |
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.
It is better to move them to the same suite.
LGTM |
/run-all-tests |
/run-all-tests tidb-test=pr/843 |
1 similar comment
/run-all-tests tidb-test=pr/843 |
meta/autoid/autoid.go
Outdated
const ( | ||
minStep = 1000 | ||
maxStep = 2000000 | ||
defaultComsumeTime = 10 * time.Second |
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.
Consume
?
/run-all-tests tidb-test=pr/843 |
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
What problem does this PR solve?
Make auto increment id step can be adjust automatically according to auto id request speed.
What is changed and how it works?
add function
NextStep
which can produce the next auto id step according to previous step.There are still many test need to be change, so do not merge.
Check List
Tests
Code changes
Side effects
Related changes