Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

objtools: fix 5GiB+ server-side copies on S3 #8427

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
* [ENHANCEMENT] ulidtime: add option to show random part of ULID, timestamp in milliseconds and header. #7615
* [ENHANCEMENT] copyblocks: add a flag to configure part-size for multipart uploads in s3 client-side copying. #8292
* [ENHANCEMENT] copyblocks: enable pprof HTTP endpoints. #8292
* [BUGFIX] objtools: use a multipart upload to server-side copy objects greater than 5GiB in size on S3. #8427

## 2.12.0

Expand Down
53 changes: 45 additions & 8 deletions pkg/util/objtools/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,59 @@ func (bkt *s3Bucket) Get(ctx context.Context, objectName string, options GetOpti
return obj, nil
}

const maxSingleCopySize int64 = 5 * (1024 * 1024 * 1024) // 5 GiB

func (bkt *s3Bucket) ServerSideCopy(ctx context.Context, objectName string, dstBucket Bucket, options CopyOptions) error {
d, ok := dstBucket.(*s3Bucket)
if !ok {
return errors.New("destination Bucket wasn't an S3 Bucket")
}
_, err := d.client.CopyObject(ctx,
minio.CopyDestOptions{
Bucket: d.bucketName,
Object: options.destinationObjectName(objectName),
},
minio.CopySrcOptions{

stat, err := bkt.client.StatObject(ctx, bkt.bucketName, objectName, minio.StatObjectOptions{
VersionID: options.SourceVersionID,
})
if err != nil {
return err
}

dstOptions := minio.CopyDestOptions{
Bucket: d.bucketName,
Object: options.destinationObjectName(objectName),
}

if stat.Size <= maxSingleCopySize {
_, err := d.client.CopyObject(
ctx,
dstOptions,
minio.CopySrcOptions{
Bucket: bkt.bucketName,
Object: objectName,
VersionID: options.SourceVersionID,
},
)
return err
}

parts := stat.Size / maxSingleCopySize
if stat.Size%maxSingleCopySize != 0 {
parts++
}
srcOptions := make([]minio.CopySrcOptions, 0, parts)
start := int64(0)
end := maxSingleCopySize - 1
for start < stat.Size {
srcOptions = append(srcOptions, minio.CopySrcOptions{
Bucket: bkt.bucketName,
Object: objectName,
VersionID: options.SourceVersionID,
},
)
Start: start,
End: end,
})
start = end + 1
end += maxSingleCopySize
}
srcOptions[len(srcOptions)-1].End = stat.Size - 1
_, err = d.client.ComposeObject(ctx, dstOptions, srcOptions...)
return err
}

Expand Down
Loading