fix(storage): bound the upload part size so uploads don't OOM the registry (#44)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit was merged in pull request #44.
This commit is contained in:
1 parent
485f3432ac
commit
b424e001dc
2 files changed
+27
-1
No files matched your search
@@ -78,8 +78,19 @@ func NewS3(ctx context.Context, cfg Config) (*S3, error) {
|
||||
return &S3{client: client, bucket: cfg.Bucket}, nil
|
||||
}
|
||||
|
||||
// uploadPartSize is the multipart chunk minio-go buffers in memory. Uploads
|
||||
// are streamed with an unknown size, and minio-go then sizes a part for the
|
||||
// largest possible object (5 TiB / 10000 parts, about 550 MiB) and allocates
|
||||
// it up front: every upload killed the registry at its 384 MiB limit. 16 MiB
|
||||
// parts cap the buffer and still allow objects far beyond the upload limit.
|
||||
const uploadPartSize = 16 << 20
|
||||
|
||||
func putOptions(contentType string) minio.PutObjectOptions {
|
||||
return minio.PutObjectOptions{ContentType: contentType, PartSize: uploadPartSize}
|
||||
}
|
||||
|
||||
func (s *S3) Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error {
|
||||
_, err := s.client.PutObject(ctx, s.bucket, key, r, size, minio.PutObjectOptions{ContentType: contentType})
|
||||
_, err := s.client.PutObject(ctx, s.bucket, key, r, size, putOptions(contentType))
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -55,3 +55,18 @@ func TestMemory(t *testing.T) {
|
||||
t.Fatal("FailPut ignored")
|
||||
}
|
||||
}
|
||||
|
||||
// A streamed upload (size -1) must not make minio-go allocate a part sized
|
||||
// for a 5 TiB object.
|
||||
func TestPutOptions_boundPartSize(t *testing.T) {
|
||||
o := putOptions("application/pdf")
|
||||
if o.ContentType != "application/pdf" {
|
||||
t.Fatalf("content type = %q", o.ContentType)
|
||||
}
|
||||
if o.PartSize != 16<<20 {
|
||||
t.Fatalf("part size = %d, want 16 MiB", o.PartSize)
|
||||
}
|
||||
if o.ConcurrentStreamParts {
|
||||
t.Fatal("concurrent stream parts would buffer several parts at once")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user