ddl: fix inconsistent rule cache (#22051)
Signed-off-by: xhe <xw897002528@gmail.com>
This commit is contained in:
@ -428,17 +428,20 @@ func GetBundle(h InfoSchema, ids []int64) *placement.Bundle {
|
||||
}
|
||||
}
|
||||
|
||||
newRules := []*placement.Rule{}
|
||||
|
||||
b, ok := h.BundleByName(placement.PDBundleID)
|
||||
if ok {
|
||||
newRules := b.Rules[:0]
|
||||
for _, rule := range b.Rules {
|
||||
if rule.StartKeyHex == "" && rule.EndKeyHex == "" {
|
||||
newRules = append(newRules, rule.Clone())
|
||||
}
|
||||
}
|
||||
b.Rules = newRules
|
||||
return b
|
||||
}
|
||||
|
||||
return &placement.Bundle{ID: placement.GroupID(ids[0])}
|
||||
id := int64(-1)
|
||||
if len(ids) > 0 {
|
||||
id = ids[0]
|
||||
}
|
||||
return &placement.Bundle{ID: placement.GroupID(id), Rules: newRules}
|
||||
}
|
||||
|
||||
@ -369,7 +369,11 @@ func (*testSuite) TestGetBundle(c *C) {
|
||||
bundles[placement.PDBundleID] = bundle
|
||||
|
||||
b := infoschema.GetBundle(is, []int64{})
|
||||
c.Assert(b, DeepEquals, bundle)
|
||||
c.Assert(b.Rules, DeepEquals, bundle.Rules)
|
||||
|
||||
// bundle itself is cloned
|
||||
b.ID = "test"
|
||||
c.Assert(bundle.ID, Equals, placement.PDBundleID)
|
||||
|
||||
ptID := placement.GroupID(3)
|
||||
bundle = &placement.Bundle{
|
||||
@ -388,6 +392,10 @@ func (*testSuite) TestGetBundle(c *C) {
|
||||
b = infoschema.GetBundle(is, []int64{2, 3})
|
||||
c.Assert(b, DeepEquals, bundle)
|
||||
|
||||
// bundle itself is cloned
|
||||
b.ID = "test"
|
||||
c.Assert(bundle.ID, Equals, ptID)
|
||||
|
||||
ptID = placement.GroupID(1)
|
||||
bundle = &placement.Bundle{
|
||||
ID: ptID,
|
||||
@ -404,4 +412,8 @@ func (*testSuite) TestGetBundle(c *C) {
|
||||
|
||||
b = infoschema.GetBundle(is, []int64{1, 2, 3})
|
||||
c.Assert(b, DeepEquals, bundle)
|
||||
|
||||
// bundle itself is cloned
|
||||
b.ID = "test"
|
||||
c.Assert(bundle.ID, Equals, ptID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user