volume_server_handlers_vacuum.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package weed_server
  2. import (
  3. "net/http"
  4. "strconv"
  5. "github.com/chrislusf/seaweedfs/weed/glog"
  6. )
  7. func (vs *VolumeServer) vacuumVolumeCheckHandler(w http.ResponseWriter, r *http.Request) {
  8. err, ret := vs.store.CheckCompactVolume(r.FormValue("volume"), r.FormValue("garbageThreshold"))
  9. if err == nil {
  10. writeJsonQuiet(w, r, http.StatusOK, map[string]interface{}{"error": "", "result": ret})
  11. } else {
  12. writeJsonQuiet(w, r, http.StatusInternalServerError, map[string]interface{}{"error": err.Error(), "result": false})
  13. }
  14. glog.V(2).Infoln("checked compacting volume =", r.FormValue("volume"), "garbageThreshold =", r.FormValue("garbageThreshold"), "vacuum =", ret)
  15. }
  16. func (vs *VolumeServer) vacuumVolumeCompactHandler(w http.ResponseWriter, r *http.Request) {
  17. var preallocate int64
  18. var err error
  19. if r.FormValue("preallocate") != "" {
  20. preallocate, err = strconv.ParseInt(r.FormValue("preallocate"), 10, 64)
  21. if err != nil {
  22. glog.V(0).Infof("Failed to parse int64 preallocate = %s: %v", r.FormValue("preallocate"), err)
  23. }
  24. }
  25. err = vs.store.CompactVolume(r.FormValue("volume"), preallocate)
  26. if err == nil {
  27. writeJsonQuiet(w, r, http.StatusOK, map[string]string{"error": ""})
  28. } else {
  29. writeJsonError(w, r, http.StatusInternalServerError, err)
  30. }
  31. glog.V(2).Infoln("compacted volume =", r.FormValue("volume"), ", error =", err)
  32. }
  33. func (vs *VolumeServer) vacuumVolumeCommitHandler(w http.ResponseWriter, r *http.Request) {
  34. err := vs.store.CommitCompactVolume(r.FormValue("volume"))
  35. if err == nil {
  36. writeJsonQuiet(w, r, http.StatusOK, map[string]string{"error": ""})
  37. } else {
  38. writeJsonError(w, r, http.StatusInternalServerError, err)
  39. }
  40. glog.V(2).Infoln("commit compact volume =", r.FormValue("volume"), ", error =", err)
  41. }
  42. func (vs *VolumeServer) vacuumVolumeCleanupHandler(w http.ResponseWriter, r *http.Request) {
  43. err := vs.store.CommitCleanupVolume(r.FormValue("volume"))
  44. if err == nil {
  45. writeJsonQuiet(w, r, http.StatusOK, map[string]string{"error": ""})
  46. } else {
  47. writeJsonError(w, r, http.StatusInternalServerError, err)
  48. }
  49. glog.V(2).Infoln("cleanup compact volume =", r.FormValue("volume"), ", error =", err)
  50. }