Repository: pingcap/tidb
File: pkg/meta/meta.go (Go)

Code before:

	return errors.Trace(workGroup.Wait())
}

// 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 *Mutator) 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
}

// foreign key info contain null and [] two situations
var checkForeignKeyAttributesNil = `"fk_info":null`
var checkForeignKeyAttributesZero = `"fk_info":[]`

// MustLoadFilterAttr is filters for IsTableInfoMustLoad.
// LoadIfMissing == true, it loads if attr is missing.
// LoadIfMissing == false, it loads if attr is present.
type MustLoadFilterAttr struct {
	Attr          string
	LoadIfMissing bool
}

var checkAttributesInOrder = []MustLoadFilterAttr{
	{Attr: `"partition":null`, LoadIfMissing: true},
	{Attr: `"Lock":null`, LoadIfMissing: true},
	{Attr: `"tiflash_replica":null`, LoadIfMissing: true},
	{Attr: `"temp_table_type":0`, LoadIfMissing: true},
	{Attr: `"policy_ref_info":null`, LoadIfMissing: true},
	{Attr: `"ttl_info":null`, LoadIfMissing: true},
	{Attr: `"affinity":{`, LoadIfMissing: false},
	{Attr: `"softdelete_info":{`, LoadIfMissing: false},
}

// isTableInfoMustLoad checks whether the table info needs to be loaded.
// If the byte representation contains all the given attributes,
// then it does not need to be loaded and this function will return false.
// Otherwise, it will return true, indicating that the table info should be loaded.
// Since attributes are checked in sequence, it's important to choose the order carefully.
// isCheckForeignKeyAttrsInOrder check foreign key or not, since fk_info contains two null situations.
func isTableInfoMustLoad(json []byte, isCheckForeignKeyAttrsInOrder bool, filterAttrs ...MustLoadFilterAttr) bool {
	idx := 0
	if isCheckForeignKeyAttrsInOrder {

Review comment (suggestion):
`MustLoadFilterAttr` comment has a grammar issue (“is filters”). Consider rewording to something like “MustLoadFilterAttr defines filters …” and clarifying that `LoadIfMissing` controls whether absence vs presence triggers loading.
```suggestion
// MustLoadFilterAttr defines filters for IsTableInfoMustLoad.
// LoadIfMissing controls whether the absence or presence of the attribute
// should trigger loading: when true, load if the attribute is missing;
// when false, load if the attribute is present.
```

Code after:

	return errors.Trace(workGroup.Wait())
}

// 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 *Mutator) 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
}

// foreign key info contain null and [] two situations
var checkForeignKeyAttributesNil = `"fk_info":null`
var checkForeignKeyAttributesZero = `"fk_info":[]`

// MustLoadFilterAttr defines filters for IsTableInfoMustLoad.
// LoadIfMissing controls whether the absence or presence of the attribute
// should trigger loading: when true, load if the attribute is missing;
// when false, load if the attribute is present.
type MustLoadFilterAttr struct {
	Attr          string
	LoadIfMissing bool
}

var checkAttributesInOrder = []MustLoadFilterAttr{
	{Attr: `"partition":null`, LoadIfMissing: true},
	{Attr: `"Lock":null`, LoadIfMissing: true},
	{Attr: `"tiflash_replica":null`, LoadIfMissing: true},
	{Attr: `"temp_table_type":0`, LoadIfMissing: true},
	{Attr: `"policy_ref_info":null`, LoadIfMissing: true},
	{Attr: `"ttl_info":null`, LoadIfMissing: true},
	{Attr: `"affinity":{`, LoadIfMissing: false},
	{Attr: `"softdelete_info":{`, LoadIfMissing: false},
}

// isTableInfoMustLoad checks whether the table info needs to be loaded.
// If the byte representation follows filterAttrs, it returns true.
// Otherwise, it return false meaning that table is not neeeded to load.
// Since attributes are checked in sequence, it's important to choose the order carefully.
// isCheckForeignKeyAttrsInOrder check foreign key or not, since fk_info contains two null situations.
func isTableInfoMustLoad(json []byte, isCheckForeignKeyAttrsInOrder bool, filterAttrs ...MustLoadFilterAttr) bool {
	idx := 0
	if isCheckForeignKeyAttrsInOrder {