|
@ -26,6 +26,7 @@ type ChunkReadAt struct { |
|
|
chunkCache chunk_cache.ChunkCache |
|
|
chunkCache chunk_cache.ChunkCache |
|
|
lastChunkFileId string |
|
|
lastChunkFileId string |
|
|
lastChunkData []byte |
|
|
lastChunkData []byte |
|
|
|
|
|
readerPattern *ReaderPattern |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var _ = io.ReaderAt(&ChunkReadAt{}) |
|
|
var _ = io.ReaderAt(&ChunkReadAt{}) |
|
@ -92,6 +93,7 @@ func NewChunkReaderAtFromClient(lookupFn wdclient.LookupFileIdFunctionType, chun |
|
|
lookupFileId: lookupFn, |
|
|
lookupFileId: lookupFn, |
|
|
chunkCache: chunkCache, |
|
|
chunkCache: chunkCache, |
|
|
fileSize: fileSize, |
|
|
fileSize: fileSize, |
|
|
|
|
|
readerPattern: NewReaderPattern(), |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -106,6 +108,8 @@ func (c *ChunkReadAt) ReadAt(p []byte, offset int64) (n int, err error) { |
|
|
c.readerLock.Lock() |
|
|
c.readerLock.Lock() |
|
|
defer c.readerLock.Unlock() |
|
|
defer c.readerLock.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
c.readerPattern.MonitorReadAt(offset, len(p)) |
|
|
|
|
|
|
|
|
// glog.V(4).Infof("ReadAt [%d,%d) of total file size %d bytes %d chunk views", offset, offset+int64(len(p)), c.fileSize, len(c.chunkViews))
|
|
|
// glog.V(4).Infof("ReadAt [%d,%d) of total file size %d bytes %d chunk views", offset, offset+int64(len(p)), c.fileSize, len(c.chunkViews))
|
|
|
return c.doReadAt(p, offset) |
|
|
return c.doReadAt(p, offset) |
|
|
} |
|
|
} |
|
@ -171,6 +175,10 @@ func (c *ChunkReadAt) doReadAt(p []byte, offset int64) (n int, err error) { |
|
|
|
|
|
|
|
|
func (c *ChunkReadAt) readChunkSlice(chunkView *ChunkView, nextChunkViews *ChunkView, offset, length uint64) ([]byte, error) { |
|
|
func (c *ChunkReadAt) readChunkSlice(chunkView *ChunkView, nextChunkViews *ChunkView, offset, length uint64) ([]byte, error) { |
|
|
|
|
|
|
|
|
|
|
|
if c.readerPattern.IsRandomMode() { |
|
|
|
|
|
return c.doFetchRangeChunkData(chunkView, offset, length) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
chunkSlice := c.chunkCache.GetChunkSlice(chunkView.FileId, offset, length) |
|
|
chunkSlice := c.chunkCache.GetChunkSlice(chunkView.FileId, offset, length) |
|
|
if len(chunkSlice) > 0 { |
|
|
if len(chunkSlice) > 0 { |
|
|
return chunkSlice, nil |
|
|
return chunkSlice, nil |
|
@ -243,3 +251,15 @@ func (c *ChunkReadAt) doFetchFullChunkData(chunkView *ChunkView) ([]byte, error) |
|
|
return data, err |
|
|
return data, err |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *ChunkReadAt) doFetchRangeChunkData(chunkView *ChunkView, offset, length uint64) ([]byte, error) { |
|
|
|
|
|
|
|
|
|
|
|
glog.V(4).Infof("+ doFetchFullChunkData %s", chunkView.FileId) |
|
|
|
|
|
|
|
|
|
|
|
data, err := fetchChunkRange(c.lookupFileId, chunkView.FileId, chunkView.CipherKey, chunkView.IsGzipped, int64(offset), int(length)) |
|
|
|
|
|
|
|
|
|
|
|
glog.V(4).Infof("- doFetchFullChunkData %s", chunkView.FileId) |
|
|
|
|
|
|
|
|
|
|
|
return data, err |
|
|
|
|
|
|
|
|
|
|
|
} |