Skip to content

Commit 95c6386

Browse files
asddongmenti-chi-bot
authored andcommitted
meta: Add a GetDBMeta function to meta. (pingcap#53684)
close pingcap#53685
1 parent 8e3a55e commit 95c6386

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

pkg/meta/meta.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -929,17 +929,27 @@ func (m *Meta) IterTables(dbID int64, fn func(info *model.TableInfo) error) erro
929929
return errors.Trace(err)
930930
}
931931

932-
// ListTables shows all tables in database.
933-
func (m *Meta) ListTables(dbID int64) ([]*model.TableInfo, error) {
932+
// GetMetasByDBID return all meta information of a database.
933+
// Note(dongmen): This method is used by TiCDC to reduce the time of changefeed initialization.
934+
// Ref: https://github.com/pingcap/tiflow/issues/11109
935+
func (m *Meta) GetMetasByDBID(dbID int64) ([]structure.HashPair, error) {
934936
dbKey := m.dbKey(dbID)
935937
if err := m.checkDBExists(dbKey); err != nil {
936938
return nil, errors.Trace(err)
937939
}
938-
939940
res, err := m.txn.HGetAll(dbKey)
940941
if err != nil {
941942
return nil, errors.Trace(err)
942943
}
944+
return res, nil
945+
}
946+
947+
// ListTables shows all tables in database.
948+
func (m *Meta) ListTables(dbID int64) ([]*model.TableInfo, error) {
949+
res, err := m.GetMetasByDBID(dbID)
950+
if err != nil {
951+
return nil, errors.Trace(err)
952+
}
943953

944954
tables := make([]*model.TableInfo, 0, len(res)/2)
945955
for _, r := range res {
@@ -963,12 +973,7 @@ func (m *Meta) ListTables(dbID int64) ([]*model.TableInfo, error) {
963973

964974
// ListSimpleTables shows all simple tables in database.
965975
func (m *Meta) ListSimpleTables(dbID int64) ([]*model.TableNameInfo, error) {
966-
dbKey := m.dbKey(dbID)
967-
if err := m.checkDBExists(dbKey); err != nil {
968-
return nil, errors.Trace(err)
969-
}
970-
971-
res, err := m.txn.HGetAll(dbKey)
976+
res, err := m.GetMetasByDBID(dbID)
972977
if err != nil {
973978
return nil, errors.Trace(err)
974979
}

0 commit comments

Comments
 (0)