mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-08-24 08:39:30 +08:00
master can redirect GET/DELETE/POST requests to volume servers. So
clients does not always need to remember the volume server locations. This is good for low~medium sized web site traffic.
This commit is contained in:
parent
e9eb8949ba
commit
8fb8ebdf14
@ -54,7 +54,7 @@ func dirLookupHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
machines := topo.Lookup(volumeId)
|
machines := topo.Lookup(volumeId)
|
||||||
if machines != nil {
|
if machines != nil {
|
||||||
ret := []map[string]string{}
|
ret := []map[string]string{}
|
||||||
for _, dn := range *machines {
|
for _, dn := range machines {
|
||||||
ret = append(ret, map[string]string{"url": dn.Url(), "publicUrl": dn.PublicUrl})
|
ret = append(ret, map[string]string{"url": dn.Url(), "publicUrl": dn.PublicUrl})
|
||||||
}
|
}
|
||||||
writeJson(w, r, map[string]interface{}{"locations": ret})
|
writeJson(w, r, map[string]interface{}{"locations": ret})
|
||||||
@ -102,7 +102,7 @@ func dirAssignHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dirJoinHandler(w http.ResponseWriter, r *http.Request) {
|
func dirJoinHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
init := r.FormValue("init")=="true"
|
init := r.FormValue("init") == "true"
|
||||||
ip := r.FormValue("ip")
|
ip := r.FormValue("ip")
|
||||||
if ip == "" {
|
if ip == "" {
|
||||||
ip = r.RemoteAddr[0:strings.Index(r.RemoteAddr, ":")]
|
ip = r.RemoteAddr[0:strings.Index(r.RemoteAddr, ":")]
|
||||||
@ -116,7 +116,7 @@ func dirJoinHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
debug(s, "volumes", r.FormValue("volumes"))
|
debug(s, "volumes", r.FormValue("volumes"))
|
||||||
topo.RegisterVolumes(init, *volumes, ip, port, publicUrl, maxVolumeCount)
|
topo.RegisterVolumes(init, *volumes, ip, port, publicUrl, maxVolumeCount)
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
m["VolumeSizeLimit"] = uint64(*volumeSizeLimitMB)*1024*1024
|
m["VolumeSizeLimit"] = uint64(*volumeSizeLimitMB) * 1024 * 1024
|
||||||
writeJson(w, r, m)
|
writeJson(w, r, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,6 +178,22 @@ func volumeStatusHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
writeJson(w, r, m)
|
writeJson(w, r, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func redirectHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vid, _, _ := parseURLPath(r.URL.Path)
|
||||||
|
volumeId, err := storage.NewVolumeId(vid)
|
||||||
|
if err != nil {
|
||||||
|
debug("parsing error:", err, r.URL.Path)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
machines := topo.Lookup(volumeId)
|
||||||
|
if machines != nil && len(machines) > 0 {
|
||||||
|
http.Redirect(w, r, "http://"+machines[0].PublicUrl+r.URL.Path, http.StatusMovedPermanently)
|
||||||
|
} else {
|
||||||
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
writeJson(w, r, map[string]string{"error": "volume id " + volumeId.String() + " not found. "})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func runMaster(cmd *Command, args []string) bool {
|
func runMaster(cmd *Command, args []string) bool {
|
||||||
if *mMaxCpu < 1 {
|
if *mMaxCpu < 1 {
|
||||||
*mMaxCpu = runtime.NumCPU()
|
*mMaxCpu = runtime.NumCPU()
|
||||||
@ -192,6 +208,7 @@ func runMaster(cmd *Command, args []string) bool {
|
|||||||
http.HandleFunc("/dir/status", dirStatusHandler)
|
http.HandleFunc("/dir/status", dirStatusHandler)
|
||||||
http.HandleFunc("/vol/grow", volumeGrowHandler)
|
http.HandleFunc("/vol/grow", volumeGrowHandler)
|
||||||
http.HandleFunc("/vol/status", volumeStatusHandler)
|
http.HandleFunc("/vol/status", volumeStatusHandler)
|
||||||
|
http.HandleFunc("/", redirectHandler)
|
||||||
|
|
||||||
topo.StartRefreshWritableVolumes(*garbageThreshold)
|
topo.StartRefreshWritableVolumes(*garbageThreshold)
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ func (t *Topology) loadConfiguration(configurationFile string) error {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Topology) Lookup(vid storage.VolumeId) *[]*DataNode {
|
func (t *Topology) Lookup(vid storage.VolumeId) []*DataNode {
|
||||||
for _, vl := range t.replicaType2VolumeLayout {
|
for _, vl := range t.replicaType2VolumeLayout {
|
||||||
if vl != nil {
|
if vl != nil {
|
||||||
if list := vl.Lookup(vid); list != nil {
|
if list := vl.Lookup(vid); list != nil {
|
||||||
|
@ -42,8 +42,8 @@ func (vl *VolumeLayout) isWritable(v *storage.VolumeInfo) bool{
|
|||||||
return uint64(v.Size) < vl.volumeSizeLimit && v.Version == storage.CurrentVersion
|
return uint64(v.Size) < vl.volumeSizeLimit && v.Version == storage.CurrentVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vl *VolumeLayout) Lookup(vid storage.VolumeId) *[]*DataNode {
|
func (vl *VolumeLayout) Lookup(vid storage.VolumeId) []*DataNode {
|
||||||
return &vl.vid2location[vid].list
|
return vl.vid2location[vid].list
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vl *VolumeLayout) PickForWrite(count int) (*storage.VolumeId, int, *VolumeLocationList, error) {
|
func (vl *VolumeLayout) PickForWrite(count int) (*storage.VolumeId, int, *VolumeLocationList, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user