Skip to content

Commit

Permalink
add full load resource group
Browse files Browse the repository at this point in the history
Signed-off-by: nolouch <nolouch@gmail.com>
  • Loading branch information
nolouch committed Jan 6, 2023
1 parent 70fdee6 commit 5bacb05
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
15 changes: 14 additions & 1 deletion domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ func (do *Domain) loadInfoSchema(startTS uint64) (infoschema.InfoSchema, bool, i
return nil, false, currentSchemaVersion, nil, err
}

newISBuilder, err := infoschema.NewBuilder(do.Store(), do.sysFacHack).InitWithDBInfos(schemas, policies, neededSchemaVersion)
resourceGroups, err := do.fetchResourceGroups(m)
if err != nil {
return nil, false, currentSchemaVersion, nil, err
}

newISBuilder, err := infoschema.NewBuilder(do.Store(), do.sysFacHack).InitWithDBInfos(schemas, policies, resourceGroups, neededSchemaVersion)
if err != nil {
return nil, false, currentSchemaVersion, nil, err
}
Expand Down Expand Up @@ -248,6 +253,14 @@ func (do *Domain) fetchPolicies(m *meta.Meta) ([]*model.PolicyInfo, error) {
return allPolicies, nil
}

func (do *Domain) fetchResourceGroups(m *meta.Meta) ([]*model.ResourceGroupInfo, error) {
allResourceGroups, err := m.ListResourceGroups()
if err != nil {
return nil, err
}
return allResourceGroups, nil
}

func (do *Domain) fetchAllSchemasWithTables(m *meta.Meta) ([]*model.DBInfo, error) {
allSchemas, err := m.ListDatabases()
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion infoschema/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,14 +926,19 @@ func (b *Builder) getSchemaAndCopyIfNecessary(dbName string) *model.DBInfo {
}

// InitWithDBInfos initializes an empty new InfoSchema with a slice of DBInfo, all placement rules, and schema version.
func (b *Builder) InitWithDBInfos(dbInfos []*model.DBInfo, policies []*model.PolicyInfo, schemaVersion int64) (*Builder, error) {
func (b *Builder) InitWithDBInfos(dbInfos []*model.DBInfo, policies []*model.PolicyInfo, resourceGroups []*model.ResourceGroupInfo, schemaVersion int64) (*Builder, error) {
info := b.is
info.schemaMetaVersion = schemaVersion
// build the policies.
for _, policy := range policies {
info.setPolicy(policy)
}

// build the groups.
for _, group := range resourceGroups {
info.setResourceGroup(group)
}

// Maintain foreign key reference information.
for _, di := range dbInfos {
for _, t := range di.Tables {
Expand Down
23 changes: 23 additions & 0 deletions meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,29 @@ func (m *Meta) GetPolicy(policyID int64) (*model.PolicyInfo, error) {
return policy, errors.Trace(err)
}

// ListResourceGroups shows all resource groups.
func (m *Meta) ListResourceGroups() ([]*model.ResourceGroupInfo, error) {
res, err := m.txn.HGetAll(mResourceGroups)
if err != nil {
return nil, errors.Trace(err)
}

groups := make([]*model.ResourceGroupInfo, 0, len(res))
for _, r := range res {
value, err := detachMagicByte(r.Value)
if err != nil {
return nil, errors.Trace(err)
}
group := &model.ResourceGroupInfo{}
err = json.Unmarshal(value, group)
if err != nil {
return nil, errors.Trace(err)
}
groups = append(groups, group)
}
return groups, nil
}

// GetResourceGroup gets the database value with ID.
func (m *Meta) GetResourceGroup(groupID int64) (*model.ResourceGroupInfo, error) {
groupKey := m.resourceGroupKey(groupID)
Expand Down

0 comments on commit 5bacb05

Please sign in to comment.