Skip to content

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.

set filer2.ErrNotFound for not found entry

Chris Lu80d80daf6437
diff --git a/weed/filer2/abstract_sql/abstract_sql_store.go b/weed/filer2/abstract_sql/abstract_sql_store.go
index 82ef571b68..d6bb717ca7 100644
--- a/weed/filer2/abstract_sql/abstract_sql_store.go
+++ b/weed/filer2/abstract_sql/abstract_sql_store.go
@@ -64,7 +64,7 @@ func (store *AbstractSqlStore) FindEntry(fullpath filer2.FullPath) (*filer2.Entr
row := store.DB.QueryRow(store.SqlFind, hashToLong(dir), name, dir)
var data []byte
if err := row.Scan(&data); err != nil {
- return nil, fmt.Errorf("read entry %s: %v", fullpath, err)
+ return nil, filer2.ErrNotFound
}
entry := &filer2.Entry{
diff --git a/weed/filer2/cassandra/cassandra_store.go b/weed/filer2/cassandra/cassandra_store.go
index d731cd99cf..7552cb524d 100644
--- a/weed/filer2/cassandra/cassandra_store.go
+++ b/weed/filer2/cassandra/cassandra_store.go
@@ -68,7 +68,7 @@ func (store *CassandraStore) FindEntry(fullpath filer2.FullPath) (entry *filer2.
"SELECT meta FROM filemeta WHERE directory=? AND name=?",
dir, name).Consistency(gocql.One).Scan(&data); err != nil {
if err != gocql.ErrNotFound {
- return nil, fmt.Errorf("read entry %s: %v", fullpath, err)
+ return nil, filer2.ErrNotFound
}
}
diff --git a/weed/filer2/filerstore.go b/weed/filer2/filerstore.go
index b169c6f80c..68fc06a5d9 100644
--- a/weed/filer2/filerstore.go
+++ b/weed/filer2/filerstore.go
@@ -11,6 +11,7 @@ type FilerStore interface {
Initialize(configuration Configuration) error
InsertEntry(*Entry) error
UpdateEntry(*Entry) (err error)
+ // err == filer2.ErrNotFound if not found
FindEntry(FullPath) (entry *Entry, err error)
DeleteEntry(FullPath) (err error)
ListDirectoryEntries(dirPath FullPath, startFileName string, includeStartFile bool, limit int) ([]*Entry, error)
diff --git a/weed/filer2/memdb/memdb_store.go b/weed/filer2/memdb/memdb_store.go
index 48a9bea314..08cee0afd0 100644
--- a/weed/filer2/memdb/memdb_store.go
+++ b/weed/filer2/memdb/memdb_store.go
@@ -49,7 +49,7 @@ func (store *MemDbStore) UpdateEntry(entry *filer2.Entry) (err error) {
func (store *MemDbStore) FindEntry(fullpath filer2.FullPath) (entry *filer2.Entry, err error) {
item := store.tree.Get(entryItem{&filer2.Entry{FullPath: fullpath}})
if item == nil {
- return nil, nil
+ return nil, filer2.ErrNotFound
}
entry = item.(entryItem).Entry
return entry, nil
diff --git a/weed/server/filer_server_handlers_write.go b/weed/server/filer_server_handlers_write.go
index 668f14ee87..0c278f67c7 100644
--- a/weed/server/filer_server_handlers_write.go
+++ b/weed/server/filer_server_handlers_write.go
@@ -27,20 +27,26 @@ type FilerPostResult struct {
func (fs *FilerServer) queryFileInfoByPath(w http.ResponseWriter, r *http.Request, path string) (fileId, urlLocation string, err error) {
var entry *filer2.Entry
- if entry, err = fs.filer.FindEntry(filer2.FullPath(path)); err != nil {
+ entry, err = fs.filer.FindEntry(filer2.FullPath(path))
+ if err == filer2.ErrNotFound {
+ return "", "", nil
+ }
+
+ if err != nil {
glog.V(0).Infoln("failing to find path in filer store", path, err.Error())
writeJsonError(w, r, http.StatusInternalServerError, err)
+ return
+ }
+
+ if len(entry.Chunks) == 0 {
+ glog.V(1).Infof("empty entry: %s", path)
+ w.WriteHeader(http.StatusNoContent)
} else {
- if len(entry.Chunks) == 0 {
- glog.V(1).Infof("empty entry: %s", path)
- w.WriteHeader(http.StatusNoContent)
- }else{
- fileId = entry.Chunks[0].FileId
- urlLocation, err = operation.LookupFileId(fs.filer.GetMaster(), fileId)
- if err != nil {
- glog.V(1).Infof("operation LookupFileId %s failed, err is %s", fileId, err.Error())
- w.WriteHeader(http.StatusNotFound)
- }
+ fileId = entry.Chunks[0].FileId
+ urlLocation, err = operation.LookupFileId(fs.filer.GetMaster(), fileId)
+ if err != nil {
+ glog.V(1).Infof("operation LookupFileId %s failed, err is %s", fileId, err.Error())
+ w.WriteHeader(http.StatusNotFound)
}
}
return