diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-08-16 00:49:26 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-08-16 00:49:26 -0700 |
| commit | 1d9ea30b7254a11232acfb265fe25954345333e6 (patch) | |
| tree | acdd78af4f43d64a7bb1883a7d34174ed37c400c /weed/filer2/filechunks.go | |
| parent | aec7f32b02c04aee315f67922cdb3813dbe7af72 (diff) | |
| download | seaweedfs-1d9ea30b7254a11232acfb265fe25954345333e6.tar.xz seaweedfs-1d9ea30b7254a11232acfb265fe25954345333e6.zip | |
fix ViewFromVisibleIntervals
Diffstat (limited to 'weed/filer2/filechunks.go')
| -rw-r--r-- | weed/filer2/filechunks.go | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/weed/filer2/filechunks.go b/weed/filer2/filechunks.go index 9de888d50..1d546bad0 100644 --- a/weed/filer2/filechunks.go +++ b/weed/filer2/filechunks.go @@ -7,6 +7,7 @@ import ( "sort" "sync" + "github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" ) @@ -134,17 +135,19 @@ func ViewFromVisibleIntervals(visibles []VisibleInterval, offset int64, size int for _, chunk := range visibles { - if chunk.start <= offset && offset < chunk.stop && offset < stop { + glog.V(1).Infof("visible [%d,%d)", chunk.start, chunk.stop) + chunkStart, chunkStop := max(offset, chunk.start), min(stop, chunk.stop) + + if chunkStart < chunkStop { views = append(views, &ChunkView{ FileId: chunk.fileId, - Offset: offset - chunk.start, // offset is the data starting location in this file id - Size: uint64(min(chunk.stop, stop) - offset), - LogicOffset: offset, + Offset: chunkStart-chunk.start, + Size: uint64(chunkStop - chunkStart), + LogicOffset: chunk.start, ChunkSize: chunk.chunkSize, CipherKey: chunk.cipherKey, IsGzipped: chunk.isGzipped, }) - offset = min(chunk.stop, stop) } } @@ -266,3 +269,9 @@ func min(x, y int64) int64 { } return y } +func max(x, y int64) int64 { + if x <= y { + return y + } + return x +} |
