|
|
@ -135,27 +135,11 @@ func PostHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
ret := store.Write(volumeId, needle) |
|
|
|
if ret > 0 || !store.HasVolume(volumeId) { //send to other replica locations
|
|
|
|
if r.FormValue("type") != "standard" { |
|
|
|
if lookupResult, lookupErr := operation.Lookup(*masterNode, volumeId); lookupErr == nil { |
|
|
|
sendFunc := func(background bool) { |
|
|
|
postContentFunc := func(location operation.Location) bool { |
|
|
|
waitTime, err := strconv.Atoi(r.FormValue("wait")) |
|
|
|
distributedOperation(volumeId, func(location operation.Location) bool { |
|
|
|
operation.Upload("http://"+location.Url+r.URL.Path+"?type=standard", filename, bytes.NewReader(needle.Data)) |
|
|
|
return true |
|
|
|
} |
|
|
|
for _, location := range lookupResult.Locations { |
|
|
|
if location.Url != (*ip+":"+strconv.Itoa(*vport)) { |
|
|
|
if background { |
|
|
|
go postContentFunc(location) |
|
|
|
} else { |
|
|
|
postContentFunc(location) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
waitTime, err := strconv.Atoi(r.FormValue("wait")) |
|
|
|
sendFunc(err == nil && waitTime > 0) |
|
|
|
} else { |
|
|
|
log.Println("Failed to lookup for", volumeId, lookupErr.Error()) |
|
|
|
} |
|
|
|
}, err == nil && waitTime > 0) |
|
|
|
} |
|
|
|
w.WriteHeader(http.StatusCreated) |
|
|
|
} |
|
|
@ -191,7 +175,19 @@ func DeleteHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
} |
|
|
|
|
|
|
|
n.Size = 0 |
|
|
|
store.Delete(volumeId, n) |
|
|
|
ret := store.Delete(volumeId, n) |
|
|
|
|
|
|
|
if ret > 0 || !store.HasVolume(volumeId) { //send to other replica locations
|
|
|
|
if r.FormValue("type") != "standard" { |
|
|
|
waitTime, err := strconv.Atoi(r.FormValue("wait")) |
|
|
|
distributedOperation(volumeId, func(location operation.Location) bool { |
|
|
|
operation.Delete("http://"+location.Url+r.URL.Path+"?type=standard") |
|
|
|
return true |
|
|
|
}, err == nil && waitTime > 0) |
|
|
|
} |
|
|
|
w.WriteHeader(http.StatusCreated) |
|
|
|
} |
|
|
|
|
|
|
|
m := make(map[string]uint32) |
|
|
|
m["size"] = uint32(count) |
|
|
|
writeJson(w, r, m) |
|
|
@ -217,6 +213,27 @@ func parseURLPath(path string) (vid, fid, ext string) { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
type distributedFunction func(location operation.Location) bool |
|
|
|
|
|
|
|
func distributedOperation(volumeId storage.VolumeId, op distributedFunction, wait bool) { |
|
|
|
if lookupResult, lookupErr := operation.Lookup(*masterNode, volumeId); lookupErr == nil { |
|
|
|
sendFunc := func(background bool) { |
|
|
|
for _, location := range lookupResult.Locations { |
|
|
|
if location.Url != (*ip + ":" + strconv.Itoa(*vport)) { |
|
|
|
if background { |
|
|
|
go op(location) |
|
|
|
} else { |
|
|
|
op(location) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
sendFunc(wait) |
|
|
|
} else { |
|
|
|
log.Println("Failed to lookup for", volumeId, lookupErr.Error()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func runVolume(cmd *Command, args []string) bool { |
|
|
|
fileInfo, err := os.Stat(*volumeFolder) |
|
|
|
//TODO: now default to 1G, this value should come from server?
|
|
|
|