Skip to content
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

Merged
merged 15 commits into from
Jun 28, 2019

Conversation

imtbkcat
Copy link

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

  • Unit test

Code changes

  • Has exported function/method change

Side effects

  • Possible performance regression
  • Increased code complexity

Related changes

  • Need to cherry-pick to the release branch

@imtbkcat imtbkcat requested review from coocood and jackysp June 28, 2019 06:55
@imtbkcat imtbkcat changed the title change test result meta: make auto increment id can be adjust. Jun 28, 2019
@codecov
Copy link

codecov bot commented Jun 28, 2019

Codecov Report

Merging #10978 into master will decrease coverage by 0.0309%.
The diff coverage is 92.8571%.

@@               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
Copy link

codecov bot commented Jun 28, 2019

Codecov Report

Merging #10978 into master will decrease coverage by 0.0058%.
The diff coverage is 100%.

@@               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

@imtbkcat
Copy link
Author

/run-all-tests

@@ -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
Copy link
Member

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.

@coocood
Copy link
Member

coocood commented Jun 28, 2019

@imtbkcat
We need unit test for NextStep.

@@ -29,6 +30,12 @@ import (
"go.uber.org/zap"
)

const (
minStep = 5000
Copy link
Member

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Member

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.

Copy link
Member

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.

}
})

if consumeDur.Nanoseconds() == 0 {
Copy link
Member

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?

if consumeDur.Nanoseconds() == 0 {
return curStep
}
y := defaultComsumeTime.Seconds() / consumeDur.Seconds()
Copy link
Member

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) {
Copy link
Member

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.

@coocood
Copy link
Member

coocood commented Jun 28, 2019

LGTM

@imtbkcat
Copy link
Author

/run-all-tests

@imtbkcat
Copy link
Author

/run-all-tests tidb-test=pr/843

1 similar comment
@imtbkcat
Copy link
Author

/run-all-tests tidb-test=pr/843

const (
minStep = 1000
maxStep = 2000000
defaultComsumeTime = 10 * time.Second
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consume?

@imtbkcat
Copy link
Author

/run-all-tests tidb-test=pr/843

@imtbkcat imtbkcat added status/all tests passed status/LGT1 Indicates that a PR has LGTM 1. labels Jun 28, 2019
Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT1 Indicates that a PR has LGTM 1. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants