Skip to content

Commit

Permalink
address the comment
Browse files Browse the repository at this point in the history
Signed-off-by: yisaer <[email protected]>

address the comment

Signed-off-by: yisaer <[email protected]>
  • Loading branch information
Yisaer committed May 5, 2022
1 parent 570409c commit 107d4c0
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions statistics/handle/lru_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type statsInnerCache struct {
func newStatsLruCache(c int64) *statsInnerCache {
s := &statsInnerCache{
elements: make(map[int64]*lruMapElement),
lru: newInnerIndexLruCache(c),
lru: newInnerLruCache(c),
}
s.lru.onEvict = s.onEvict
return s
Expand All @@ -45,7 +45,7 @@ type innerItemLruCache struct {
onEvict func(tblID int64)
}

func newInnerIndexLruCache(c int64) *innerItemLruCache {
func newInnerLruCache(c int64) *innerItemLruCache {
return &innerItemLruCache{
capacity: c,
cache: list.New(),
Expand Down Expand Up @@ -82,8 +82,8 @@ func (s *statsInnerCache) GetByQuery(tblID int64) (*statistics.Table, bool) {

// Get implements statsCacheInner
func (s *statsInnerCache) Get(tblID int64) (*statistics.Table, bool) {
s.Lock()
defer s.Unlock()
s.RLock()
defer s.RUnlock()
element, ok := s.elements[tblID]
if !ok {
return nil, false
Expand Down Expand Up @@ -135,10 +135,6 @@ func (s *statsInnerCache) updateIndices(tblID int64, tbl *statistics.Table, tblM
}
for idxID, index := range tbl.Indices {
idxMem := tblMemUsage.IndicesMemUsage[idxID]
if idxMem.TrackingMemUsage() < 1 {
deletedIdx = append(deletedIdx, idxID)
continue
}
s.lru.put(tblID, idxID, index, idxMem, true, needMove)
}
for _, idxID := range deletedIdx {
Expand Down Expand Up @@ -278,28 +274,28 @@ func (s *statsInnerCache) capacity() int64 {
return s.lru.capacity
}

func (c *innerItemLruCache) get(tblID, idxID int64) (*lruCacheItem, bool) {
func (c *innerItemLruCache) get(tblID, id int64) (*lruCacheItem, bool) {
v, ok := c.elements[tblID]
if !ok {
return nil, false
}
ele, ok := v[idxID]
ele, ok := v[id]
if !ok {
return nil, false
}
return ele.Value.(*lruCacheItem), true
}

func (c *innerItemLruCache) del(tblID, idxID int64) {
func (c *innerItemLruCache) del(tblID, id int64) {
v, ok := c.elements[tblID]
if !ok {
return
}
ele, ok := v[idxID]
ele, ok := v[id]
if !ok {
return
}
delete(c.elements[tblID], idxID)
delete(c.elements[tblID], id)
c.cache.Remove(ele)
}

Expand Down Expand Up @@ -367,7 +363,7 @@ func (c *innerItemLruCache) calculateCost(newUsage, oldUsage statistics.CacheIte
}

func (c *innerItemLruCache) copy() *innerItemLruCache {
newLRU := newInnerIndexLruCache(c.capacity)
newLRU := newInnerLruCache(c.capacity)
curr := c.cache.Back()
for curr != nil {
item := curr.Value.(*lruCacheItem)
Expand Down

0 comments on commit 107d4c0

Please sign in to comment.