Browse Source

since we already know the chunk size, no need to iterate

pull/1377/head
Chris Lu 5 years ago
parent
commit
bef356ce4c
  1. 22
      weed/util/chunk_cache/chunk_cache.go

22
weed/util/chunk_cache/chunk_cache.go

@ -46,10 +46,12 @@ func (c *ChunkCache) GetChunk(fileId string, chunkSize uint64) (data []byte) {
func (c *ChunkCache) doGetChunk(fileId string, chunkSize uint64) (data []byte) {
if chunkSize < memCacheSizeLimit {
data = c.memCache.GetChunk(fileId)
if len(data) != 0 && len(data) >= int(chunkSize) {
if len(data) >= int(chunkSize) {
return data
}
}
fid, err := needle.ParseFileIdFromString(fileId)
if err != nil {
@ -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
}
}

Loading…
Cancel
Save