lib/mergeset: properly update lastAccesstime in indexBlockCache entries

This is a follow-up for 6665f10e7b
This commit is contained in:
Aliaksandr Valialkin 2020-01-29 21:19:17 +02:00
parent 170c1c3a4e
commit cb2a2f281f

View file

@ -172,7 +172,7 @@ type indexBlockCache struct {
requests uint64 requests uint64
misses uint64 misses uint64
m map[uint64]indexBlockCacheEntry m map[uint64]*indexBlockCacheEntry
mu sync.RWMutex mu sync.RWMutex
cleanerStopCh chan struct{} cleanerStopCh chan struct{}
@ -190,7 +190,7 @@ type indexBlockCacheEntry struct {
func newIndexBlockCache() *indexBlockCache { func newIndexBlockCache() *indexBlockCache {
var idxbc indexBlockCache var idxbc indexBlockCache
idxbc.m = make(map[uint64]indexBlockCacheEntry) idxbc.m = make(map[uint64]*indexBlockCacheEntry)
idxbc.cleanerStopCh = make(chan struct{}) idxbc.cleanerStopCh = make(chan struct{})
idxbc.cleanerWG.Add(1) idxbc.cleanerWG.Add(1)
go func() { go func() {
@ -248,10 +248,10 @@ var (
func (idxbc *indexBlockCache) Get(k uint64) *indexBlock { func (idxbc *indexBlockCache) Get(k uint64) *indexBlock {
atomic.AddUint64(&idxbc.requests, 1) atomic.AddUint64(&idxbc.requests, 1)
idxbc.mu.RLock() idxbc.mu.RLock()
idxbe, ok := idxbc.m[k] idxbe := idxbc.m[k]
idxbc.mu.RUnlock() idxbc.mu.RUnlock()
if ok { if idxbe != nil {
currentTime := atomic.LoadUint64(&currentTimestamp) currentTime := atomic.LoadUint64(&currentTimestamp)
if atomic.LoadUint64(&idxbe.lastAccessTime) != currentTime { if atomic.LoadUint64(&idxbe.lastAccessTime) != currentTime {
atomic.StoreUint64(&idxbe.lastAccessTime, currentTime) atomic.StoreUint64(&idxbe.lastAccessTime, currentTime)
@ -284,7 +284,7 @@ func (idxbc *indexBlockCache) Put(k uint64, idxb *indexBlock) bool {
} }
// Store idxb in the cache. // Store idxb in the cache.
idxbe := indexBlockCacheEntry{ idxbe := &indexBlockCacheEntry{
lastAccessTime: atomic.LoadUint64(&currentTimestamp), lastAccessTime: atomic.LoadUint64(&currentTimestamp),
idxb: idxb, idxb: idxb,
} }