-
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: cancel add index when can not find partition and fix GetPartition function bug #10475
Changes from 9 commits
0f801fa
e9d0a53
edf9d76
18872d1
d491799
52ada5e
e45863f
67d9966
6c14dde
3563ba5
fcbd8ed
605a10d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -733,9 +733,9 @@ func (m *Meta) GetDDLReorgHandle(job *model.Job) (startHandle, endHandle, physic | |
err = errors.Trace(err) | ||
return | ||
} | ||
// endHandle or physicalTableID may be 0, because older version TiDB (without table partition) doesn't store them. | ||
// physicalTableID may be 0, because older version TiDB (without table partition) doesn't store them. | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. why ignore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
if physicalTableID == 0 { | ||
if job.ReorgMeta != nil { | ||
endHandle = job.ReorgMeta.EndHandle | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
p, ok := t.partitions[pid] | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Golang traps and pitfalls... A nil of type There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||||||||||
if !ok { | ||||||||||
return nil | ||||||||||
} | ||||||||||
return p | ||||||||||
} | ||||||||||
|
||||||||||
// GetPartitionByRow returns a Table, which is actually a Partition. | ||||||||||
|
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 fromexec
funcThere 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