mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
Using Url instead of PublicUrl for volume server
Originally there are only url(ip + port), and publicUrl. Because ip was used to listen for http service, it has less flexibility and volume server has to be accessed via publicUrl. Recently we added ip.bind, for binding http service. With this change, url can be used to connect to volume servers. And publicUrl becomes a free style piece of url information, it does not even need to be unique.
This commit is contained in:
parent
29a325626f
commit
cc724305b6
|
@ -66,11 +66,11 @@ func DeleteFiles(master string, fileIds []string) (*DeleteFilesResult, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, location := range result.Locations {
|
for _, location := range result.Locations {
|
||||||
if _, ok := server_to_fileIds[location.PublicUrl]; !ok {
|
if _, ok := server_to_fileIds[location.Url]; !ok {
|
||||||
server_to_fileIds[location.PublicUrl] = make([]string, 0)
|
server_to_fileIds[location.Url] = make([]string, 0)
|
||||||
}
|
}
|
||||||
server_to_fileIds[location.PublicUrl] = append(
|
server_to_fileIds[location.Url] = append(
|
||||||
server_to_fileIds[location.PublicUrl], vid_to_fileIds[vid]...)
|
server_to_fileIds[location.Url], vid_to_fileIds[vid]...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ func LookupFileId(server string, fileId string) (fullUrl string, err error) {
|
||||||
if len(lookup.Locations) == 0 {
|
if len(lookup.Locations) == 0 {
|
||||||
return "", errors.New("File Not Found")
|
return "", errors.New("File Not Found")
|
||||||
}
|
}
|
||||||
return "http://" + lookup.Locations[rand.Intn(len(lookup.Locations))].PublicUrl + "/" + fileId, nil
|
return "http://" + lookup.Locations[rand.Intn(len(lookup.Locations))].Url + "/" + fileId, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LookupVolumeIds find volume locations by cache and actual lookup
|
// LookupVolumeIds find volume locations by cache and actual lookup
|
||||||
|
|
|
@ -137,7 +137,7 @@ func upload_one_chunk(filename string, reader io.Reader, master, replication str
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, err
|
return "", 0, err
|
||||||
}
|
}
|
||||||
fileUrl, fid := "http://"+ret.PublicUrl+"/"+ret.Fid, ret.Fid
|
fileUrl, fid := "http://"+ret.Url+"/"+ret.Fid, ret.Fid
|
||||||
glog.V(4).Info("Uploading part ", filename, " to ", fileUrl, "...")
|
glog.V(4).Info("Uploading part ", filename, " to ", fileUrl, "...")
|
||||||
uploadResult, uploadError := Upload(fileUrl, filename, reader, false, "application/octet-stream")
|
uploadResult, uploadError := Upload(fileUrl, filename, reader, false, "application/octet-stream")
|
||||||
if uploadError != nil {
|
if uploadError != nil {
|
||||||
|
|
|
@ -203,7 +203,7 @@ func writeFiles(idChan chan int, fileIdLineChan chan string, s *stat) {
|
||||||
fileSize := int64(*b.fileSize + rand.Intn(64))
|
fileSize := int64(*b.fileSize + rand.Intn(64))
|
||||||
fp := &operation.FilePart{Reader: &FakeReader{id: uint64(id), size: fileSize}, FileSize: fileSize}
|
fp := &operation.FilePart{Reader: &FakeReader{id: uint64(id), size: fileSize}, FileSize: fileSize}
|
||||||
if assignResult, err := operation.Assign(*b.server, 1, "", *b.collection, ""); err == nil {
|
if assignResult, err := operation.Assign(*b.server, 1, "", *b.collection, ""); err == nil {
|
||||||
fp.Server, fp.Fid, fp.Collection = assignResult.PublicUrl, assignResult.Fid, *b.collection
|
fp.Server, fp.Fid, fp.Collection = assignResult.Url, assignResult.Fid, *b.collection
|
||||||
if _, err := fp.Upload(0, *b.server); err == nil {
|
if _, err := fp.Upload(0, *b.server); err == nil {
|
||||||
if rand.Intn(100) < *b.deletePercentage {
|
if rand.Intn(100) < *b.deletePercentage {
|
||||||
s.total++
|
s.total++
|
||||||
|
@ -251,7 +251,7 @@ func readFiles(fileIdLineChan chan string, s *stat) {
|
||||||
if _, now_ok := b.vid2server[vid]; !now_ok {
|
if _, now_ok := b.vid2server[vid]; !now_ok {
|
||||||
if ret, err := operation.Lookup(*b.server, vid); err == nil {
|
if ret, err := operation.Lookup(*b.server, vid); err == nil {
|
||||||
if len(ret.Locations) > 0 {
|
if len(ret.Locations) > 0 {
|
||||||
server = ret.Locations[0].PublicUrl
|
server = ret.Locations[0].Url
|
||||||
b.vid2server[vid] = server
|
b.vid2server[vid] = server
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,7 +96,7 @@ func submitForClientHandler(w http.ResponseWriter, r *http.Request, masterUrl st
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
url := "http://" + assignResult.PublicUrl + "/" + assignResult.Fid
|
url := "http://" + assignResult.Url + "/" + assignResult.Fid
|
||||||
if lastModified != 0 {
|
if lastModified != 0 {
|
||||||
url = url + "?ts=" + strconv.FormatUint(lastModified, 10)
|
url = url + "?ts=" + strconv.FormatUint(lastModified, 10)
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request,
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
urlLocation := lookup.Locations[rand.Intn(len(lookup.Locations))].PublicUrl
|
urlLocation := lookup.Locations[rand.Intn(len(lookup.Locations))].Url
|
||||||
urlString := "http://" + urlLocation + "/" + fileId
|
urlString := "http://" + urlLocation + "/" + fileId
|
||||||
if fs.redirectOnRead {
|
if fs.redirectOnRead {
|
||||||
http.Redirect(w, r, urlString, http.StatusFound)
|
http.Redirect(w, r, urlString, http.StatusFound)
|
||||||
|
@ -126,7 +126,7 @@ func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
u, _ := url.Parse("http://" + assignResult.PublicUrl + "/" + assignResult.Fid)
|
u, _ := url.Parse("http://" + assignResult.Url + "/" + assignResult.Fid)
|
||||||
glog.V(4).Infoln("post to", u)
|
glog.V(4).Infoln("post to", u)
|
||||||
request := &http.Request{
|
request := &http.Request{
|
||||||
Method: r.Method,
|
Method: r.Method,
|
||||||
|
|
|
@ -119,7 +119,7 @@ func (ms *MasterServer) redirectHandler(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
machines := ms.Topo.Lookup("", volumeId)
|
machines := ms.Topo.Lookup("", volumeId)
|
||||||
if machines != nil && len(machines) > 0 {
|
if machines != nil && len(machines) > 0 {
|
||||||
http.Redirect(w, r, "http://"+machines[0].PublicUrl+r.URL.Path, http.StatusMovedPermanently)
|
http.Redirect(w, r, "http://"+machines[0].Url()+r.URL.Path, http.StatusMovedPermanently)
|
||||||
} else {
|
} else {
|
||||||
writeJsonError(w, r, http.StatusNotFound, fmt.Errorf("volume id %d not found.", volumeId))
|
writeJsonError(w, r, http.StatusNotFound, fmt.Errorf("volume id %d not found.", volumeId))
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
|
||||||
lookupResult, err := operation.Lookup(vs.masterNode, volumeId.String())
|
lookupResult, err := operation.Lookup(vs.masterNode, volumeId.String())
|
||||||
glog.V(2).Infoln("volume", volumeId, "found on", lookupResult, "error", err)
|
glog.V(2).Infoln("volume", volumeId, "found on", lookupResult, "error", err)
|
||||||
if err == nil && len(lookupResult.Locations) > 0 {
|
if err == nil && len(lookupResult.Locations) > 0 {
|
||||||
http.Redirect(w, r, "http://"+lookupResult.Locations[0].PublicUrl+r.URL.Path, http.StatusMovedPermanently)
|
http.Redirect(w, r, "http://"+lookupResult.Locations[0].Url+r.URL.Path, http.StatusMovedPermanently)
|
||||||
} else {
|
} else {
|
||||||
glog.V(2).Infoln("lookup error:", err, r.URL.Path)
|
glog.V(2).Infoln("lookup error:", err, r.URL.Path)
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
|
Loading…
Reference in a new issue