mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-21 22:08:52 +08:00
Add filer option to redirect instead of proxying to volume server on file GET requests.
This commit is contained in:
@@ -9,17 +9,23 @@ import (
|
||||
)
|
||||
|
||||
type FilerServer struct {
|
||||
port string
|
||||
master string
|
||||
collection string
|
||||
filer filer.Filer
|
||||
port string
|
||||
master string
|
||||
collection string
|
||||
defaultReplication string
|
||||
redirectOnRead bool
|
||||
filer filer.Filer
|
||||
}
|
||||
|
||||
func NewFilerServer(r *http.ServeMux, port int, master string, dir string, collection string) (fs *FilerServer, err error) {
|
||||
func NewFilerServer(r *http.ServeMux, port int, master string, dir string, collection string,
|
||||
replication string, redirectOnRead bool,
|
||||
) (fs *FilerServer, err error) {
|
||||
fs = &FilerServer{
|
||||
master: master,
|
||||
collection: collection,
|
||||
port: ":" + strconv.Itoa(port),
|
||||
master: master,
|
||||
collection: collection,
|
||||
defaultReplication: replication,
|
||||
redirectOnRead: redirectOnRead,
|
||||
port: ":" + strconv.Itoa(port),
|
||||
}
|
||||
|
||||
if fs.filer, err = filer.NewFilerEmbedded(master, dir); err != nil {
|
||||
|
@@ -81,7 +81,11 @@ func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request,
|
||||
return
|
||||
}
|
||||
urlLocation := lookup.Locations[rand.Intn(len(lookup.Locations))].PublicUrl
|
||||
u, _ := url.Parse("http://" + urlLocation + "/" + fileId)
|
||||
urlString := "http://" + urlLocation + "/" + fileId
|
||||
if fs.redirectOnRead {
|
||||
|
||||
}
|
||||
u, _ := url.Parse(urlString)
|
||||
request := &http.Request{
|
||||
Method: r.Method,
|
||||
URL: u,
|
||||
@@ -110,7 +114,11 @@ func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request,
|
||||
|
||||
func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
query := r.URL.Query()
|
||||
assignResult, ae := operation.Assign(fs.master, 1, query.Get("replication"), fs.collection, query.Get("ttl"))
|
||||
replication := query.Get("replication")
|
||||
if replication == "" {
|
||||
replication = fs.defaultReplication
|
||||
}
|
||||
assignResult, ae := operation.Assign(fs.master, 1, replication, fs.collection, query.Get("ttl"))
|
||||
if ae != nil {
|
||||
glog.V(0).Infoln("failing to assign a file id", ae.Error())
|
||||
writeJsonError(w, r, ae)
|
||||
|
Reference in New Issue
Block a user