Skip to content

Commit

Permalink
meta: Add a GetDBMeta function to meta. (#53684) (#53781)
Browse files Browse the repository at this point in the history
close #53685
  • Loading branch information
ti-chi-bot authored Aug 2, 2024
1 parent cf23e7a commit abb56db
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions pkg/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -986,17 +986,27 @@ func (m *Meta) IterTables(dbID int64, fn func(info *model.TableInfo) error) erro
return errors.Trace(err)
}

// ListTables shows all tables in database.
func (m *Meta) ListTables(dbID int64) ([]*model.TableInfo, error) {
// GetMetasByDBID return all meta information of a database.
// Note(dongmen): This method is used by TiCDC to reduce the time of changefeed initialization.
// Ref: https://github.com/pingcap/tiflow/issues/11109
func (m *Meta) GetMetasByDBID(dbID int64) ([]structure.HashPair, error) {
dbKey := m.dbKey(dbID)
if err := m.checkDBExists(dbKey); err != nil {
return nil, errors.Trace(err)
}

res, err := m.txn.HGetAll(dbKey)
if err != nil {
return nil, errors.Trace(err)
}
return res, nil
}

// ListTables shows all tables in database.
func (m *Meta) ListTables(dbID int64) ([]*model.TableInfo, error) {
res, err := m.GetMetasByDBID(dbID)
if err != nil {
return nil, errors.Trace(err)
}

tables := make([]*model.TableInfo, 0, len(res)/2)
for _, r := range res {
Expand All @@ -1021,12 +1031,7 @@ func (m *Meta) ListTables(dbID int64) ([]*model.TableInfo, error) {

// ListSimpleTables shows all simple tables in database.
func (m *Meta) ListSimpleTables(dbID int64) ([]*model.TableNameInfo, error) {
dbKey := m.dbKey(dbID)
if err := m.checkDBExists(dbKey); err != nil {
return nil, errors.Trace(err)
}

res, err := m.txn.HGetAll(dbKey)
res, err := m.GetMetasByDBID(dbID)
if err != nil {
return nil, errors.Trace(err)
}
Expand Down

0 comments on commit abb56db

Please sign in to comment.