Skip to content

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.

fix: pass proxied query param (#7477)

Konstantin Lebedev4477edbcc4cd
diff --git a/weed/server/volume_server_handlers.go b/weed/server/volume_server_handlers.go
index a427320626..cf22adf34f 100644
--- a/weed/server/volume_server_handlers.go
+++ b/weed/server/volume_server_handlers.go
@@ -75,6 +75,10 @@ func (vs *VolumeServer) checkDownloadLimit(w http.ResponseWriter, r *http.Reques
// - true: Request was handled (either proxied successfully or failed with error response)
// - false: No proxy available (volume has no replicas or request already proxied)
func (vs *VolumeServer) tryProxyToReplica(w http.ResponseWriter, r *http.Request) bool {
+ if r.URL.Query().Get(reqIsProxied) == "true" {
+ return false // already proxied
+ }
+
vid, _, _, _, _ := parseURLPath(r.URL.Path)
volumeId, err := needle.NewVolumeId(vid)
if err != nil {
@@ -84,7 +88,7 @@ func (vs *VolumeServer) tryProxyToReplica(w http.ResponseWriter, r *http.Request
}
volume := vs.store.GetVolume(volumeId)
- if volume != nil && volume.ReplicaPlacement != nil && volume.ReplicaPlacement.HasReplication() && r.URL.Query().Get(reqIsProxied) != "true" {
+ if volume != nil && volume.ReplicaPlacement != nil && volume.ReplicaPlacement.HasReplication() {
vs.proxyReqToTargetServer(w, r)
return true // handled by proxy
}
diff --git a/weed/server/volume_server_handlers_read.go b/weed/server/volume_server_handlers_read.go
index a12b1aeb2f..a29ebd1835 100644
--- a/weed/server/volume_server_handlers_read.go
+++ b/weed/server/volume_server_handlers_read.go
@@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"io"
+ "math/rand/v2"
"mime"
"net/http"
"net/url"
@@ -59,6 +60,11 @@ func (vs *VolumeServer) proxyReqToTargetServer(w http.ResponseWriter, r *http.Re
NotFound(w)
return
}
+ if len(lookupResult.Locations) >= 2 {
+ rand.Shuffle(len(lookupResult.Locations), func(i, j int) {
+ lookupResult.Locations[i], lookupResult.Locations[j] = lookupResult.Locations[j], lookupResult.Locations[i]
+ })
+ }
var tragetUrl *url.URL
location := fmt.Sprintf("%s:%d", vs.store.Ip, vs.store.Port)
for _, loc := range lookupResult.Locations {
@@ -79,7 +85,9 @@ func (vs *VolumeServer) proxyReqToTargetServer(w http.ResponseWriter, r *http.Re
// proxy client request to target server
r.URL.Host = tragetUrl.Host
r.URL.Scheme = tragetUrl.Scheme
- r.URL.Query().Add(reqIsProxied, "true")
+ query := r.URL.Query()
+ query.Set(reqIsProxied, "true")
+ r.URL.RawQuery = query.Encode()
request, err := http.NewRequest(http.MethodGet, r.URL.String(), nil)
if err != nil {
glog.V(0).Infof("failed to instance http request of url %s: %v", r.URL.String(), err)