Skip to content

Commit

Permalink
meta: Add a GetDBMeta function to meta. (pingcap#53684)
Browse files Browse the repository at this point in the history
  • Loading branch information
asddongmen authored and ti-chi-bot committed Jun 4, 2024
1 parent 8e3a55e commit 95c6386
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 @@ -929,17 +929,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 @@ -963,12 +973,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 95c6386

Please sign in to comment.