1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2024-07-01 22:56:38 +02:00

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

This commit is contained in:
Chris Lu 2020-06-27 12:51:04 -07:00
parent a808b3b5df
commit bef356ce4c

View file

@ -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
}
}