-
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
ddl: cancel add index when can not find partition and fix GetPartition function bug #10475
ddl: cancel add index when can not find partition and fix GetPartition function bug #10475
Conversation
@@ -313,7 +313,11 @@ func (t *partitionedTable) locateHashPartition(ctx sessionctx.Context, pi *model | |||
|
|||
// GetPartition returns a Table, which is actually a partition. | |||
func (t *partitionedTable) GetPartition(pid int64) table.PhysicalTable { | |||
return t.partitions[pid] | |||
p, ok := t.partitions[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.
eg:
type partition struct {
tableCommon
}
type partitionTables struct {
ps map[int]*partition
}
func (p *partition) GetPhysicalID() int {
return 0
}
type tableCommon struct {
tableID int64
}
type physibleTable interface {
GetPhysicalID() int
}
func (pt *partitionTables) getPartition(id int) physibleTable {
return pt.ps[id]
}
func (pt *partitionTables) getPartition2(id int) physibleTable {
p, ok := pt.ps[id]
if !ok {
return nil
}
return p
}
func main() {
ps := make(map[int]*partition)
pt := &partitionTables{ps: ps}
fmt.Println(pt.getPartition(0) == nil) // false
fmt.Println(pt.getPartition2(0) == nil) // 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.
Golang traps and pitfalls...
A nil of type *partition
is a kind of physibleTable
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.
Good catch! @crazycs520
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.
Would like to add some comment 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.
done.
Codecov Report
@@ Coverage Diff @@
## master #10475 +/- ##
===============================================
- Coverage 77.2752% 77.2633% -0.012%
===============================================
Files 413 413
Lines 86967 86974 +7
===============================================
- Hits 67204 67199 -5
- Misses 14599 14608 +9
- Partials 5164 5167 +3 |
// update them to table's in this case. | ||
if endHandle == 0 || physicalTableID == 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.
why ignore endHandle
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.
Because endHandle
is 0 don't mean doesn't store them before. Maybe the stored endHandle
is 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.
Is there any test to cover 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.
yes, https://github.com/pingcap/tidb/pull/10475/files#diff-e259172e2953a3597b096f11d3c8d3daR1289 this test do this job.
…/crazycs520/tidb into fix-add-index-in-partition-table
…-index-in-partition-table
@@ -313,7 +313,13 @@ func (t *partitionedTable) locateHashPartition(ctx sessionctx.Context, pi *model | |||
|
|||
// GetPartition returns a Table, which is actually a partition. | |||
func (t *partitionedTable) GetPartition(pid int64) table.PhysicalTable { | |||
return t.partitions[pid] | |||
// Attention, can't simply use `return t.partitions[pid]` here. | |||
// Because A nil of type *partition is a kind of `table.PhysicalTable` |
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.
// Because A nil of type *partition is a kind of `table.PhysicalTable` | |
// Because A nil of type *partition is a kind of `table.PhysicalTable`, | |
// the final result will be a non-nil interface whose underlying value is nil, | |
// use that result will get a nil pointer panic. |
LGTM |
/run-all-tests |
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
err = w.runReorgJob(t, reorgInfo, d.lease, func() error { | ||
err = w.runReorgJob(t, reorgInfo, d.lease, func() (addIndexErr error) { | ||
defer func() { | ||
r := recover() |
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.
use util.WithRecover instead.
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, I need return cancelled error 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.
you can change util.WithReocover
to return value from exec
func
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.
Ok, go WithReocover can not return values
/run-all-tests |
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
What problem does this PR solve?
Below sql will cause tidb panic when add index.
What is changed and how it works?
alter table t1 add index idx(a);
execute successful.Check List
Tests
Code changes
Side effects
Related changes