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.

error handling

Chris Lu59ca65da3c59
diff --git a/weed-fs/src/cmd/weed/master.go b/weed-fs/src/cmd/weed/master.go
index 5b69b3d12d..9bc7acc3e3 100644
--- a/weed-fs/src/cmd/weed/master.go
+++ b/weed-fs/src/cmd/weed/master.go
@@ -45,17 +45,18 @@ func dirLookupHandler(w http.ResponseWriter, r *http.Request) {
if commaSep > 0 {
vid = vid[0:commaSep]
}
- volumeId, _ := storage.NewVolumeId(vid)
- machines := topo.Lookup(volumeId)
- if machines != nil {
- ret := []map[string]string{}
- for _, dn := range *machines {
- ret = append(ret, map[string]string{"url": dn.Ip + strconv.Itoa(dn.Port), "publicUrl": dn.PublicUrl})
+ volumeId, err := storage.NewVolumeId(vid)
+ if err == nil {
+ machines := topo.Lookup(volumeId)
+ if machines != nil {
+ ret := []map[string]string{}
+ for _, dn := range *machines {
+ ret = append(ret, map[string]string{"url": dn.Ip + strconv.Itoa(dn.Port), "publicUrl": dn.PublicUrl})
+ }
+ writeJson(w, r, map[string]interface{}{"locations": ret})
+ } else {
+ writeJson(w, r, map[string]string{"error": "volume id " + volumeId.String() + " not found. "})
}
- writeJson(w, r, map[string]interface{}{"locations": ret})
- } else {
- log.Println("Invalid volume id", volumeId)
- writeJson(w, r, map[string]string{"error": "volume id " + volumeId.String() + " not found. "})
}
}
diff --git a/weed-fs/src/cmd/weed/volume.go b/weed-fs/src/cmd/weed/volume.go
index a6d3e613ad..ed3d9a081b 100644
--- a/weed-fs/src/cmd/weed/volume.go
+++ b/weed-fs/src/cmd/weed/volume.go
@@ -65,21 +65,29 @@ func storeHandler(w http.ResponseWriter, r *http.Request) {
func GetHandler(w http.ResponseWriter, r *http.Request) {
n := new(storage.Needle)
vid, fid, ext := parseURLPath(r.URL.Path)
- volumeId, _ := storage.NewVolumeId(vid)
+ volumeId, err := storage.NewVolumeId(vid)
+ if err != nil {
+ if *IsDebug {
+ log.Println("parsing error:", err, r.URL.Path)
+ }
+ return
+ }
n.ParsePath(fid)
if *IsDebug {
log.Println("volume", volumeId, "reading", n)
}
if !store.HasVolume(volumeId) {
- lookupResult, err := operation.Lookup(*server, volumeId)
+ lookupResult, err := operation.Lookup(*masterNode, volumeId)
if *IsDebug {
log.Println("volume", volumeId, "found on", lookupResult, "error", err)
}
if err == nil {
http.Redirect(w, r, "http://"+lookupResult.Locations[0].PublicUrl+r.URL.Path, http.StatusMovedPermanently)
} else {
- log.Println("lookup error:", err)
+ if *IsDebug {
+ log.Println("lookup error:", err, r.URL.Path)
+ }
w.WriteHeader(http.StatusNotFound)
}
return
@@ -90,7 +98,7 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
log.Println("read bytes", count, "error", e)
}
if e != nil || count <= 0 {
- log.Println("read error:", e)
+ log.Println("read error:", e)
w.WriteHeader(http.StatusNotFound)
return
}