Skip to content

Commit

Permalink
ddl: address comment
Browse files Browse the repository at this point in the history
Signed-off-by: xhe <xw897002528@gmail.com>
  • Loading branch information
xhebox committed Dec 31, 2020
1 parent 91e8c81 commit e9d84b1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
9 changes: 3 additions & 6 deletions executor/infoschema_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1820,21 +1820,21 @@ func (e *memtableRetriever) setDataForPlacementPolicy(ctx sessionctx.Context) er
checker := privilege.GetPrivilegeManager(ctx)
is := infoschema.GetInfoSchema(ctx)
var rows [][]types.Datum
if err := is.ForEachBundle(func(bundle *placement.Bundle) error {
for _, bundle := range is.RuleBundles() {
id, err := placement.ObjectIDFromGroupID(bundle.ID)
if err != nil {
return errors.Wrapf(err, "Restore bundle %s failed", bundle.ID)
}
if id == 0 {
return nil
continue
}
// Currently, only partitions have placement rules.
tb, db, part := is.FindTableByPartitionID(id)
if tb == nil {
return errors.Errorf("Can't find partition by id %d", id)
}
if checker != nil && !checker.RequestVerification(ctx.GetSessionVars().ActiveRoles, db.Name.L, tb.Meta().Name.L, "", mysql.SelectPriv) {
return nil
continue
}
for _, rule := range bundle.Rules {
constraint, err := placement.RestoreLabelConstraintList(rule.LabelConstraints)
Expand All @@ -1855,9 +1855,6 @@ func (e *memtableRetriever) setDataForPlacementPolicy(ctx sessionctx.Context) er
)
rows = append(rows, row)
}
return nil
}); err != nil {
return errors.Trace(err)
}
e.rows = rows
return nil
Expand Down
5 changes: 1 addition & 4 deletions infoschema/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,8 @@ func (b *Builder) copySchemasMap(oldIS *infoSchema) {

func (b *Builder) copyBundlesMap(oldIS *infoSchema) {
is := b.is
if err := oldIS.ForEachBundle(func(v *placement.Bundle) error {
for _, v := range oldIS.RuleBundles() {
is.SetBundle(v)
return nil
}); err != nil {
return
}
}

Expand Down
15 changes: 6 additions & 9 deletions infoschema/infoschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ type InfoSchema interface {
FindTableByPartitionID(partitionID int64) (table.Table, *model.DBInfo, *model.PartitionDefinition)
// BundleByName is used to get a rule bundle.
BundleByName(name string) (*placement.Bundle, bool)
// ForEachBundle will iterate all placement rule bundles. If visitor
// return a non-nil value, the iteration will stop and the error will
// be returned to the caller.
ForEachBundle(visitor func(*placement.Bundle) error) error
// SetBundle is only used for TEST
SetBundle(*placement.Bundle)
// RuleBundles will return a copy of all rule bundles.
RuleBundles() []*placement.Bundle
}

type sortedTables []table.Table
Expand Down Expand Up @@ -415,15 +413,14 @@ func (is *infoSchema) BundleByName(name string) (*placement.Bundle, bool) {
return t, r
}

func (is *infoSchema) ForEachBundle(visitor func(*placement.Bundle) error) error {
func (is *infoSchema) RuleBundles() []*placement.Bundle {
is.ruleBundleMutex.RLock()
defer is.ruleBundleMutex.RUnlock()
bundles := make([]*placement.Bundle, 0, len(is.ruleBundleMap))
for _, bundle := range is.ruleBundleMap {
if err := visitor(bundle); err != nil {
return err
}
bundles = append(bundles, bundle)
}
return nil
return bundles
}

func (is *infoSchema) SetBundle(bundle *placement.Bundle) {
Expand Down

0 comments on commit e9d84b1

Please sign in to comment.