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
Merged

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

merged 6 commits into from
Jan 8, 2019

Conversation

winkyao
Copy link
Contributor

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

@winkyao winkyao added the sig/execution SIG execution label Jan 4, 2019
@codecov-io
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))
Copy link
Contributor

Choose a reason for hiding this comment

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

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

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

@winkyao
Copy link
Contributor Author

winkyao commented Jan 7, 2019

@XuHuaiyu PTAL

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think bit operations is more readable.

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@winkyao
Copy link
Contributor Author

winkyao commented Jan 8, 2019

@zz-jason  PTAL

@zz-jason zz-jason added the status/LGT2 Indicates that a PR has LGTM 2. label Jan 8, 2019
@zz-jason
Copy link
Member

zz-jason commented Jan 8, 2019

/run-all-tests

1 similar comment
@winkyao
Copy link
Contributor Author

winkyao commented Jan 8, 2019

/run-all-tests

@winkyao
Copy link
Contributor Author

winkyao commented Jan 8, 2019

/run-unit-test

1 similar comment
@winkyao
Copy link
Contributor Author

winkyao commented Jan 8, 2019

/run-unit-test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants