From e9d84b14d5bd48c4820c2302de40712dc20bde43 Mon Sep 17 00:00:00 2001 From: xhe Date: Thu, 31 Dec 2020 16:49:20 +0800 Subject: [PATCH] ddl: address comment Signed-off-by: xhe --- executor/infoschema_reader.go | 9 +++------ infoschema/builder.go | 5 +---- infoschema/infoschema.go | 15 ++++++--------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/executor/infoschema_reader.go b/executor/infoschema_reader.go index 0b8512f0d5866..d240b19a92c67 100644 --- a/executor/infoschema_reader.go +++ b/executor/infoschema_reader.go @@ -1820,13 +1820,13 @@ 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) @@ -1834,7 +1834,7 @@ func (e *memtableRetriever) setDataForPlacementPolicy(ctx sessionctx.Context) er 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) @@ -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 diff --git a/infoschema/builder.go b/infoschema/builder.go index a95d0dd399e66..4e51753cc0ec4 100644 --- a/infoschema/builder.go +++ b/infoschema/builder.go @@ -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 } } diff --git a/infoschema/infoschema.go b/infoschema/infoschema.go index 02d698acd05c8..d53f4de78e55c 100644 --- a/infoschema/infoschema.go +++ b/infoschema/infoschema.go @@ -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 @@ -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) {