|
@ -24,9 +24,12 @@ type ChunkReadAt struct { |
|
|
|
|
|
|
|
|
fetchGroup singleflight.Group |
|
|
fetchGroup singleflight.Group |
|
|
chunkCache chunk_cache.ChunkCache |
|
|
chunkCache chunk_cache.ChunkCache |
|
|
|
|
|
lastChunkFileId string |
|
|
|
|
|
lastChunkData []byte |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// var _ = io.ReaderAt(&ChunkReadAt{})
|
|
|
|
|
|
|
|
|
var _ = io.ReaderAt(&ChunkReadAt{}) |
|
|
|
|
|
var _ = io.Closer(&ChunkReadAt{}) |
|
|
|
|
|
|
|
|
type LookupFileIdFunctionType func(fileId string) (targetUrls []string, err error) |
|
|
type LookupFileIdFunctionType func(fileId string) (targetUrls []string, err error) |
|
|
|
|
|
|
|
@ -94,6 +97,12 @@ func NewChunkReaderAtFromClient(filerClient filer_pb.FilerClient, chunkViews []* |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *ChunkReadAt) Close() error { |
|
|
|
|
|
c.lastChunkData = nil |
|
|
|
|
|
c.lastChunkFileId = "" |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func (c *ChunkReadAt) ReadAt(p []byte, offset int64) (n int, err error) { |
|
|
func (c *ChunkReadAt) ReadAt(p []byte, offset int64) (n int, err error) { |
|
|
|
|
|
|
|
|
c.readerLock.Lock() |
|
|
c.readerLock.Lock() |
|
@ -162,6 +171,10 @@ func (c *ChunkReadAt) doReadAt(p []byte, offset int64) (n int, err error) { |
|
|
|
|
|
|
|
|
func (c *ChunkReadAt) readFromWholeChunkData(chunkView *ChunkView, nextChunkViews ...*ChunkView) (chunkData []byte, err error) { |
|
|
func (c *ChunkReadAt) readFromWholeChunkData(chunkView *ChunkView, nextChunkViews ...*ChunkView) (chunkData []byte, err error) { |
|
|
|
|
|
|
|
|
|
|
|
if c.lastChunkFileId == chunkView.FileId { |
|
|
|
|
|
return c.lastChunkData, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
v, doErr := c.readOneWholeChunk(chunkView) |
|
|
v, doErr := c.readOneWholeChunk(chunkView) |
|
|
|
|
|
|
|
|
if doErr != nil { |
|
|
if doErr != nil { |
|
@ -170,6 +183,9 @@ func (c *ChunkReadAt) readFromWholeChunkData(chunkView *ChunkView, nextChunkView |
|
|
|
|
|
|
|
|
chunkData = v.([]byte) |
|
|
chunkData = v.([]byte) |
|
|
|
|
|
|
|
|
|
|
|
c.lastChunkData = chunkData |
|
|
|
|
|
c.lastChunkFileId = chunkView.FileId |
|
|
|
|
|
|
|
|
for _, nextChunkView := range nextChunkViews { |
|
|
for _, nextChunkView := range nextChunkViews { |
|
|
if c.chunkCache != nil && nextChunkView != nil { |
|
|
if c.chunkCache != nil && nextChunkView != nil { |
|
|
go c.readOneWholeChunk(nextChunkView) |
|
|
go c.readOneWholeChunk(nextChunkView) |
|
|