mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
a little optimization
This commit is contained in:
parent
2a1f396df5
commit
e613695af7
|
@ -105,9 +105,11 @@ func (c *ChunkReadAt) fetchChunkData(chunkView *ChunkView) (data []byte, err err
|
||||||
|
|
||||||
// fmt.Printf("fetching %s [%d,%d)\n", chunkView.FileId, chunkView.LogicOffset, chunkView.LogicOffset+int64(chunkView.Size))
|
// fmt.Printf("fetching %s [%d,%d)\n", chunkView.FileId, chunkView.LogicOffset, chunkView.LogicOffset+int64(chunkView.Size))
|
||||||
|
|
||||||
|
hasDataInCache := false
|
||||||
chunkData := c.chunkCache.GetChunk(chunkView.FileId)
|
chunkData := c.chunkCache.GetChunk(chunkView.FileId)
|
||||||
if chunkData != nil {
|
if chunkData != nil {
|
||||||
glog.V(3).Infof("cache hit %s [%d,%d)", chunkView.FileId, chunkView.LogicOffset, chunkView.LogicOffset+int64(chunkView.Size))
|
glog.V(3).Infof("cache hit %s [%d,%d)", chunkView.FileId, chunkView.LogicOffset, chunkView.LogicOffset+int64(chunkView.Size))
|
||||||
|
hasDataInCache = true
|
||||||
} else {
|
} else {
|
||||||
chunkData, err = c.doFetchFullChunkData(chunkView.FileId, chunkView.CipherKey, chunkView.IsGzipped)
|
chunkData, err = c.doFetchFullChunkData(chunkView.FileId, chunkView.CipherKey, chunkView.IsGzipped)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -121,7 +123,9 @@ func (c *ChunkReadAt) fetchChunkData(chunkView *ChunkView) (data []byte, err err
|
||||||
|
|
||||||
data = chunkData[chunkView.Offset : chunkView.Offset+int64(chunkView.Size)]
|
data = chunkData[chunkView.Offset : chunkView.Offset+int64(chunkView.Size)]
|
||||||
|
|
||||||
|
if !hasDataInCache {
|
||||||
c.chunkCache.SetChunk(chunkView.FileId, chunkData)
|
c.chunkCache.SetChunk(chunkView.FileId, chunkData)
|
||||||
|
}
|
||||||
|
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue