-
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
table: fix wrong handle comparation in index double write #57418
Conversation
Hi @joechenrh. Thanks for your PR. PRs from untrusted users cannot be marked as trusted with I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #57418 +/- ##
================================================
+ Coverage 72.9476% 75.2817% +2.3341%
================================================
Files 1672 1717 +45
Lines 461826 477452 +15626
================================================
+ Hits 336891 359434 +22543
+ Misses 104197 95757 -8440
- Partials 20738 22261 +1523
Flags with carried forward coverage won't be shown. Click here to find out more.
|
/ok-to-test |
pkg/table/tables/index.go
Outdated
if !h.Equal(oh) { | ||
// The handle passed in may be a `PartitionHandle`, | ||
// so we can't directly do comparation with them. | ||
if !handleEqual(h, oh) { |
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.
If the passed handle is PartaitionHandle, why oh isn't partitionHandle here?
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.
Take the case in #57414 as example, the handle h
is retrieved from FetchDuplicatedHandle
. Since global index is first checked and duplication is found, we will get PartitionHandle
.
Lines 272 to 273 in 043f833
for _, uk := range r.uniqueKeys { | |
_, handle, err := tables.FetchDuplicatedHandle(ctx, uk.newKey, true, txn, e.Table.Meta().ID) |
But the newly added index is not global index, so
oh
is just IntHandle
.
In addition, there may also be opposite situations that oh
is PartitionHandle
and h
is IntHandle
. But IntHandle
can be compared with PartitionHandle
correctly.
pkg/table/tables/index.go
Outdated
@@ -386,6 +386,13 @@ func needPresumeKeyNotExistsFlag(ctx context.Context, txn kv.Transaction, key, t | |||
return false, nil | |||
} | |||
|
|||
func handleEqual(dupHandle, prevHandle kv.Handle) bool { |
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.
Maybe we could change func (ph PartitionHandle) Equal(h Handle) bool
function. Only both handles are partition handle, we need compare pid.
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.
Maybe we could change func (ph PartitionHandle) Equal(h Handle) bool function.
I'm not sure if it will affect other code so I add a new function. Let me have a try.
if idxInfo.Global { | ||
// 'handle' comes from reading directly from a partition, without partition id, | ||
// so we can only compare the handle part of the key. | ||
if ph, ok := h.(kv.PartitionHandle); ok && ph.Handle.Equal(handle) { | ||
// table row has been back-filled already, OK to add the index entry | ||
return nil | ||
} | ||
} |
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.
Just remove some unnecessary logic for comparation.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Defined2014, wjhuang2016 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
In response to a cherrypick label: new pull request created to branch |
What problem does this PR solve?
Issue Number: close #57414
Problem Summary:
What changed and how does it work?
Unlike other indices, global index encodes the value of its key-value pairs with a partition ID:
tidb/pkg/tablecodec/tablecodec.go
Lines 1630 to 1649 in 2ca497e
So during the double write process, we may do comparison between partition handles and non-partition handles.
tidb/pkg/table/tables/index.go
Lines 419 to 432 in 2ca497e
For example, in #57414,
h
is the handle of global indexi1
whose type isPartitionHandle
whileoh
isIntHandle
of the current index. Thus,!h.Equal(oh)
will return false.Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.