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
randomly pick one replica to write
chrislubebc385607fa
diff --git a/weed/operation/submit.go b/weed/operation/submit.goindex 516478dbeb..66d5542af6 100644--- a/weed/operation/submit.go+++ b/weed/operation/submit.go@@ -4,6 +4,7 @@ import ("context""github.com/seaweedfs/seaweedfs/weed/pb""io"+ "math/rand""mime""net/url""os"@@ -179,11 +180,8 @@ func (fi FilePart) Upload(maxMB int, masterFn GetMasterFn, usePublicUrl bool, jwid += "_" + strconv.FormatInt(i, 10)}}- fileUrl := "http://" + ret.Url + "/" + id- if usePublicUrl {- fileUrl = "http://" + ret.PublicUrl + "/" + id- }- count, e := upload_one_chunk(+ fileUrl := genFileUrl(ret, id, usePublicUrl)+ count, e := uploadOneChunk(baseName+"-"+strconv.FormatInt(i+1, 10),io.LimitReader(fi.Reader, chunkSize),masterFn, fileUrl,@@ -202,7 +200,7 @@ func (fi FilePart) Upload(maxMB int, masterFn GetMasterFn, usePublicUrl bool, jw)retSize += count}- err = upload_chunked_file_manifest(fileUrl, &cm, jwt)+ err = uploadChunkedFileManifest(fileUrl, &cm, jwt)if err != nil {// delete all uploaded chunkscm.DeleteChunks(masterFn, usePublicUrl, grpcDialOption)@@ -217,7 +215,7 @@ func (fi FilePart) Upload(maxMB int, masterFn GetMasterFn, usePublicUrl bool, jwPairMap: nil,Jwt: jwt,}-+uploader, e := NewUploader()if e != nil {return 0, e@@ -232,7 +230,23 @@ func (fi FilePart) Upload(maxMB int, masterFn GetMasterFn, usePublicUrl bool, jwreturn}-func upload_one_chunk(filename string, reader io.Reader, masterFn GetMasterFn,+func genFileUrl(ret *AssignResult, id string, usePublicUrl bool) string {+ fileUrl := "http://" + ret.Url + "/" + id+ if usePublicUrl {+ fileUrl = "http://" + ret.PublicUrl + "/" + id+ }+ for _, replica := range ret.Replicas {+ if rand.Intn(len(ret.Replicas)+1) == 0 {+ fileUrl = "http://" + replica.Url + "/" + id+ if usePublicUrl {+ fileUrl = "http://" + replica.PublicUrl + "/" + id+ }+ }+ }+ return fileUrl+}++func uploadOneChunk(filename string, reader io.Reader, masterFn GetMasterFn,fileUrl string, jwt security.EncodedJwt,) (size uint32, e error) {glog.V(4).Info("Uploading part ", filename, " to ", fileUrl, "...")@@ -258,7 +272,7 @@ func upload_one_chunk(filename string, reader io.Reader, masterFn GetMasterFn,return uploadResult.Size, nil}-func upload_chunked_file_manifest(fileUrl string, manifest *ChunkManifest, jwt security.EncodedJwt) error {+func uploadChunkedFileManifest(fileUrl string, manifest *ChunkManifest, jwt security.EncodedJwt) error {buf, e := manifest.Marshal()if e != nil {return e@@ -277,7 +291,7 @@ func upload_chunked_file_manifest(fileUrl string, manifest *ChunkManifest, jwt sPairMap: nil,Jwt: jwt,}-+uploader, e := NewUploader()if e != nil {return e