From bef356ce4ca3c95a77123ea6ff5c89b9c2a8ab36 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 27 Jun 2020 12:51:04 -0700 Subject: [PATCH] since we already know the chunk size, no need to iterate --- weed/util/chunk_cache/chunk_cache.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/weed/util/chunk_cache/chunk_cache.go b/weed/util/chunk_cache/chunk_cache.go index 3ae0f4ed5..17b64fb6c 100644 --- a/weed/util/chunk_cache/chunk_cache.go +++ b/weed/util/chunk_cache/chunk_cache.go @@ -46,9 +46,11 @@ func (c *ChunkCache) GetChunk(fileId string, chunkSize uint64) (data []byte) { func (c *ChunkCache) doGetChunk(fileId string, chunkSize uint64) (data []byte) { - data = c.memCache.GetChunk(fileId) - if len(data) != 0 && len(data) >= int(chunkSize) { - return data + if chunkSize < memCacheSizeLimit { + data = c.memCache.GetChunk(fileId) + if len(data) >= int(chunkSize) { + return data + } } fid, err := needle.ParseFileIdFromString(fileId) @@ -57,9 +59,21 @@ func (c *ChunkCache) doGetChunk(fileId string, chunkSize uint64) (data []byte) { return nil } - for _, diskCache := range c.diskCaches { - data := diskCache.getChunk(fid.Key) - if len(data) != 0 && len(data) >= int(chunkSize) { + if chunkSize < onDiskCacheSizeLimit0 { + data = c.diskCaches[0].getChunk(fid.Key) + if len(data) >= int(chunkSize) { + return data + } + } + if chunkSize < onDiskCacheSizeLimit1 { + data = c.diskCaches[1].getChunk(fid.Key) + if len(data) >= int(chunkSize) { + return data + } + } + { + data = c.diskCaches[2].getChunk(fid.Key) + if len(data) >= int(chunkSize) { return data } }