diff options
| author | Chris Lu <chris.lu@gmail.com> | 2018-10-15 00:03:55 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2018-10-15 00:03:55 -0700 |
| commit | 8301519fb0b339408c6d32a1ef940a46d70f41dc (patch) | |
| tree | fed93a752e0dd7fc2ee6b290aed7e805b9ad5fe3 /weed/server | |
| parent | db152ca54041694f30495a9de96bb891ecc71f8a (diff) | |
| download | seaweedfs-8301519fb0b339408c6d32a1ef940a46d70f41dc.tar.xz seaweedfs-8301519fb0b339408c6d32a1ef940a46d70f41dc.zip | |
migrate delete collection to grpc API on volume server
Diffstat (limited to 'weed/server')
| -rw-r--r-- | weed/server/master_server_handlers_admin.go | 11 | ||||
| -rw-r--r-- | weed/server/volume_grpc_admin.go | 22 | ||||
| -rw-r--r-- | weed/server/volume_server.go | 1 | ||||
| -rw-r--r-- | weed/server/volume_server_handlers_admin.go | 10 |
4 files changed, 32 insertions, 12 deletions
diff --git a/weed/server/master_server_handlers_admin.go b/weed/server/master_server_handlers_admin.go index 4f1d94594..99da2c603 100644 --- a/weed/server/master_server_handlers_admin.go +++ b/weed/server/master_server_handlers_admin.go @@ -1,6 +1,7 @@ package weed_server import ( + "context" "errors" "fmt" "math/rand" @@ -8,6 +9,8 @@ import ( "strconv" "github.com/chrislusf/seaweedfs/weed/glog" + "github.com/chrislusf/seaweedfs/weed/operation" + "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb" "github.com/chrislusf/seaweedfs/weed/storage" "github.com/chrislusf/seaweedfs/weed/topology" "github.com/chrislusf/seaweedfs/weed/util" @@ -20,7 +23,13 @@ func (ms *MasterServer) collectionDeleteHandler(w http.ResponseWriter, r *http.R return } for _, server := range collection.ListVolumeServers() { - _, err := util.Get("http://" + server.Ip + ":" + strconv.Itoa(server.Port) + "/admin/delete_collection?collection=" + r.FormValue("collection")) + serverAddress := fmt.Sprintf("%s:%d", server.Ip, server.Port) + err := operation.WithVolumeServerClient(serverAddress, func(client volume_server_pb.VolumeServerClient) error { + _, deleteErr := client.DeleteCollection(context.Background(), &volume_server_pb.DeleteCollectionRequest{ + Collection: collection.Name, + }) + return deleteErr + }) if err != nil { writeJsonError(w, r, http.StatusInternalServerError, err) return diff --git a/weed/server/volume_grpc_admin.go b/weed/server/volume_grpc_admin.go new file mode 100644 index 000000000..52a5e1928 --- /dev/null +++ b/weed/server/volume_grpc_admin.go @@ -0,0 +1,22 @@ +package weed_server + +import ( + "context" + + "github.com/chrislusf/seaweedfs/weed/glog" + "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb" +) + +func (vs *VolumeServer) DeleteCollection(ctx context.Context, req *volume_server_pb.DeleteCollectionRequest) (*volume_server_pb.DeleteCollectionResponse, error) { + + resp := &volume_server_pb.DeleteCollectionResponse{} + + err := vs.store.DeleteCollection(req.Collection) + + if err != nil { + glog.V(3).Infof("delete collection %s: %v", req.Collection, err) + } + + return resp, err + +} diff --git a/weed/server/volume_server.go b/weed/server/volume_server.go index 238330abb..64eeb0d79 100644 --- a/weed/server/volume_server.go +++ b/weed/server/volume_server.go @@ -48,7 +48,6 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string, adminMux.HandleFunc("/ui/index.html", vs.uiStatusHandler) adminMux.HandleFunc("/status", vs.guard.WhiteList(vs.statusHandler)) adminMux.HandleFunc("/admin/assign_volume", vs.guard.WhiteList(vs.assignVolumeHandler)) - adminMux.HandleFunc("/admin/delete_collection", vs.guard.WhiteList(vs.deleteCollectionHandler)) adminMux.HandleFunc("/admin/sync/status", vs.guard.WhiteList(vs.getVolumeSyncStatusHandler)) adminMux.HandleFunc("/admin/sync/index", vs.guard.WhiteList(vs.getVolumeIndexContentHandler)) adminMux.HandleFunc("/admin/sync/data", vs.guard.WhiteList(vs.getVolumeDataContentHandler)) diff --git a/weed/server/volume_server_handlers_admin.go b/weed/server/volume_server_handlers_admin.go index 9a8b92ebc..4e985f787 100644 --- a/weed/server/volume_server_handlers_admin.go +++ b/weed/server/volume_server_handlers_admin.go @@ -45,16 +45,6 @@ func (vs *VolumeServer) assignVolumeHandler(w http.ResponseWriter, r *http.Reque r.FormValue("volume"), r.FormValue("collection"), r.FormValue("replication"), err) } -func (vs *VolumeServer) deleteCollectionHandler(w http.ResponseWriter, r *http.Request) { - err := vs.store.DeleteCollection(r.FormValue("collection")) - if err == nil { - writeJsonQuiet(w, r, http.StatusOK, map[string]string{"error": ""}) - } else { - writeJsonError(w, r, http.StatusInternalServerError, err) - } - glog.V(2).Infof("deleting collection = %s, error = %v", r.FormValue("collection"), err) -} - func (vs *VolumeServer) statsDiskHandler(w http.ResponseWriter, r *http.Request) { m := make(map[string]interface{}) m["Version"] = util.VERSION |
