incase the memory data is too small

This commit is contained in:
Chris Lu 2020-06-27 11:59:12 -07:00
parent c3fed4fb6b
commit a808b3b5df

View file

@ -46,10 +46,9 @@ func (c *ChunkCache) GetChunk(fileId string, chunkSize uint64) (data []byte) {
func (c *ChunkCache) doGetChunk(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 data = c.memCache.GetChunk(fileId); data != nil { if len(data) != 0 && len(data) >= int(chunkSize) {
return data return data
}
} }
fid, err := needle.ParseFileIdFromString(fileId) fid, err := needle.ParseFileIdFromString(fileId)
@ -58,21 +57,9 @@ func (c *ChunkCache) doGetChunk(fileId string, chunkSize uint64) (data []byte) {
return nil return nil
} }
if chunkSize < onDiskCacheSizeLimit0 { for _, diskCache := range c.diskCaches {
data = c.diskCaches[0].getChunk(fid.Key) data := diskCache.getChunk(fid.Key)
if len(data) >= int(chunkSize) { if len(data) != 0 && 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 return data
} }
} }