1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2024-07-03 23:56:41 +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) { func (c *ChunkCache) doGetChunk(fileId string, chunkSize uint64) (data []byte) {
data = c.memCache.GetChunk(fileId) if chunkSize < memCacheSizeLimit {
if len(data) != 0 && len(data) >= int(chunkSize) { data = c.memCache.GetChunk(fileId)
return data if len(data) >= int(chunkSize) {
return data
}
} }
fid, err := needle.ParseFileIdFromString(fileId) fid, err := needle.ParseFileIdFromString(fileId)
@ -57,9 +59,21 @@ func (c *ChunkCache) doGetChunk(fileId string, chunkSize uint64) (data []byte) {
return nil return nil
} }
for _, diskCache := range c.diskCaches { if chunkSize < onDiskCacheSizeLimit0 {
data := diskCache.getChunk(fid.Key) data = c.diskCaches[0].getChunk(fid.Key)
if len(data) != 0 && len(data) >= int(chunkSize) { 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 return data
} }
} }