Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
- Hardware parameters:
- OS type:
- Others: code inspection of origin/main. No open issue covers this. [Feature Request]: multipart write data to stage. #18947 is a multipart feature request. MinIO and Aliyun
Writesend the reader toputObject. COS unknown-size non-seekable writes go throughWriteMultipartParallel, whose empty-reader path puts a zero-byte object.
Actual Behavior
AwsSDKv2.Write (pkg/fileservice/aws_sdk_v2.go 437–496) treats a nil sizeHint as a sequential multipart upload. It calls CreateMultipartUpload first. If the reader yields no bytes, the loop stops with num == 1 and the function return nil under the comment "no content".
That return is a success. The named err stays nil, so the defer that aborts the multipart upload does not run. CompleteMultipartUpload is not called, and there is no PutObject of a zero-byte object. The key does not exist, and the upload id remains.
S3FS.write (s3_fs.go 580–628) passes vector.size() through. IOVector.size (io_vector.go 165–176) returns nil when any entry has Size < 0. The ETL default parallel mode is ParallelOff (parallel_mode.go parseParallelMode(""), get.go etlParallelMode). With parallel mode off, an unknown-size stream uses storage.Write, which is this path.
Callers that then record success:
SELECT INTO OUTFILE/ export (pkg/frontend/export.go180–197,Close270–287). Header off and zero rows closes the pipe without a write.AsyncGroup.Waitsees a nil error and the statement succeeds.- Table dump of a zero-byte object (
pkg/frontend/table_dump.gostreamTableDumpFile691–712, recorded at 791–799) stores size 0 and the empty SHA-256, and adds the fixture path. Unlike the server-side copy branch, this path does notStatFilethe destination. - Backup
streamCopyFile(pkg/backup/tae.go833–875) returns the empty hash and a nil error. FileServiceWriter.Close(pkg/fileservice/file_service_writer.go49–66, 86–96) returns nil after an empty pipe.
WriteMultipartParallel handles the same empty reader by calling Write with a non-nil size of 0 (aws_sdk_v2.go 640–642), which takes the small-object PutObject path. A known Size: 0 entry does the same. Only the nil-sizeHint empty stream reports success without creating the key.
Expected Behavior
An empty unknown-size write should leave a zero-byte object at the key and return nil, matching the parallel empty path and a Size: 0 PutObject. If the multipart upload is not completed, Write should return the error and the existing defer should abort the upload id.
Steps to Reproduce
- Build an
AwsSDKv2client against S3 or a mock that recordsCreateMultipartUpload,PutObject,CompleteMultipartUpload, andAbortMultipartUpload. - Call
Write(ctx, key, bytes.NewReader(nil), nil, nil). - The call returns nil.
HeadObject/GetObjectis not found.ListMultipartUploadsstill contains the upload created in step 2.PutObjectandCompleteMultipartUploadwere not called.
The same outcome comes from S3FS created with ParallelMode: ParallelOff and Write of an IOVector whose only entry is {Size: -1, ReaderForWrite: bytes.NewReader(nil)}.
Additional information
A non-empty nil-sizeHint stream still uploads one part and completes, so a data-branch output that writes COMMIT;\n before close is not this case. The failure is the zero-byte stream. Each such statement leaks one incomplete multipart upload in addition to publishing a missing key.
Activity
fix(fileservice): publish empty unknown-size S3 writes (#29344)
Ariznawlll commentedon Sep 27, 2026
测试版本
main5be6cd90b501da225be591ffffe6000bf01f515e原问题验证
该问题依赖内部 reader 生命周期或 I/O 故障注入,公开 SQL 无法稳定制造目标失败点。已在最新 main 上运行对应定向测试
TestAwsSDKv2WriteUnknownSizeEmptyCreatesObject 及 multipart abort/cancel 测试,连续 3 次通过。Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
确认修复提交
7ce783464806490263c184f22aaf5d307225adef是当前 main 的祖先,并直接执行该提交新增的定向测试,结果 3/3 PASS。回归测试
回归已落在 MatrixOne UT:
TestAwsSDKv2WriteUnknownSizeEmptyCreatesObject 及 multipart abort/cancel 测试。未加入 MOTR,因为该场景必须注入内部 reader/I/O 失败,SQL 黑盒无法可靠触发;按覆盖矩阵应保留在 UT 层。测试证据
5be6cd90b501da225be591ffffe6000bf01f515e7ce783464806490263c184f22aaf5d307225adef测试结论
测试通过。
[4.2-dev] fix: finalize exports safely and clean up S3 uploads (#30742)