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
fix: return immediately on first error in DistributedOperation (#9740)
Rushikesh Deshpandeea33b851e62b
diff --git a/weed/topology/store_replicate.go b/weed/topology/store_replicate.goindex d6c774d318..6547c0b5cd 100644--- a/weed/topology/store_replicate.go+++ b/weed/topology/store_replicate.go@@ -191,18 +191,28 @@ type RemoteResult struct {func DistributedOperation(locations []operation.Location, op func(location operation.Location) error) error {length := len(locations)- results := make(chan RemoteResult)+ if length == 0 {+ return nil+ }++ // buffered so a straggler (e.g. a replica stalled on a TCP dial timeout) can+ // still deliver its result and exit after we have already returned.+ resultCh := make(chan RemoteResult, length)for _, location := range locations {- go func(location operation.Location, results chan RemoteResult) {- results <- RemoteResult{location.Url, op(location)}- }(location, results)+ go func(location operation.Location) {+ resultCh <- RemoteResult{location.Url, op(location)}+ }(location)}+ret := DistributedOperationResult(make(map[string]error))for i := 0; i < length; i++ {- result := <-results+ result := <-resultChret[result.Host] = result.Error+ if result.Error != nil {+ // fail fast on the first error instead of waiting for slow replicas+ return ret.Error()+ }}-return ret.Error()}