Skip to content

Commit

Permalink
meta: Add a GetDBMeta function to meta. (#53684)
Browse files Browse the repository at this point in the history
close #53685
  • Loading branch information
asddongmen committed Jun 4, 2024
1 parent d760a06 commit 7629a0d
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 @@ -989,17 +989,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 @@ -1024,12 +1034,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 7629a0d

Please sign in to comment.