fix(flashnode): fix eof issues that could be caused by concurrent creation of cacheBlock.

close:#23100234

Signed-off-by: shuqiang-zheng <zhengshuqiang@oppo.com>
This commit is contained in:
shuqiang-zheng 2025-03-04 17:02:24 +08:00 committed by zhumingze1108
parent b36e228468
commit 24d656446f

View File

@ -622,6 +622,17 @@ func (c *CacheEngine) createCacheBlock(volume string, inode, fixedOffset uint64,
}()
}
v, ok = c.keyToDiskMap.Load(key)
if ok {
cacheItem := v.(*lruCacheItem)
if atomic.LoadInt32(&cacheItem.status) == proto.ReadWrite {
if blockValue, got := cacheItem.lruCache.Peek(key); got {
block = blockValue.(*CacheBlock)
return
}
}
}
var cacheItem *lruCacheItem
if cacheItem, err = c.selectAvailableLruCache(); err == nil {
block = NewCacheBlock(cacheItem.config.Path, volume, inode, fixedOffset, version, allocSize, c.readSourceFunc, clientIP)