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

*: fix panic when to enable lite-init-stats and concurrently-init-stats #52226

Merged
merged 22 commits into from
Mar 30, 2024
Merged
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3ccc217
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
31f7bef
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
3f35ae7
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
4a95c2b
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
a33de6c
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
bff288d
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
b266039
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
7bc28a6
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
b9d7178
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
5b39b5c
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
2b16a02
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
191aef5
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
9e0aa57
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
d6d4268
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
b5d28c7
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
2dd1f9a
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
bef092c
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
29e9abc
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 29, 2024
39d7433
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 30, 2024
369ca7c
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 30, 2024
bb531c3
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 30, 2024
78081f9
*: fix panic when to enable lite-init-stats and concurrently-init-stats
hawkingrei Mar 30, 2024
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
19 changes: 19 additions & 0 deletions pkg/statistics/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type Table struct {
// ColAndIdxExistenceMap is the meta map for statistics.Table.
// It can tell whether a column/index really has its statistics. So we won't send useless kv request when we do online stats loading.
type ColAndIdxExistenceMap struct {
mu sync.RWMutex // It will cause concurrent map writes when to init stats.
colInfoMap map[int64]*model.ColumnInfo
colAnalyzed map[int64]bool
idxInfoMap map[int64]*model.IndexInfo
Expand All @@ -88,6 +89,8 @@ type ColAndIdxExistenceMap struct {
// SomeAnalyzed checks whether some part of the table is analyzed.
// The newly added column/index might not have its stats.
func (m *ColAndIdxExistenceMap) SomeAnalyzed() bool {
m.mu.RLock()
defer m.mu.RUnlock()
if m == nil {
return false
}
Expand All @@ -108,6 +111,8 @@ func (m *ColAndIdxExistenceMap) SomeAnalyzed() bool {
// This method only checks whether the given item exists or not.
// Don't check whether it has statistics or not.
func (m *ColAndIdxExistenceMap) Has(id int64, isIndex bool) bool {
m.mu.RLock()
defer m.mu.RUnlock()
if isIndex {
_, ok := m.idxInfoMap[id]
return ok
Expand All @@ -125,6 +130,8 @@ func (m *ColAndIdxExistenceMap) Has(id int64, isIndex bool) bool {
//
// To figure out three status, we use HasAnalyzed's TRUE value to represents the status 3. The Has's FALSE to represents the status 1.
func (m *ColAndIdxExistenceMap) HasAnalyzed(id int64, isIndex bool) bool {
m.mu.RLock()
defer m.mu.RUnlock()
if isIndex {
analyzed, ok := m.idxAnalyzed[id]
return ok && analyzed
Expand All @@ -135,33 +142,45 @@ func (m *ColAndIdxExistenceMap) HasAnalyzed(id int64, isIndex bool) bool {

// InsertCol inserts a column with its meta into the map.
func (m *ColAndIdxExistenceMap) InsertCol(id int64, info *model.ColumnInfo, analyzed bool) {
m.mu.Lock()
defer m.mu.Unlock()
m.colInfoMap[id] = info
m.colAnalyzed[id] = analyzed
}

// GetCol gets the meta data of the given column.
func (m *ColAndIdxExistenceMap) GetCol(id int64) *model.ColumnInfo {
m.mu.RLock()
defer m.mu.RUnlock()
return m.colInfoMap[id]
}

// InsertIndex inserts an index with its meta into the map.
func (m *ColAndIdxExistenceMap) InsertIndex(id int64, info *model.IndexInfo, analyzed bool) {
m.mu.Lock()
defer m.mu.Unlock()
m.idxInfoMap[id] = info
m.idxAnalyzed[id] = analyzed
}

// GetIndex gets the meta data of the given index.
func (m *ColAndIdxExistenceMap) GetIndex(id int64) *model.IndexInfo {
m.mu.RLock()
defer m.mu.RUnlock()
return m.idxInfoMap[id]
}

// IsEmpty checks whether the map is empty.
func (m *ColAndIdxExistenceMap) IsEmpty() bool {
m.mu.RLock()
defer m.mu.RUnlock()
return len(m.colInfoMap)+len(m.idxInfoMap) == 0
}

// Clone deeply copies the map.
func (m *ColAndIdxExistenceMap) Clone() *ColAndIdxExistenceMap {
m.mu.RLock()
defer m.mu.RUnlock()
mm := NewColAndIndexExistenceMap(len(m.colInfoMap), len(m.idxInfoMap))
mm.colInfoMap = maps.Clone(m.colInfoMap)
mm.colAnalyzed = maps.Clone(m.colAnalyzed)
Expand Down