From e074a54a2080a13af7526c66ac60ad8a7ee9859a Mon Sep 17 00:00:00 2001 From: brstgt Date: Fri, 20 Jan 2017 13:02:37 +0100 Subject: [PATCH] Delete volumes online without restarting volume server --- weed/server/volume_server.go | 1 + weed/server/volume_server_handlers_admin.go | 44 +++++++++++++++++++++ weed/server/volume_server_handlers_sync.go | 34 +--------------- weed/storage/disk_location.go | 10 ++++- weed/storage/store.go | 10 +++++ 5 files changed, 65 insertions(+), 34 deletions(-) diff --git a/weed/server/volume_server.go b/weed/server/volume_server.go index bb2791622..cc06f0092 100644 --- a/weed/server/volume_server.go +++ b/weed/server/volume_server.go @@ -60,6 +60,7 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string, adminMux.HandleFunc("/admin/sync/data", vs.guard.WhiteList(vs.getVolumeDataContentHandler)) adminMux.HandleFunc("/admin/volume/mount", vs.guard.WhiteList(vs.getVolumeMountHandler)) adminMux.HandleFunc("/admin/volume/unmount", vs.guard.WhiteList(vs.getVolumeUnmountHandler)) + adminMux.HandleFunc("/admin/volume/delete", vs.guard.WhiteList(vs.getVolumeDeleteHandler)) adminMux.HandleFunc("/stats/counter", vs.guard.WhiteList(statsCounterHandler)) adminMux.HandleFunc("/stats/memory", vs.guard.WhiteList(statsMemoryHandler)) adminMux.HandleFunc("/stats/disk", vs.guard.WhiteList(vs.statsDiskHandler)) diff --git a/weed/server/volume_server_handlers_admin.go b/weed/server/volume_server_handlers_admin.go index 28631dac7..79bb89756 100644 --- a/weed/server/volume_server_handlers_admin.go +++ b/weed/server/volume_server_handlers_admin.go @@ -1,6 +1,7 @@ package weed_server import ( + "fmt" "net/http" "path/filepath" "strconv" @@ -8,6 +9,7 @@ import ( "github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/stats" "github.com/chrislusf/seaweedfs/weed/util" + "github.com/chrislusf/seaweedfs/weed/storage" ) func (vs *VolumeServer) statusHandler(w http.ResponseWriter, r *http.Request) { @@ -65,3 +67,45 @@ func (vs *VolumeServer) statsDiskHandler(w http.ResponseWriter, r *http.Request) m["DiskStatuses"] = ds writeJsonQuiet(w, r, http.StatusOK, m) } + +func (vs *VolumeServer) getVolume(volumeParameterName string, r *http.Request) (*storage.Volume, error) { + vid, err := vs.getVolumeId(volumeParameterName, r) + if err != nil { + return nil, err + } + v := vs.store.GetVolume(vid) + if v == nil { + return nil, fmt.Errorf("Not Found Volume Id %d", vid) + } + return v, nil +} + +func (vs *VolumeServer) getVolumeMountHandler(w http.ResponseWriter, r *http.Request) { + vid, err := vs.getVolumeId("volume", r) + if err != nil { + writeJsonError(w, r, http.StatusNotFound, err) + return + } + vs.store.MountVolume(vid) + writeJsonQuiet(w, r, http.StatusOK, "Volume mounted") +} + +func (vs *VolumeServer) getVolumeUnmountHandler(w http.ResponseWriter, r *http.Request) { + vid, err := vs.getVolumeId("volume", r) + if err != nil { + writeJsonError(w, r, http.StatusNotFound, err) + return + } + vs.store.UnmountVolume(vid) + writeJsonQuiet(w, r, http.StatusOK, "Volume unmounted") +} + +func (vs *VolumeServer) getVolumeDeleteHandler(w http.ResponseWriter, r *http.Request) { + vid, err := vs.getVolumeId("volume", r) + if err != nil { + writeJsonError(w, r, http.StatusNotFound, err) + return + } + vs.store.DeleteVolume(vid) + writeJsonQuiet(w, r, http.StatusOK, "Volume deleted") +} diff --git a/weed/server/volume_server_handlers_sync.go b/weed/server/volume_server_handlers_sync.go index 438f17b25..68c381e28 100644 --- a/weed/server/volume_server_handlers_sync.go +++ b/weed/server/volume_server_handlers_sync.go @@ -83,36 +83,4 @@ func (vs *VolumeServer) getVolumeId(volumeParameterName string, r *http.Request) } return vid, err -} - -func (vs *VolumeServer) getVolume(volumeParameterName string, r *http.Request) (*storage.Volume, error) { - vid, err := vs.getVolumeId(volumeParameterName, r) - if err != nil { - return nil, err - } - v := vs.store.GetVolume(vid) - if v == nil { - return nil, fmt.Errorf("Not Found Volume Id %d", vid) - } - return v, nil -} - -func (vs *VolumeServer) getVolumeMountHandler(w http.ResponseWriter, r *http.Request) { - vid, err := vs.getVolumeId("volume", r) - if err != nil { - writeJsonError(w, r, http.StatusNotFound, err) - return - } - vs.store.MountVolume(vid) - writeJsonQuiet(w, r, http.StatusOK, "Volume mounted") -} - -func (vs *VolumeServer) getVolumeUnmountHandler(w http.ResponseWriter, r *http.Request) { - vid, err := vs.getVolumeId("volume", r) - if err != nil { - writeJsonError(w, r, http.StatusNotFound, err) - return - } - vs.store.UnmountVolume(vid) - writeJsonQuiet(w, r, http.StatusOK, "Volume unmounted") -} +} \ No newline at end of file diff --git a/weed/storage/disk_location.go b/weed/storage/disk_location.go index 8f5527d30..a42f67ecd 100644 --- a/weed/storage/disk_location.go +++ b/weed/storage/disk_location.go @@ -152,7 +152,15 @@ func (l *DiskLocation) LoadVolume(vid VolumeId, needleMapKind NeedleMapType) boo return false } -func (l *DiskLocation) UnloadVolume(vid VolumeId) (e error) { +func (l *DiskLocation) DeleteVolume(vid VolumeId) (error) { + _, ok := l.volumes[vid] + if !ok { + return fmt.Errorf("Volume not found, VolumeId: %d", vid) + } + return l.deleteVolumeById(vid) +} + +func (l *DiskLocation) UnloadVolume(vid VolumeId) (error) { _, ok := l.volumes[vid] if !ok { return fmt.Errorf("Volume not loaded, VolumeId: %d", vid) diff --git a/weed/storage/store.go b/weed/storage/store.go index 045b48220..58c8de0d7 100644 --- a/weed/storage/store.go +++ b/weed/storage/store.go @@ -338,3 +338,13 @@ func (s *Store) UnmountVolume(i VolumeId) error { return fmt.Errorf("Volume %d not found on disk", i) } +func (s *Store) DeleteVolume(i VolumeId) error { + for _, location := range s.Locations { + if error := location.deleteVolumeById(i); error == nil { + s.updateMaster() + return nil + } + } + + return fmt.Errorf("Volume %d not found on disk", i) +}