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
feat(mount): attach Content-MD5 to chunk uploads (#10016)
Jaehoon Kim20e4614fc6ed
diff --git a/weed/mount/weedfs_write.go b/weed/mount/weedfs_write.goindex 0bcc6f21d7..dfe5a6e484 100644--- a/weed/mount/weedfs_write.go+++ b/weed/mount/weedfs_write.go@@ -26,12 +26,14 @@ func (wfs *WFS) saveDataAsChunk(fullPath util.FullPath) filer.SaveDataAsChunkFunreturn}+ // WantMd5 gives mount writes a real filer.ETag (server echoes Content-MD5 back).uploadOption := &operation.UploadOption{Filename: filename,Cipher: wfs.option.Cipher,IsInputCompressed: false,MimeType: "",PairMap: nil,+ WantMd5: true,}genFileUrlFn := func(host, fileId string) string {fileUrl := fmt.Sprintf("http://%s/%s", host, fileId)diff --git a/weed/operation/upload_content.go b/weed/operation/upload_content.goindex 1920478b49..075087ee0e 100644--- a/weed/operation/upload_content.go+++ b/weed/operation/upload_content.go@@ -3,6 +3,8 @@ package operationimport ("bytes""context"+ "crypto/md5"+ "encoding/base64""encoding/json""fmt""io"@@ -39,6 +41,7 @@ type UploadOption struct {Jwt security.EncodedJwtRetryForever boolMd5 string+ WantMd5 bool // compute Content-MD5 from the data when Md5 is unset and the upload is not cipheredBytesBuffer *bytes.BufferSourceUrl string // optional: for logging when reading from a remote sourceMaxAttempts int // <=0 uses the default@@ -196,6 +199,14 @@ func (uploader *Uploader) UploadWithRetry(filerClient filer_pb.FilerClient, assiassignRequest.ExpectedDataSize = uint64(len(data))}+ // Hash the buffer we already hold so the server echoes Content-MD5 back as+ // the chunk ETag (std-base64 of the raw digest, the form ParseUpload+ // verifies). Never under cipher: the server sees only ciphertext.+ if uploadOption.WantMd5 && uploadOption.Md5 == "" && !uploadOption.Cipher {+ digest := md5.Sum(data)+ uploadOption.Md5 = base64.StdEncoding.EncodeToString(digest[:])+ }+fileId, uploadResult, err = uploader.uploadWithRetryData(func() (fileId string, host string, auth security.EncodedJwt, err error) {// grpc assign volumeif grpcAssignErr := filerClient.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {