Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

Delete volumes online without restarting volume server

brstgte074a54a2080
diff --git a/weed/server/volume_server.go b/weed/server/volume_server.go
index bb27916220..cc06f0092d 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 28631dac76..79bb89756d 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 438f17b253..68c381e28f 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 8f5527d308..a42f67ecd1 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 045b482202..58c8de0d71 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)
+}