mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
more error handling
This commit is contained in:
parent
a847e2beee
commit
20706d8cf2
|
@ -77,6 +77,7 @@ func dirAssignHandler(w http.ResponseWriter, r *http.Request) {
|
|||
if topo.GetVolumeLayout(rt).GetActiveVolumeCount() <= 0 {
|
||||
if topo.FreeSpace() <= 0 {
|
||||
writeJson(w, r, map[string]string{"error": "No free volumes left!"})
|
||||
return
|
||||
} else {
|
||||
vg.GrowByType(rt, topo)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"pkg/operation"
|
||||
"pkg/operation"
|
||||
"pkg/util"
|
||||
"strconv"
|
||||
)
|
||||
|
@ -60,7 +60,7 @@ func assign(count int) (*AssignResult, error) {
|
|||
return &ret, nil
|
||||
}
|
||||
|
||||
func upload(filename string, server string, fid string) (int) {
|
||||
func upload(filename string, server string, fid string) (int, error) {
|
||||
if *IsDebug {
|
||||
fmt.Println("Start uploading file:", filename)
|
||||
}
|
||||
|
@ -69,15 +69,19 @@ func upload(filename string, server string, fid string) (int) {
|
|||
if *IsDebug {
|
||||
fmt.Println("Failed to open file:", filename)
|
||||
}
|
||||
panic(err.Error())
|
||||
return 0, err
|
||||
}
|
||||
ret, _ := operation.Upload("http://"+server+"/"+fid, filename, fh)
|
||||
return ret.Size
|
||||
ret, e := operation.Upload("http://"+server+"/"+fid, filename, fh)
|
||||
if e != nil {
|
||||
return 0, e
|
||||
}
|
||||
return ret.Size, e
|
||||
}
|
||||
|
||||
type SubmitResult struct {
|
||||
Fid string "fid"
|
||||
Size int "size"
|
||||
Fid string "fid"
|
||||
Size int "size"
|
||||
Error string "error"
|
||||
}
|
||||
|
||||
func submit(files []string) []SubmitResult {
|
||||
|
@ -92,7 +96,11 @@ func submit(files []string) []SubmitResult {
|
|||
if index > 0 {
|
||||
fid = fid + "_" + strconv.Itoa(index)
|
||||
}
|
||||
results[index].Size = upload(file, ret.PublicUrl, fid)
|
||||
results[index].Size, err = upload(file, ret.PublicUrl, fid)
|
||||
if err != nil {
|
||||
fid = ""
|
||||
results[index].Error = err.Error()
|
||||
}
|
||||
results[index].Fid = fid
|
||||
}
|
||||
return results
|
||||
|
|
|
@ -133,6 +133,7 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
|
|||
writeJson(w, r, ne)
|
||||
} else {
|
||||
ret := store.Write(volumeId, needle)
|
||||
errorStatus := ""
|
||||
if ret > 0 || !store.HasVolume(volumeId) { //send to other replica locations
|
||||
if r.FormValue("type") != "standard" {
|
||||
if distributedOperation(volumeId, func(location operation.Location) bool {
|
||||
|
@ -142,16 +143,19 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
|
|||
w.WriteHeader(http.StatusCreated)
|
||||
} else {
|
||||
ret = 0
|
||||
errorStatus = "Failed to write to replicas for volume " + volumeId.String()
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
} else {
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
}
|
||||
} else {
|
||||
errorStatus = "Failed to write to local disk"
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
m := make(map[string]uint32)
|
||||
m := make(map[string]interface{})
|
||||
m["size"] = ret
|
||||
m["error"] = errorStatus
|
||||
writeJson(w, r, m)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,10 +9,12 @@ import (
|
|||
"log"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type UploadResult struct {
|
||||
Size int
|
||||
Error string
|
||||
}
|
||||
|
||||
func Upload(uploadUrl string, filename string, reader io.Reader) (*UploadResult, error) {
|
||||
|
@ -38,5 +40,8 @@ func Upload(uploadUrl string, filename string, reader io.Reader) (*UploadResult,
|
|||
log.Println("failing to read upload resonse", uploadUrl, resp_body)
|
||||
return nil, err
|
||||
}
|
||||
if ret.Error != ""{
|
||||
return nil, errors.New(ret.Error)
|
||||
}
|
||||
return &ret, nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue