SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
s3: an abort answered mid-part no longer leaves the upload completable (#11025)
Chris Lu7dc3835b0252
diff --git a/weed/s3api/filer_multipart.go b/weed/s3api/filer_multipart.goindex b1d847fe68..fd537260e5 100644--- a/weed/s3api/filer_multipart.go+++ b/weed/s3api/filer_multipart.go@@ -411,6 +411,11 @@ func (s3a *S3ApiServer) prepareMultipartCompletionState(r *http.Request, input *}return nil, nil, s3err.ErrInternalError}+ // only createMultipartUpload stamps the key; a directory a part write left behind is not an upload+ if !isMultipartUploadEntry(pentry) {+ stats.S3HandlerCounter.WithLabelValues(stats.ErrorCompletedNoSuchUpload).Inc()+ return nil, nil, s3err.ErrNoSuchUpload+ }deleteEntries := make([]*filer_pb.Entry, 0)partEntries := make(map[int][]*filer_pb.Entry, len(entries))diff --git a/weed/s3api/s3api_multipart_upload_entry_test.go b/weed/s3api/s3api_multipart_upload_entry_test.gonew file mode 100644index 0000000000..024c88fa83--- /dev/null+++ b/weed/s3api/s3api_multipart_upload_entry_test.go@@ -0,0 +1,28 @@+package s3api++import (+ "testing"++ "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"+ "github.com/seaweedfs/seaweedfs/weed/s3api/s3_constants"+)++func TestIsMultipartUploadEntry(t *testing.T) {+ tests := []struct {+ name string+ entry *filer_pb.Entry+ want bool+ }{+ {"aborted upload", nil, false},+ {"directory re-created by a part write", &filer_pb.Entry{IsDirectory: true}, false},+ {"key emptied", &filer_pb.Entry{IsDirectory: true, Extended: map[string][]byte{s3_constants.ExtMultipartObjectKey: {}}}, false},+ {"open upload", &filer_pb.Entry{IsDirectory: true, Extended: map[string][]byte{s3_constants.ExtMultipartObjectKey: []byte("a.bin")}}, true},+ }+ for _, tc := range tests {+ t.Run(tc.name, func(t *testing.T) {+ if got := isMultipartUploadEntry(tc.entry); got != tc.want {+ t.Errorf("isMultipartUploadEntry() = %v, want %v", got, tc.want)+ }+ })+ }+}diff --git a/weed/s3api/s3api_object_handlers_copy.go b/weed/s3api/s3api_object_handlers_copy.goindex f1e69b6e95..5885188e19 100644--- a/weed/s3api/s3api_object_handlers_copy.go+++ b/weed/s3api/s3api_object_handlers_copy.go@@ -1028,6 +1028,10 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Reqs3err.WriteErrorResponse(w, r, errCode)return}+ // the copy above re-creates a directory an abort removed mid-copy+ if !s3a.checkUploadStillOpen(w, r, dstBucket, dstObject, uploadID) {+ return+ }setEtag(w, "\""+strings.Trim(etag, "\"")+"\"")// Mirror PutObjectPartHandler: write x-amz-server-side-encryption /// x-amz-server-side-encryption-aws-kms-key-id headers on the response@@ -1104,6 +1108,11 @@ func (s3a *S3ApiServer) CopyObjectPartHandler(w http.ResponseWriter, r *http.Reqreturn}+ // the copy above re-creates a directory an abort removed mid-copy+ if !s3a.checkUploadStillOpen(w, r, dstBucket, dstObject, uploadID) {+ return+ }+// Calculate ETag for the partetag := copyEntryETag(dstEntry)setEtag(w, etag)diff --git a/weed/s3api/s3api_object_handlers_multipart.go b/weed/s3api/s3api_object_handlers_multipart.goindex defdfbbd2b..f5c593c087 100644--- a/weed/s3api/s3api_object_handlers_multipart.go+++ b/weed/s3api/s3api_object_handlers_multipart.go@@ -469,6 +469,11 @@ func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Requreturn}+ // the write above re-creates a directory an abort removed mid-body+ if !s3a.checkUploadStillOpen(w, r, bucket, object, uploadID) {+ return+ }+glog.V(2).Infof("PutObjectPart: SUCCESS - bucket=%s, object=%s, partNumber=%d, etag=%s, sseType=%s",bucket, object, partID, etag, sseMetadata.SSEType)@@ -485,6 +490,38 @@ func (s3a *S3ApiServer) genUploadsFolder(bucket string) string {return fmt.Sprintf("%s/%s", s3a.bucketDir(bucket), s3_constants.MultipartUploadsFolder)}+// isMultipartUploadEntry tells the .uploads/<id> directory createMultipartUpload+// made from the one a part write re-created on its way to the filer: only the+// former carries the destination object key.+func isMultipartUploadEntry(entry *filer_pb.Entry) bool {+ return entry != nil && len(entry.Extended[s3_constants.ExtMultipartObjectKey]) > 0+}++// checkUploadStillOpen re-checks the upload after a part landed, and removes the+// part along with the directory it resurrected when an abort was answered while+// the part was in flight. It reports whether the caller may answer success.+func (s3a *S3ApiServer) checkUploadStillOpen(w http.ResponseWriter, r *http.Request, bucket, object, uploadID string) bool {+ entry, err := s3a.getEntry(s3a.genUploadsFolder(bucket), uploadID)+ if err != nil && !errors.Is(err, filer_pb.ErrNotFound) {+ glog.Errorf("checkUploadStillOpen %s/%s: %v", bucket, uploadID, err)+ s3err.WriteErrorResponse(w, r, s3err.ErrInternalError)+ return false+ }+ if isMultipartUploadEntry(entry) {+ return true+ }+ // the upload is gone either way, so the client still hears NoSuchUpload+ if _, code := s3a.abortMultipartUpload(&s3.AbortMultipartUploadInput{+ Bucket: aws.String(bucket),+ Key: objectKey(aws.String(object)),+ UploadId: aws.String(uploadID),+ }); code != s3err.ErrNone {+ glog.Warningf("checkUploadStillOpen %s/%s: part left behind, cleanup failed", bucket, uploadID)+ }+ s3err.WriteErrorResponse(w, r, s3err.ErrNoSuchUpload)+ return false+}+// getMultipartSSEAlgorithm returns the canonical SSE algorithm ("AES256" or// "aws:kms") that was stored when the multipart upload was initiated, or ""// if the upload entry is not found or had no SSE. It is used by the bucket