prepare to read from multiple file chunks

This commit is contained in:
Chris Lu
2018-05-23 22:28:54 -07:00
parent 849b6ec28d
commit 00d0274fd7
2 changed files with 157 additions and 4 deletions

View File

@@ -52,6 +52,27 @@ func FindUnusedFileChunks(oldChunks, newChunks []*filer_pb.FileChunk) (unused []
return
}
func ReadFromChunks(chunks []*filer_pb.FileChunk, offset int64, size int) (views []*filer_pb.FileChunk) {
visibles := nonOverlappingVisibleIntervals(chunks)
stop := offset + int64(size)
for _, chunk := range visibles {
if chunk.start <= offset && offset < chunk.stop {
views = append(views, &filer_pb.FileChunk{
FileId: chunk.fileId,
Offset: offset - chunk.start, // offset is the data starting location in this file id
Size: uint64(min(chunk.stop, stop) - offset),
})
offset = min(chunk.stop, stop)
}
}
return views
}
func logPrintf(name string, visibles []*visibleInterval) {
return