mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-10-15 20:06:19 +08:00
Use type AssignResult when writing and reading result.
This commit is contained in:
@@ -10,11 +10,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AssignResult struct {
|
type AssignResult struct {
|
||||||
Fid string `json:"fid"`
|
Fid string `json:"fid,omitempty"`
|
||||||
Url string `json:"url"`
|
Url string `json:"url,omitempty"`
|
||||||
PublicUrl string `json:"publicUrl"`
|
PublicUrl string `json:"publicUrl,omitempty"`
|
||||||
Count int
|
Count int `json:"count,omitempty"`
|
||||||
Error string `json:"error"`
|
Error string `json:"error,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func Assign(server string, count int, replication string, collection string) (*AssignResult, error) {
|
func Assign(server string, count int, replication string, collection string) (*AssignResult, error) {
|
||||||
|
@@ -74,21 +74,21 @@ func (ms *MasterServer) dirAssignHandler(w http.ResponseWriter, r *http.Request)
|
|||||||
option, err := ms.getVolumeGrowOption(r)
|
option, err := ms.getVolumeGrowOption(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusNotAcceptable)
|
w.WriteHeader(http.StatusNotAcceptable)
|
||||||
writeJsonQuiet(w, r, map[string]string{"error": err.Error()})
|
writeJsonQuiet(w, r, AssignResult{Error: err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ms.Topo.HasWriableVolume(option) {
|
if !ms.Topo.HasWriableVolume(option) {
|
||||||
if ms.Topo.FreeSpace() <= 0 {
|
if ms.Topo.FreeSpace() <= 0 {
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
writeJsonQuiet(w, r, map[string]string{"error": "No free volumes left!"})
|
writeJsonQuiet(w, r, AssignResult{Error: "No free volumes left!"})
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
ms.vgLock.Lock()
|
ms.vgLock.Lock()
|
||||||
defer ms.vgLock.Unlock()
|
defer ms.vgLock.Unlock()
|
||||||
if !ms.Topo.HasWriableVolume(option) {
|
if !ms.Topo.HasWriableVolume(option) {
|
||||||
if _, err = ms.vg.AutomaticGrowByType(option, ms.Topo); err != nil {
|
if _, err = ms.vg.AutomaticGrowByType(option, ms.Topo); err != nil {
|
||||||
writeJsonQuiet(w, r, map[string]string{"error": "Cannot grow volume group! " + err.Error()})
|
writeJsonQuiet(w, r, AssignResult{Error: "Cannot grow volume group! " + err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,9 +96,9 @@ func (ms *MasterServer) dirAssignHandler(w http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
fid, count, dn, err := ms.Topo.PickForWrite(requestedCount, option)
|
fid, count, dn, err := ms.Topo.PickForWrite(requestedCount, option)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
writeJsonQuiet(w, r, map[string]interface{}{"fid": fid, "url": dn.Url(), "publicUrl": dn.PublicUrl, "count": count})
|
writeJsonQuiet(w, r, AssignResult{Fid: fid, Url: dn.Url(), PublicUrl: dn.PublicUrl, Count: count})
|
||||||
} else {
|
} else {
|
||||||
w.WriteHeader(http.StatusNotAcceptable)
|
w.WriteHeader(http.StatusNotAcceptable)
|
||||||
writeJsonQuiet(w, r, map[string]string{"error": err.Error()})
|
writeJsonQuiet(w, r, AssignResult{Error: err.Error()})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user