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

executor: return error if autoid overflow to shard bits. #8936

Merged
merged 6 commits into from Jan 8, 2019

Conversation

Projects
None yet
4 participants
@winkyao
Copy link
Member

winkyao commented Jan 4, 2019

What problem does this PR solve?

If autoid overflow when the table has shard bits, the rowID may be duplicated.

What is changed and how it works?

Don't allow to return the overflow rowID, and return autoid.ErrAutoincReadFailed error

Check List

Tests

  • Unit test

Side effects

  • Increased code complexity

Related changes

  • Need to cherry-pick to the release branch

This change is Reviewable

@codecov-io

This comment has been minimized.

Copy link

codecov-io commented Jan 4, 2019

Codecov Report

❗️ No coverage uploaded for pull request base (master@e646276). Click here to learn what that means.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #8936   +/-   ##
=========================================
  Coverage          ?   67.52%           
=========================================
  Files             ?      363           
  Lines             ?    75196           
  Branches          ?        0           
=========================================
  Hits              ?    50778           
  Misses            ?    19935           
  Partials          ?     4483
Impacted Files Coverage Δ
table/tables/tables.go 52.41% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e646276...3fdbcc7. Read the comment docs.

@@ -929,6 +939,12 @@ func (t *tableCommon) AllocAutoID(ctx sessionctx.Context) (int64, error) {
return rowID, nil
}

// overflowShardBits check whether the rowID overflow (64-t.meta.ShardRowIDBits) bits.
func (t *tableCommon) overflowShardBits(rowID int64) bool {
mark := uint64(^(1<<(64-t.meta.ShardRowIDBits) - 1))

This comment has been minimized.

Copy link
@XuHuaiyu

XuHuaiyu Jan 4, 2019

Contributor

s/ mark/ mask?

@@ -929,6 +939,12 @@ func (t *tableCommon) AllocAutoID(ctx sessionctx.Context) (int64, error) {
return rowID, nil
}

// overflowShardBits check whether the rowID overflow (64-t.meta.ShardRowIDBits) bits.

This comment has been minimized.

Copy link
@XuHuaiyu

XuHuaiyu Jan 4, 2019

Contributor

Will this be better?
overflows `1 << (64-t.meta.ShardRowIDBits) - 1`

@winkyao

This comment has been minimized.

Copy link
Member Author

winkyao commented Jan 7, 2019

@XuHuaiyu PTAL

@XuHuaiyu
Copy link
Contributor

XuHuaiyu left a comment

LGTM

// overflowShardBits check whether the rowID overflow `1<<(64-t.meta.ShardRowIDBits) -1`.
func (t *tableCommon) overflowShardBits(rowID int64) bool {
mask := uint64(^(1<<(64-t.meta.ShardRowIDBits) - 1))
return uint64(rowID)&mask > 0

This comment has been minimized.

Copy link
@zz-jason

zz-jason Jan 7, 2019

Member

I think it should be 64-t.meta.ShardRowIDBits-1, because in calcShard, the shard id takes t.meta.ShardRowIDBits+1 bits: https://github.com/pingcap/tidb/pull/8936/files#diff-f92a6a9ee57cf92f8d63bd55d2edc05bR952

how about:

upperBound := uint64(1<<(64-t.meta.ShardRowIDBits-1) - 1)
return uint64(rowID) > upperBound

Hope it would be more easy for understanding.

This comment has been minimized.

Copy link
@winkyao

winkyao Jan 8, 2019

Author Member

I think bit operations is more readable.

fix
@zz-jason
Copy link
Member

zz-jason left a comment

LGTM

@winkyao

This comment has been minimized.

Copy link
Member Author

winkyao commented Jan 8, 2019

@zz-jason  PTAL

@zz-jason zz-jason added the status/LGT2 label Jan 8, 2019

@zz-jason

This comment has been minimized.

Copy link
Member

zz-jason commented Jan 8, 2019

/run-all-tests

1 similar comment
@winkyao

This comment has been minimized.

Copy link
Member Author

winkyao commented Jan 8, 2019

/run-all-tests

@winkyao

This comment has been minimized.

Copy link
Member Author

winkyao commented Jan 8, 2019

/run-unit-test

1 similar comment
@winkyao

This comment has been minimized.

Copy link
Member Author

winkyao commented Jan 8, 2019

/run-unit-test

@zz-jason zz-jason merged commit 106bc7e into pingcap:master Jan 8, 2019

12 checks passed

ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
idc-jenkins-ci-tidb/build Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/common-test job succeeded
Details
idc-jenkins-ci-tidb/integration-common-test Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/integration-compatibility-test Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/integration-ddl-test Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/mybatis-test job succeeded
Details
idc-jenkins-ci-tidb/sqllogic-test-1 Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/sqllogic-test-2 Jenkins job succeeded.
Details
idc-jenkins-ci-tidb/unit-test Jenkins job succeeded.
Details
license/cla Contributor License Agreement is signed.
Details

@winkyao winkyao deleted the winkyao:shard_overflow branch Jan 8, 2019

winkyao added a commit to winkyao/tidb that referenced this pull request Jan 8, 2019

winkyao added a commit to winkyao/tidb that referenced this pull request Jan 8, 2019

zz-jason added a commit that referenced this pull request Jan 8, 2019

zz-jason added a commit that referenced this pull request Jan 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.