mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-15 20:06:19 +08:00
for moved volumes, redirect with code 501
This commit is contained in:
@@ -53,7 +53,7 @@ func dirLookupHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
for _, machine := range machines {
|
for _, machine := range machines {
|
||||||
ret = append(ret, map[string]string{"url": machine.Url, "publicUrl": machine.PublicUrl})
|
ret = append(ret, map[string]string{"url": machine.Url, "publicUrl": machine.PublicUrl})
|
||||||
}
|
}
|
||||||
writeJson(w, r, ret)
|
writeJson(w, r, map[string]interface{}{"locations":ret})
|
||||||
} else {
|
} else {
|
||||||
log.Println("Invalid volume id", volumeId)
|
log.Println("Invalid volume id", volumeId)
|
||||||
writeJson(w, r, map[string]string{"error": "volume id " + volumeId.String() + " not found. " + e.Error()})
|
writeJson(w, r, map[string]string{"error": "volume id " + volumeId.String() + " not found. " + e.Error()})
|
||||||
|
@@ -7,6 +7,7 @@ import (
|
|||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"pkg/operation"
|
||||||
"pkg/storage"
|
"pkg/storage"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -86,6 +87,18 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
if *IsDebug {
|
if *IsDebug {
|
||||||
log.Println("volume", volumeId, "reading", n)
|
log.Println("volume", volumeId, "reading", n)
|
||||||
}
|
}
|
||||||
|
if !store.HasVolume(volumeId) {
|
||||||
|
lookupResult, err := operation.Lookup(*server, volumeId)
|
||||||
|
if *IsDebug {
|
||||||
|
log.Println("volume", volumeId, "found on", lookupResult, "error", err)
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
http.Redirect(w, r, "http://"+lookupResult.Locations[0].PublicUrl+r.URL.Path, http.StatusMovedPermanently)
|
||||||
|
} else {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
cookie := n.Cookie
|
cookie := n.Cookie
|
||||||
count, e := store.Read(volumeId, n)
|
count, e := store.Read(volumeId, n)
|
||||||
if *IsDebug {
|
if *IsDebug {
|
||||||
|
34
weed-fs/src/pkg/operation/lookup.go
Normal file
34
weed-fs/src/pkg/operation/lookup.go
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package operation
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/url"
|
||||||
|
"pkg/storage"
|
||||||
|
"pkg/util"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Location struct {
|
||||||
|
Url string "url"
|
||||||
|
PublicUrl string "publicUrl"
|
||||||
|
}
|
||||||
|
type LookupResult struct {
|
||||||
|
Locations []Location "locations"
|
||||||
|
Error string "error"
|
||||||
|
}
|
||||||
|
|
||||||
|
func Lookup(server string, vid storage.VolumeId) (*LookupResult, error) {
|
||||||
|
values := make(url.Values)
|
||||||
|
values.Add("volumeId", vid.String())
|
||||||
|
jsonBlob, err := util.Post("http://"+server+"/dir/lookup", values)
|
||||||
|
fmt.Println("Lookup Result:", string(jsonBlob))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
var ret LookupResult
|
||||||
|
err = json.Unmarshal(jsonBlob, &ret)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &ret, nil
|
||||||
|
}
|
@@ -136,6 +136,11 @@ func (s *Store) Read(i VolumeId, n *Needle) (int, error) {
|
|||||||
return 0, errors.New("Not Found")
|
return 0, errors.New("Not Found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Store) HasVolume(i VolumeId) bool {
|
||||||
|
_, ok := s.volumes[i]
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
type VolumeLocations struct {
|
type VolumeLocations struct {
|
||||||
Vid VolumeId
|
Vid VolumeId
|
||||||
Locations []string
|
Locations []string
|
||||||
|
Reference in New Issue
Block a user