migrate assign volume to grpc API on volume server
This commit is contained in:
@@ -23,8 +23,7 @@ func (ms *MasterServer) collectionDeleteHandler(w http.ResponseWriter, r *http.R
|
||||
return
|
||||
}
|
||||
for _, server := range collection.ListVolumeServers() {
|
||||
serverAddress := fmt.Sprintf("%s:%d", server.Ip, server.Port)
|
||||
err := operation.WithVolumeServerClient(serverAddress, func(client volume_server_pb.VolumeServerClient) error {
|
||||
err := operation.WithVolumeServerClient(server.Url(), func(client volume_server_pb.VolumeServerClient) error {
|
||||
_, deleteErr := client.DeleteCollection(context.Background(), &volume_server_pb.DeleteCollectionRequest{
|
||||
Collection: collection.Name,
|
||||
})
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage"
|
||||
)
|
||||
|
||||
func (vs *VolumeServer) DeleteCollection(ctx context.Context, req *volume_server_pb.DeleteCollectionRequest) (*volume_server_pb.DeleteCollectionResponse, error) {
|
||||
@@ -14,7 +15,32 @@ func (vs *VolumeServer) DeleteCollection(ctx context.Context, req *volume_server
|
||||
err := vs.store.DeleteCollection(req.Collection)
|
||||
|
||||
if err != nil {
|
||||
glog.V(3).Infof("delete collection %s: %v", req.Collection, err)
|
||||
glog.Errorf("delete collection %s: %v", req.Collection, err)
|
||||
} else {
|
||||
glog.V(2).Infof("delete collection %v", req)
|
||||
}
|
||||
|
||||
return resp, err
|
||||
|
||||
}
|
||||
|
||||
func (vs *VolumeServer) AssignVolume(ctx context.Context, req *volume_server_pb.AssignVolumeRequest) (*volume_server_pb.AssignVolumeResponse, error) {
|
||||
|
||||
resp := &volume_server_pb.AssignVolumeResponse{}
|
||||
|
||||
err := vs.store.AddVolume(
|
||||
storage.VolumeId(req.VolumdId),
|
||||
req.Collection,
|
||||
vs.needleMapKind,
|
||||
req.Replication,
|
||||
req.Ttl,
|
||||
req.Preallocate,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
glog.Errorf("assign volume %v: %v", req, err)
|
||||
} else {
|
||||
glog.V(2).Infof("assign volume %v", req)
|
||||
}
|
||||
|
||||
return resp, err
|
||||
|
||||
@@ -47,7 +47,6 @@ func NewVolumeServer(adminMux, publicMux *http.ServeMux, ip string,
|
||||
handleStaticResources(adminMux)
|
||||
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/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))
|
||||
|
||||
@@ -4,10 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
"github.com/chrislusf/seaweedfs/weed/stats"
|
||||
"github.com/chrislusf/seaweedfs/weed/stats"
|
||||
"github.com/chrislusf/seaweedfs/weed/storage"
|
||||
"github.com/chrislusf/seaweedfs/weed/util"
|
||||
)
|
||||
@@ -19,32 +16,6 @@ func (vs *VolumeServer) statusHandler(w http.ResponseWriter, r *http.Request) {
|
||||
writeJsonQuiet(w, r, http.StatusOK, m)
|
||||
}
|
||||
|
||||
func (vs *VolumeServer) assignVolumeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
var err error
|
||||
preallocate := int64(0)
|
||||
if r.FormValue("preallocate") != "" {
|
||||
preallocate, err = strconv.ParseInt(r.FormValue("preallocate"), 10, 64)
|
||||
if err != nil {
|
||||
glog.V(0).Infof("ignoring invalid int64 value for preallocate = %v", r.FormValue("preallocate"))
|
||||
}
|
||||
}
|
||||
err = vs.store.AddVolume(
|
||||
r.FormValue("volume"),
|
||||
r.FormValue("collection"),
|
||||
vs.needleMapKind,
|
||||
r.FormValue("replication"),
|
||||
r.FormValue("ttl"),
|
||||
preallocate,
|
||||
)
|
||||
if err == nil {
|
||||
writeJsonQuiet(w, r, http.StatusAccepted, map[string]string{"error": ""})
|
||||
} else {
|
||||
writeJsonError(w, r, http.StatusNotAcceptable, err)
|
||||
}
|
||||
glog.V(2).Infof("assign volume = %s, collection = %s , replication = %s, error = %v",
|
||||
r.FormValue("volume"), r.FormValue("collection"), r.FormValue("replication"), err)
|
||||
}
|
||||
|
||||
func (vs *VolumeServer) statsDiskHandler(w http.ResponseWriter, r *http.Request) {
|
||||
m := make(map[string]interface{})
|
||||
m["Version"] = util.VERSION
|
||||
|
||||
Reference in New Issue
Block a user