Skip to content

Commit e7a6ce2

Browse files
lunixbochsbenmcclelland
authored andcommitted
feat: make zero-copy GetObject possible via sendfile
From versity#919, This provides the *os.File handle to io.Copy() for the case where the full file range is requested. This prevents hiding the *os.File type for io.Copy() optimizations. This still requires the change to valyala/fasthttp#1889 to expose the net.Conn similarly to enable the linux sendfile optimization.
1 parent a53667c commit e7a6ce2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

backend/posix/posix.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,7 +2931,12 @@ func (p *Posix) GetObject(_ context.Context, input *s3.GetObjectInput) (*s3.GetO
29312931
return nil, fmt.Errorf("open object: %w", err)
29322932
}
29332933

2934-
rdr := io.NewSectionReader(f, startOffset, length)
2934+
// using an os.File allows zero-copy sendfile via io.Copy(os.File, net.Conn)
2935+
var body io.ReadCloser = f
2936+
if startOffset != 0 || length != objSize {
2937+
rdr := io.NewSectionReader(f, startOffset, length)
2938+
body = &backend.FileSectionReadCloser{R: rdr, F: f}
2939+
}
29352940

29362941
return &s3.GetObjectOutput{
29372942
AcceptRanges: &acceptRange,
@@ -2945,7 +2950,7 @@ func (p *Posix) GetObject(_ context.Context, input *s3.GetObjectInput) (*s3.GetO
29452950
ContentRange: &contentRange,
29462951
StorageClass: types.StorageClassStandard,
29472952
VersionId: &versionId,
2948-
Body: &backend.FileSectionReadCloser{R: rdr, F: f},
2953+
Body: body,
29492954
}, nil
29502955
}
29512956

0 commit comments

Comments
 (0)