Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta: Add a GetDBMeta function to meta. #53684

Merged
merged 8 commits into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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