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.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
more robust filer
Chris Lu51fafdb5255b
diff --git a/go/operation/upload_content.go b/go/operation/upload_content.goindex 10e9db3153..646df6886c 100644--- a/go/operation/upload_content.go+++ b/go/operation/upload_content.go@@ -17,6 +17,7 @@ import ()type UploadResult struct {+ Name stringSize intError string}diff --git a/go/weed/weed_server/filer_server.go b/go/weed/weed_server/filer_server.goindex 80ffb0861a..ffcb64cfc0 100644--- a/go/weed/weed_server/filer_server.go+++ b/go/weed/weed_server/filer_server.go@@ -57,7 +57,11 @@ func (fs *FilerServer) ListDirectories(fullpath string) (dirs []string, err erroif e != nil {return nil, e}- return strings.Split(string(data), ":"), nil+ val := string(data)+ if val == "" {+ return nil, nil+ }+ return strings.Split(val, ":"), nil}func (fs *FilerServer) ListFiles(fullpath string, start, limit int) (files []string) {@@ -82,6 +86,9 @@ func (fs *FilerServer) ListFiles(fullpath string, start, limit int) (files []strbreak}fileName := key[len(fullpath):]+ if fileName == "" {+ continue //skip the directory entry+ }if strings.Contains(fileName, "/") {break}@@ -129,15 +136,17 @@ func (fs *FilerServer) findEntry(fullpath string) (value string, err error) {func (fs *FilerServer) ensureFileFolder(fullFileName string) (err error) {parts := strings.Split(fullFileName, "/")path := "/"- for i := 1; i < len(parts)-1; i++ {+ for i := 1; i < len(parts); i++ {sub := parts[i]- if sub == "" {- continue+ if i == len(parts)-1 {+ sub = ""}if err = fs.ensureFolderHasEntry(path, sub); err != nil {return}- path = path + sub + "/"+ if sub != "" {+ path = path + sub + "/"+ }}return nil}diff --git a/go/weed/weed_server/filer_server_handlers.go b/go/weed/weed_server/filer_server_handlers.goindex 5bdbdc96de..a9ead0e336 100644--- a/go/weed/weed_server/filer_server_handlers.go+++ b/go/weed/weed_server/filer_server_handlers.go@@ -12,6 +12,7 @@ import ("math/rand""net/http""net/url"+ "strconv""strings")@@ -29,9 +30,35 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) {fs.PostHandler(w, r)}}+func (fs *FilerServer) listDirectoryHandler(w http.ResponseWriter, r *http.Request) {+ if !strings.HasSuffix(r.URL.Path, "/") {+ return+ }+ dirlist, err := fs.ListDirectories(r.URL.Path)+ if err == leveldb.ErrNotFound {+ glog.V(3).Infoln("Directory Not Found in db", r.URL.Path)+ w.WriteHeader(http.StatusNotFound)+ return+ }+ m := make(map[string]interface{})+ m["Directory"] = r.URL.Path+ m["Subdirectories"] = dirlist+ start, _ := strconv.Atoi(r.FormValue("start"))+ limit, limit_err := strconv.Atoi(r.FormValue("limit"))+ if limit_err != nil {+ limit = 100+ }+ m["Files"] = fs.ListFiles(r.URL.Path, start, limit)+ writeJsonQuiet(w, r, m)+}func (fs *FilerServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) {+ if strings.HasSuffix(r.URL.Path, "/") {+ fs.listDirectoryHandler(w, r)+ return+ }fileId, err := fs.FindFile(r.URL.Path)if err == leveldb.ErrNotFound {+ glog.V(3).Infoln("Not found in db", r.URL.Path)w.WriteHeader(http.StatusNotFound)return}@@ -128,13 +155,25 @@ func (fs *FilerServer) PostHandler(w http.ResponseWriter, r *http.Request) {writeJsonError(w, r, errors.New(ret.Error))return}- if db_err := fs.CreateFile(r.URL.Path, assignResult.Fid); db_err != nil {+ path := r.URL.Path+ if strings.HasSuffix(path, "/") {+ if ret.Name != "" {+ path += ret.Name+ } else {+ operation.DeleteFile(fs.master, assignResult.Fid) //clean up+ glog.V(0).Infoln("Can not to write to folder", path, "without a file name!")+ w.WriteHeader(http.StatusInternalServerError)+ writeJsonError(w, r, errors.New("Can not to write to folder "+path+" without a file name"))+ return+ }+ }+ if db_err := fs.CreateFile(path, assignResult.Fid); db_err != nil {operation.DeleteFile(fs.master, assignResult.Fid) //clean upglog.V(0).Infoln("failing to write to filer server", db_err.Error())w.WriteHeader(http.StatusInternalServerError)writeJsonError(w, r, db_err)+ return}- w.WriteHeader(http.StatusCreated)}func (fs *FilerServer) DeleteHandler(w http.ResponseWriter, r *http.Request) {diff --git a/go/weed/weed_server/volume_server_handlers.go b/go/weed/weed_server/volume_server_handlers.goindex aaa4410048..0649ce7f4b 100644--- a/go/weed/weed_server/volume_server_handlers.go+++ b/go/weed/weed_server/volume_server_handlers.go@@ -221,6 +221,9 @@ func (vs *VolumeServer) PostHandler(w http.ResponseWriter, r *http.Request) {w.WriteHeader(http.StatusInternalServerError)m["error"] = errorStatus}+ if needle.HasName() {+ m["name"] = string(needle.Name)+ }m["size"] = retwriteJsonQuiet(w, r, m)}