-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8936 +/- ##
=========================================
Coverage ? 67.52%
=========================================
Files ? 363
Lines ? 75196
Branches ? 0
=========================================
Hits ? 50778
Misses ? 19935
Partials ? 4483
Continue to review full report at Codecov.
|
table/tables/tables.go
Outdated
@@ -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)) |
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.
s/ mark/ mask?
table/tables/tables.go
Outdated
@@ -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. |
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.
Will this be better?
overflows `1 << (64-t.meta.ShardRowIDBits) - 1`
@XuHuaiyu PTAL |
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
table/tables/tables.go
Outdated
// 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 |
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.
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.
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.
I think bit operations is more readable.
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
@zz-jason PTAL |
/run-all-tests |
1 similar comment
/run-all-tests |
/run-unit-test |
1 similar comment
/run-unit-test |
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
errorCheck List
Tests
Side effects
Related changes
This change is