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
add ETag to upload results and chunks
Chris Lu7d6b2a4740c3
diff --git a/weed/command/filer_copy.go b/weed/command/filer_copy.goindex 218abf645a..d7b4746282 100644--- a/weed/command/filer_copy.go+++ b/weed/command/filer_copy.go@@ -201,6 +201,7 @@ func uploadFileAsOne(filerAddress, filerGrpcAddress string, urlFolder string, fOffset: 0,Size: uint64(uploadResult.Size),Mtime: time.Now().UnixNano(),+ ETag: uploadResult.ETag,})fmt.Printf("copied %s => http://%s%s%s\n", fileName, filerAddress, urlFolder, fileName)@@ -278,6 +279,7 @@ func uploadFileInChunks(filerAddress, filerGrpcAddress string, urlFolder string,Offset: i * chunkSize,Size: uint64(uploadResult.Size),Mtime: time.Now().UnixNano(),+ ETag: uploadResult.ETag,})fmt.Printf("uploaded %s-%d to %s [%d,%d)\n", fileName, i+1, targetUrl, i*chunkSize, i*chunkSize+int64(uploadResult.Size))}diff --git a/weed/filesys/dirty_page.go b/weed/filesys/dirty_page.goindex eb810d3832..8bdb12d4d7 100644--- a/weed/filesys/dirty_page.go+++ b/weed/filesys/dirty_page.go@@ -187,6 +187,7 @@ func (pages *ContinuousDirtyPages) saveToStorage(ctx context.Context, buf []byteOffset: offset,Size: uint64(len(buf)),Mtime: time.Now().UnixNano(),+ ETag: uploadResult.ETag,}, nil}diff --git a/weed/operation/upload_content.go b/weed/operation/upload_content.goindex 30c7f1ea36..1fd0ed2b9c 100644--- a/weed/operation/upload_content.go+++ b/weed/operation/upload_content.go@@ -22,6 +22,7 @@ type UploadResult struct {Name string `json:"name,omitempty"`Size uint32 `json:"size,omitempty"`Error string `json:"error,omitempty"`+ ETag string `json:"error,omitempty"`}var (@@ -90,6 +91,7 @@ func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) errorreturn nil, post_err}defer resp.Body.Close()+ etag := getEtag(resp)resp_body, ra_err := ioutil.ReadAll(resp.Body)if ra_err != nil {return nil, ra_err@@ -103,5 +105,14 @@ func upload_content(uploadUrl string, fillBufferFunction func(w io.Writer) errorif ret.Error != "" {return nil, errors.New(ret.Error)}+ ret.ETag = etagreturn &ret, nil}++func getEtag(r *http.Response) (etag string) {+ etag = r.Header.Get("ETag")+ if strings.HasPrefix(etag, "\"") && strings.HasSuffix(etag, "\"") {+ etag = etag[1 : len(etag)-1]+ }+ return+}diff --git a/weed/server/common.go b/weed/server/common.goindex 2e30530922..12adbf1b49 100644--- a/weed/server/common.go+++ b/weed/server/common.go@@ -123,6 +123,7 @@ func submitForClientHandler(w http.ResponseWriter, r *http.Request, masterUrl stm["fid"] = assignResult.Fidm["fileUrl"] = assignResult.PublicUrl + "/" + assignResult.Fidm["size"] = uploadResult.Size+ m["eTag"] = uploadResult.ETagwriteJsonQuiet(w, r, http.StatusCreated, m)return}