diff options
| author | chrislu <chris.lu@gmail.com> | 2022-09-04 18:50:45 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2022-09-04 18:50:45 -0700 |
| commit | 8c5759a06dbe30faa97ede493680e3e38969064f (patch) | |
| tree | 72aa6c40816522ec3cd0f45ce1fd1b62e106d065 | |
| parent | 70777d9b9f03d12b1c9a23a25f26ea729de89d7b (diff) | |
| download | seaweedfs-8c5759a06dbe30faa97ede493680e3e38969064f.tar.xz seaweedfs-8c5759a06dbe30faa97ede493680e3e38969064f.zip | |
minor optimization
| -rw-r--r-- | weed/storage/volume_read.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/weed/storage/volume_read.go b/weed/storage/volume_read.go index b38ec32d3..d4d795fee 100644 --- a/weed/storage/volume_read.go +++ b/weed/storage/volume_read.go @@ -107,7 +107,7 @@ func (v *Volume) readNeedleDataInto(n *needle.Needle, readOption *ReadOption, wr readOption.IsOutOfRange = false err = n.ReadNeedleMeta(v.DataBackend, nv.Offset.ToActualOffset(), readSize, v.Version()) } - buf := mem.Allocate(1024 * 1024) + buf := mem.Allocate(min(1024*1024, int(size))) defer mem.Free(buf) actualOffset := nv.Offset.ToActualOffset() if readOption.IsOutOfRange { @@ -117,6 +117,13 @@ func (v *Volume) readNeedleDataInto(n *needle.Needle, readOption *ReadOption, wr return n.ReadNeedleDataInto(v.DataBackend, actualOffset, buf, writer, offset, size) } +func min(x, y int) int { + if x < y { + return x + } + return y +} + // read fills in Needle content by looking up n.Id from NeedleMapper func (v *Volume) ReadNeedleBlob(offset int64, size Size) ([]byte, error) { v.dataFileAccessLock.RLock() |
