Bruce
3 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
11 additions and
6 deletions
-
weed/filer/reader_at.go
-
weed/filer/reader_cache.go
-
weed/util/chunk_cache/chunk_cache.go
|
|
@ -199,7 +199,8 @@ func (c *ChunkReadAt) readChunkSliceAt(buffer []byte, chunkView *ChunkView, next |
|
|
|
return fetchChunkRange(buffer, c.readerCache.lookupFileIdFn, chunkView.FileId, chunkView.CipherKey, chunkView.IsGzipped, int64(offset)) |
|
|
|
} |
|
|
|
|
|
|
|
n, err = c.readerCache.ReadChunkAt(buffer, chunkView.FileId, chunkView.CipherKey, chunkView.IsGzipped, int64(offset), int(chunkView.ChunkSize), (uint64(chunkView.ViewOffset)+chunkView.ChunkSize) <= c.readerCache.chunkCache.GetMaxFilePartSizeInCache()) |
|
|
|
shouldCache := (uint64(chunkView.ViewOffset) + chunkView.ChunkSize) <= c.readerCache.chunkCache.GetMaxFilePartSizeInCache() |
|
|
|
n, err = c.readerCache.ReadChunkAt(buffer, chunkView.FileId, chunkView.CipherKey, chunkView.IsGzipped, int64(offset), int(chunkView.ChunkSize), shouldCache) |
|
|
|
if c.lastChunkFid != chunkView.FileId { |
|
|
|
if chunkView.OffsetInChunk == 0 { // start of a new chunk
|
|
|
|
if c.lastChunkFid != "" { |
|
|
|
|
|
@ -74,7 +74,8 @@ func (rc *ReaderCache) MaybeCache(chunkViews *Interval[*ChunkView]) { |
|
|
|
|
|
|
|
// glog.V(4).Infof("prefetch %s offset %d", chunkView.FileId, chunkView.ViewOffset)
|
|
|
|
// cache this chunk if not yet
|
|
|
|
cacher := newSingleChunkCacher(rc, chunkView.FileId, chunkView.CipherKey, chunkView.IsGzipped, int(chunkView.ChunkSize), (uint64(chunkView.ViewOffset)+chunkView.ChunkSize) <= rc.chunkCache.GetMaxFilePartSizeInCache()) |
|
|
|
shouldCache := (uint64(chunkView.ViewOffset) + chunkView.ChunkSize) <= rc.chunkCache.GetMaxFilePartSizeInCache() |
|
|
|
cacher := newSingleChunkCacher(rc, chunkView.FileId, chunkView.CipherKey, chunkView.IsGzipped, int(chunkView.ChunkSize), shouldCache) |
|
|
|
go cacher.startCaching() |
|
|
|
<-cacher.cacheStartedCh |
|
|
|
rc.downloaders[chunkView.FileId] = cacher |
|
|
|
|
|
@ -42,12 +42,15 @@ func NewTieredChunkCache(maxEntries int64, dir string, diskSizeInUnit int64, uni |
|
|
|
c.diskCaches[0] = NewOnDiskCacheLayer(dir, "c0_2", diskSizeInUnit*unitSize/8, 2) |
|
|
|
c.diskCaches[1] = NewOnDiskCacheLayer(dir, "c1_3", diskSizeInUnit*unitSize/4+diskSizeInUnit*unitSize/8, 3) |
|
|
|
c.diskCaches[2] = NewOnDiskCacheLayer(dir, "c2_2", diskSizeInUnit*unitSize/2, 2) |
|
|
|
c.maxFilePartSizeInCache = uint64(unitSize*diskSizeInUnit)/4 |
|
|
|
c.maxFilePartSizeInCache = uint64(unitSize*diskSizeInUnit) / 4 |
|
|
|
|
|
|
|
return c |
|
|
|
} |
|
|
|
|
|
|
|
func (c *TieredChunkCache) GetMaxFilePartSizeInCache() (answer uint64) { |
|
|
|
if c == nil { |
|
|
|
return 0 |
|
|
|
} |
|
|
|
return c.maxFilePartSizeInCache |
|
|
|
} |
|
|
|
|
|
|
|