-
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
ddl: fix a bug that we miss adding last handle index in some case. #7142
Conversation
/run-all-tests |
ddl/index.go
Outdated
@@ -678,7 +684,19 @@ func (w *addIndexWorker) handleBackfillTask(d *ddlCtx, task *reorgIndexTask) *ad | |||
} | |||
|
|||
handleRange.startHandle = nextHandle | |||
if handleRange.startHandle >= handleRange.endHandle { | |||
finishTask := false | |||
// if nextHandle is math.Int64, we can only use handleOutOfRange to indicates the nexHandle is handled. |
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/if/If
s/to indicates/to indicate
s/nexHandle/nextHandle
ddl/index.go
Outdated
@@ -678,7 +684,19 @@ func (w *addIndexWorker) handleBackfillTask(d *ddlCtx, task *reorgIndexTask) *ad | |||
} | |||
|
|||
handleRange.startHandle = nextHandle | |||
if handleRange.startHandle >= handleRange.endHandle { | |||
finishTask := false |
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.
We can move it to line 692, where it is used.
ddl/index.go
Outdated
if handleRange.startHandle >= handleRange.endHandle { | ||
finishTask := false | ||
// if nextHandle is math.Int64, we can only use handleOutOfRange to indicates the nexHandle is handled. | ||
if handleOutOfRange && nextHandle == handleRange.endHandle { |
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.
Is handleOutOfRange
implies nextHandle == handleRange.endHandle
?
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.
no. handleOutOfRange just mean current batch is handled out of range.
@zimulala @lamxTyler 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
ddl/index.go
Outdated
@@ -637,6 +642,7 @@ func (w *addIndexWorker) backfillIndexInTxn(handleRange reorgIndexTask) (nextHan | |||
|
|||
if handleOutOfRange || len(idxRecords) == 0 { | |||
nextHandle = handleRange.endHandle | |||
handleOutOfRange = true |
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'm confused why handleOutOfRange = true
when len(idxRecords) == 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.
And nextHandle
should not be handleRange.endHandle
when handleRange.exclude
is false
/run-all-tests |
/run-all-tests |
/run-integration-common-test -tidb-test=pr/592 |
/run-common-test -tidb-test=pr/592 |
PTAL @shenli |
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
ddl/index.go
Outdated
// TODO: use tableScan to prune columns. | ||
w.idxRecords = w.idxRecords[:0] | ||
startTime := time.Now() | ||
|
||
// handleOutOfRange means that the added handle is out of taskRange.endHandle. |
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.
Can we rename the handleOutOfRange
to taskDone
?
ddl/index.go
Outdated
@@ -549,10 +551,26 @@ func (w *addIndexWorker) getIndexRecord(handle int64, recordKey []byte, rawRecor | |||
return idxRecord, nil | |||
} | |||
|
|||
func (w *addIndexWorker) fetchRowColVals(txn kv.Transaction, taskRange reorgIndexTask) ([]*indexRecord, bool, error) { | |||
func (w *addIndexWorker) getNextHandle(taskRange reorgIndexTask, handleOutOfRange bool) (nextHandle int64) { | |||
nextHandle = taskRange.startHandle |
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.
This line is useless.
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 !taskDone {
// The task is not done. So we need to pick the last processed entry's handle and plus one.
return w.idxRecords[len(w.idxRecords)-1].handle + 1
}
// The task is done. So we need to choose a handle out side this range. There are some corner cases should be considered:
// - The end of task range is MaxInt64.
// - The end of the task is excluded in the range.
if taskRange.endHandle == math.MaxInt64 || !taskRange.endIncluded {
return taskRange.endHandle
}
return taskRange.endHandle + 1
ddl/index.go
Outdated
return nextHandle | ||
} | ||
|
||
func (w *addIndexWorker) fetchRowColVals(txn kv.Transaction, taskRange reorgIndexTask) ([]*indexRecord, int64, bool, error) { |
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.
Add comment for the newly added return value.
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
@shenli PTAL |
LGTM |
Here is a suggestion for your PR description: This PR fixes a bug that when the last remained index count is just In this case, The newly added test case will fail in the master branch:
|
/run-all-tests |
@CaitinChen Thanks for your valuable suggestions. |
ddl/index.go
Outdated
// getNextHandle gets next handle of entry that we are going to process. | ||
func (w *addIndexWorker) getNextHandle(taskRange reorgIndexTask, taskDone bool) (nextHandle int64) { | ||
if !taskDone { | ||
// The task is not done. So we need to pick the last processed entry's handle and plus one. |
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.
The task is not done. So we need to pick the last processed entry's handle and add one.
Note: "plus" is a prep, not a verb.
ddl/index.go
Outdated
return w.idxRecords[len(w.idxRecords)-1].handle + 1 | ||
} | ||
|
||
// The task is done. So we need to choose a handle out side this range. |
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.
The task is done. So we need to choose a handle outside this range.
ddl/index.go
Outdated
} | ||
|
||
// The task is done. So we need to choose a handle out side this range. | ||
// There are some corner cases should be considered: |
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.
Some corner cases should be considered:
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.
You can also use "There are some corner cases which should be considered:"
@winkyao My pleasure. ^_^ |
What have you changed? (mandatory)
This PR fixes a bug that, when the last remains indices count is just defaultTaskHandleCnt+1, we do not use handleRange.endIncluded outside, so we may miss adding the last index.
In this case, we break fetchRowColVals by
len(w.idxRecords) >= w.batchCnt
, then the handleOutOfRange is false, so thenextHandle = idxRecords[len(idxRecords)-1].handle + 1
, it is exactly equal to endHandle, so in handleBackfillTask, we break the loop byfinishTask = handleRange.startHandle >= handleRange.endHandle
mistakenly.master branch will fail the newly added test case with:
What is the type of the changes? (mandatory)
How has this PR been tested? (mandatory)
ut
Does this PR affect documentation (docs/docs-cn) update? (mandatory)
NO
Does this PR affect tidb-ansible update? (mandatory)
NO
Does this PR need to be added to the release notes? (mandatory)
YES
Refer to a related PR or issue link (optional)
Benchmark result if necessary (optional)
Add a few positive/negative examples (optional)