2014-04-14 07:13:18 +00:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2017-08-30 09:24:19 +00:00
|
|
|
"strconv"
|
2014-10-26 18:34:55 +00:00
|
|
|
|
2016-06-03 01:09:14 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2014-04-14 07:13:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (vs *VolumeServer) vacuumVolumeCheckHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err, ret := vs.store.CheckCompactVolume(r.FormValue("volume"), r.FormValue("garbageThreshold"))
|
|
|
|
if err == nil {
|
2015-01-08 08:19:32 +00:00
|
|
|
writeJsonQuiet(w, r, http.StatusOK, map[string]interface{}{"error": "", "result": ret})
|
2014-04-14 07:13:18 +00:00
|
|
|
} else {
|
2015-01-08 08:19:32 +00:00
|
|
|
writeJsonQuiet(w, r, http.StatusInternalServerError, map[string]interface{}{"error": err.Error(), "result": false})
|
2014-04-14 07:13:18 +00:00
|
|
|
}
|
|
|
|
glog.V(2).Infoln("checked compacting volume =", r.FormValue("volume"), "garbageThreshold =", r.FormValue("garbageThreshold"), "vacuum =", ret)
|
|
|
|
}
|
|
|
|
func (vs *VolumeServer) vacuumVolumeCompactHandler(w http.ResponseWriter, r *http.Request) {
|
2017-08-30 06:59:53 +00:00
|
|
|
var preallocate int64
|
|
|
|
var err error
|
|
|
|
if r.FormValue("preallocate") != "" {
|
|
|
|
preallocate, err = strconv.ParseInt(r.FormValue("preallocate"), 10, 64)
|
|
|
|
if err != nil {
|
2018-06-01 05:49:55 +00:00
|
|
|
glog.V(0).Infof("Failed to parse int64 preallocate = %s: %v", r.FormValue("preallocate"), err)
|
2017-08-30 06:59:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
err = vs.store.CompactVolume(r.FormValue("volume"), preallocate)
|
2014-04-14 07:13:18 +00:00
|
|
|
if err == nil {
|
2015-01-08 08:19:32 +00:00
|
|
|
writeJsonQuiet(w, r, http.StatusOK, map[string]string{"error": ""})
|
2014-04-14 07:13:18 +00:00
|
|
|
} else {
|
2015-01-08 08:19:32 +00:00
|
|
|
writeJsonError(w, r, http.StatusInternalServerError, err)
|
2014-04-14 07:13:18 +00:00
|
|
|
}
|
|
|
|
glog.V(2).Infoln("compacted volume =", r.FormValue("volume"), ", error =", err)
|
|
|
|
}
|
|
|
|
func (vs *VolumeServer) vacuumVolumeCommitHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err := vs.store.CommitCompactVolume(r.FormValue("volume"))
|
|
|
|
if err == nil {
|
2015-01-08 08:19:32 +00:00
|
|
|
writeJsonQuiet(w, r, http.StatusOK, map[string]string{"error": ""})
|
2014-04-14 07:13:18 +00:00
|
|
|
} else {
|
2015-01-08 08:19:32 +00:00
|
|
|
writeJsonError(w, r, http.StatusInternalServerError, err)
|
2014-04-14 07:13:18 +00:00
|
|
|
}
|
|
|
|
glog.V(2).Infoln("commit compact volume =", r.FormValue("volume"), ", error =", err)
|
|
|
|
}
|
2017-08-30 06:59:53 +00:00
|
|
|
func (vs *VolumeServer) vacuumVolumeCleanupHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err := vs.store.CommitCleanupVolume(r.FormValue("volume"))
|
|
|
|
if err == nil {
|
|
|
|
writeJsonQuiet(w, r, http.StatusOK, map[string]string{"error": ""})
|
|
|
|
} else {
|
|
|
|
writeJsonError(w, r, http.StatusInternalServerError, err)
|
|
|
|
}
|
|
|
|
glog.V(2).Infoln("cleanup compact volume =", r.FormValue("volume"), ", error =", err)
|
|
|
|
}
|