aboutsummaryrefslogtreecommitdiff
path: root/weed/filer2/filechunks.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2018-05-23 22:28:54 -0700
committerChris Lu <chris.lu@gmail.com>2018-05-23 22:28:54 -0700
commit00d0274fd7c829f5d26c051f5832e0f602929b08 (patch)
tree76025aee287cfd02d99c04170a7bf40b61041c44 /weed/filer2/filechunks.go
parent849b6ec28d96540d530cf18c9f6fe3a08c1f5755 (diff)
downloadseaweedfs-00d0274fd7c829f5d26c051f5832e0f602929b08.tar.xz
seaweedfs-00d0274fd7c829f5d26c051f5832e0f602929b08.zip
prepare to read from multiple file chunks
Diffstat (limited to 'weed/filer2/filechunks.go')
-rw-r--r--weed/filer2/filechunks.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/weed/filer2/filechunks.go b/weed/filer2/filechunks.go
index 65197d471..93cee81de 100644
--- a/weed/filer2/filechunks.go
+++ b/weed/filer2/filechunks.go
@@ -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