make reader_at handle random reads more efficiently for FUSE

This commit is contained in:
Nathan Hawkins
2021-04-28 19:13:37 -04:00
parent 83cf94ad2d
commit 042de9359c
6 changed files with 152 additions and 7 deletions

View File

@@ -31,6 +31,20 @@ func (c *ChunkCacheInMemory) GetChunk(fileId string) []byte {
return data
}
func (c *ChunkCacheInMemory) getChunkSlice(fileId string, offset, length uint64) ([]byte, error) {
item := c.cache.Get(fileId)
if item == nil {
return nil, nil
}
data := item.Value().([]byte)
item.Extend(time.Hour)
wanted := min(int(length), len(data)-int(offset))
if wanted < 0 {
return nil, ErrorOutOfBounds
}
return data[offset : int(offset)+wanted], nil
}
func (c *ChunkCacheInMemory) SetChunk(fileId string, data []byte) {
localCopy := make([]byte, len(data))
copy(localCopy, data)