From 5065d4ab2df795436b1782c46836b2253a99034b Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 20 Nov 2018 11:35:45 -0800 Subject: [PATCH] master add grpc API for fileid assigning --- weed/operation/assign_file_id.go | 74 +++---- weed/pb/master.proto | 19 ++ weed/pb/master_pb/master.pb.go | 266 ++++++++++++++++++----- weed/server/master_grpc_server_lookup.go | 29 --- weed/server/master_grpc_server_volume.go | 86 ++++++++ 5 files changed, 352 insertions(+), 122 deletions(-) delete mode 100644 weed/server/master_grpc_server_lookup.go create mode 100644 weed/server/master_grpc_server_volume.go diff --git a/weed/operation/assign_file_id.go b/weed/operation/assign_file_id.go index 169fd664d..d9f12e545 100644 --- a/weed/operation/assign_file_id.go +++ b/weed/operation/assign_file_id.go @@ -1,13 +1,9 @@ package operation import ( - "encoding/json" "fmt" - "net/url" - "strconv" - - "github.com/chrislusf/seaweedfs/weed/glog" - "github.com/chrislusf/seaweedfs/weed/util" + "github.com/chrislusf/seaweedfs/weed/pb/master_pb" + "context" ) type VolumeAssignRequest struct { @@ -29,52 +25,54 @@ type AssignResult struct { } func Assign(server string, primaryRequest *VolumeAssignRequest, alternativeRequests ...*VolumeAssignRequest) (*AssignResult, error) { + var requests []*VolumeAssignRequest requests = append(requests, primaryRequest) requests = append(requests, alternativeRequests...) var lastError error + ret := &AssignResult{} + for i, request := range requests { if request == nil { continue } - values := make(url.Values) - values.Add("count", strconv.FormatUint(request.Count, 10)) - if request.Replication != "" { - values.Add("replication", request.Replication) - } - if request.Collection != "" { - values.Add("collection", request.Collection) - } - if request.Ttl != "" { - values.Add("ttl", request.Ttl) - } - if request.DataCenter != "" { - values.Add("dataCenter", request.DataCenter) - } - if request.Rack != "" { - values.Add("rack", request.Rack) - } - if request.DataNode != "" { - values.Add("dataNode", request.DataNode) + + lastError = withMasterServerClient(server, func(masterClient master_pb.SeaweedClient) error { + req := &master_pb.AssignRequest{ + Count: primaryRequest.Count, + Replication: primaryRequest.Replication, + Collection: primaryRequest.Collection, + Ttl: primaryRequest.Ttl, + DataCenter: primaryRequest.DataCenter, + Rack: primaryRequest.Rack, + DataNode: primaryRequest.DataNode, + } + resp, grpcErr := masterClient.Assign(context.Background(), req) + if grpcErr != nil { + return grpcErr + } + + ret.Count = resp.Count + ret.Fid = resp.Fid + ret.Url = resp.Url + ret.PublicUrl = resp.PublicUrl + ret.Error = resp.Error + + return nil + + }) + + if lastError != nil { + continue } - postUrl := fmt.Sprintf("http://%s/dir/assign", server) - jsonBlob, err := util.Post(postUrl, values) - glog.V(2).Infof("assign %d result from %s %+v : %s", i, postUrl, values, string(jsonBlob)) - if err != nil { - return nil, err - } - var ret AssignResult - err = json.Unmarshal(jsonBlob, &ret) - if err != nil { - return nil, fmt.Errorf("/dir/assign result JSON unmarshal error:%v, json:%s", err, string(jsonBlob)) - } if ret.Count <= 0 { lastError = fmt.Errorf("assign failure %d: %v", i+1, ret.Error) continue } - return &ret, nil + } - return nil, lastError + + return ret, lastError } diff --git a/weed/pb/master.proto b/weed/pb/master.proto index 3f348a4bd..c1e5d4798 100644 --- a/weed/pb/master.proto +++ b/weed/pb/master.proto @@ -11,6 +11,8 @@ service Seaweed { } rpc LookupVolume (LookupVolumeRequest) returns (LookupVolumeResponse) { } + rpc Assign (AssignRequest) returns (AssignResponse) { + } } ////////////////////////////////////////////////// @@ -89,3 +91,20 @@ message Location { string url = 1; string public_url = 2; } + +message AssignRequest { + uint64 count = 1; + string replication = 2; + string collection = 3; + string ttl = 4; + string data_center = 5; + string rack = 6; + string data_node = 7; +} +message AssignResponse { + string fid = 1; + string url = 2; + string public_url = 3; + uint64 count = 4; + string error = 5; +} diff --git a/weed/pb/master_pb/master.pb.go b/weed/pb/master_pb/master.pb.go index d99c789d7..79d4d3f53 100644 --- a/weed/pb/master_pb/master.pb.go +++ b/weed/pb/master_pb/master.pb.go @@ -19,6 +19,8 @@ It has these top-level messages: LookupVolumeRequest LookupVolumeResponse Location + AssignRequest + AssignResponse */ package master_pb @@ -471,6 +473,118 @@ func (m *Location) GetPublicUrl() string { return "" } +type AssignRequest struct { + Count uint64 `protobuf:"varint,1,opt,name=count" json:"count,omitempty"` + Replication string `protobuf:"bytes,2,opt,name=replication" json:"replication,omitempty"` + Collection string `protobuf:"bytes,3,opt,name=collection" json:"collection,omitempty"` + Ttl string `protobuf:"bytes,4,opt,name=ttl" json:"ttl,omitempty"` + DataCenter string `protobuf:"bytes,5,opt,name=data_center,json=dataCenter" json:"data_center,omitempty"` + Rack string `protobuf:"bytes,6,opt,name=rack" json:"rack,omitempty"` + DataNode string `protobuf:"bytes,7,opt,name=data_node,json=dataNode" json:"data_node,omitempty"` +} + +func (m *AssignRequest) Reset() { *m = AssignRequest{} } +func (m *AssignRequest) String() string { return proto.CompactTextString(m) } +func (*AssignRequest) ProtoMessage() {} +func (*AssignRequest) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{10} } + +func (m *AssignRequest) GetCount() uint64 { + if m != nil { + return m.Count + } + return 0 +} + +func (m *AssignRequest) GetReplication() string { + if m != nil { + return m.Replication + } + return "" +} + +func (m *AssignRequest) GetCollection() string { + if m != nil { + return m.Collection + } + return "" +} + +func (m *AssignRequest) GetTtl() string { + if m != nil { + return m.Ttl + } + return "" +} + +func (m *AssignRequest) GetDataCenter() string { + if m != nil { + return m.DataCenter + } + return "" +} + +func (m *AssignRequest) GetRack() string { + if m != nil { + return m.Rack + } + return "" +} + +func (m *AssignRequest) GetDataNode() string { + if m != nil { + return m.DataNode + } + return "" +} + +type AssignResponse struct { + Fid string `protobuf:"bytes,1,opt,name=fid" json:"fid,omitempty"` + Url string `protobuf:"bytes,2,opt,name=url" json:"url,omitempty"` + PublicUrl string `protobuf:"bytes,3,opt,name=public_url,json=publicUrl" json:"public_url,omitempty"` + Count uint64 `protobuf:"varint,4,opt,name=count" json:"count,omitempty"` + Error string `protobuf:"bytes,5,opt,name=error" json:"error,omitempty"` +} + +func (m *AssignResponse) Reset() { *m = AssignResponse{} } +func (m *AssignResponse) String() string { return proto.CompactTextString(m) } +func (*AssignResponse) ProtoMessage() {} +func (*AssignResponse) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{11} } + +func (m *AssignResponse) GetFid() string { + if m != nil { + return m.Fid + } + return "" +} + +func (m *AssignResponse) GetUrl() string { + if m != nil { + return m.Url + } + return "" +} + +func (m *AssignResponse) GetPublicUrl() string { + if m != nil { + return m.PublicUrl + } + return "" +} + +func (m *AssignResponse) GetCount() uint64 { + if m != nil { + return m.Count + } + return 0 +} + +func (m *AssignResponse) GetError() string { + if m != nil { + return m.Error + } + return "" +} + func init() { proto.RegisterType((*Heartbeat)(nil), "master_pb.Heartbeat") proto.RegisterType((*HeartbeatResponse)(nil), "master_pb.HeartbeatResponse") @@ -484,6 +598,8 @@ func init() { proto.RegisterType((*LookupVolumeResponse)(nil), "master_pb.LookupVolumeResponse") proto.RegisterType((*LookupVolumeResponse_VolumeIdLocation)(nil), "master_pb.LookupVolumeResponse.VolumeIdLocation") proto.RegisterType((*Location)(nil), "master_pb.Location") + proto.RegisterType((*AssignRequest)(nil), "master_pb.AssignRequest") + proto.RegisterType((*AssignResponse)(nil), "master_pb.AssignResponse") } // Reference imports to suppress errors if they are not otherwise used. @@ -500,6 +616,7 @@ type SeaweedClient interface { SendHeartbeat(ctx context.Context, opts ...grpc.CallOption) (Seaweed_SendHeartbeatClient, error) KeepConnected(ctx context.Context, opts ...grpc.CallOption) (Seaweed_KeepConnectedClient, error) LookupVolume(ctx context.Context, in *LookupVolumeRequest, opts ...grpc.CallOption) (*LookupVolumeResponse, error) + Assign(ctx context.Context, in *AssignRequest, opts ...grpc.CallOption) (*AssignResponse, error) } type seaweedClient struct { @@ -581,12 +698,22 @@ func (c *seaweedClient) LookupVolume(ctx context.Context, in *LookupVolumeReques return out, nil } +func (c *seaweedClient) Assign(ctx context.Context, in *AssignRequest, opts ...grpc.CallOption) (*AssignResponse, error) { + out := new(AssignResponse) + err := grpc.Invoke(ctx, "/master_pb.Seaweed/Assign", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for Seaweed service type SeaweedServer interface { SendHeartbeat(Seaweed_SendHeartbeatServer) error KeepConnected(Seaweed_KeepConnectedServer) error LookupVolume(context.Context, *LookupVolumeRequest) (*LookupVolumeResponse, error) + Assign(context.Context, *AssignRequest) (*AssignResponse, error) } func RegisterSeaweedServer(s *grpc.Server, srv SeaweedServer) { @@ -663,6 +790,24 @@ func _Seaweed_LookupVolume_Handler(srv interface{}, ctx context.Context, dec fun return interceptor(ctx, in, info, handler) } +func _Seaweed_Assign_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(AssignRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(SeaweedServer).Assign(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/master_pb.Seaweed/Assign", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(SeaweedServer).Assign(ctx, req.(*AssignRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Seaweed_serviceDesc = grpc.ServiceDesc{ ServiceName: "master_pb.Seaweed", HandlerType: (*SeaweedServer)(nil), @@ -671,6 +816,10 @@ var _Seaweed_serviceDesc = grpc.ServiceDesc{ MethodName: "LookupVolume", Handler: _Seaweed_LookupVolume_Handler, }, + { + MethodName: "Assign", + Handler: _Seaweed_Assign_Handler, + }, }, Streams: []grpc.StreamDesc{ { @@ -692,59 +841,66 @@ var _Seaweed_serviceDesc = grpc.ServiceDesc{ func init() { proto.RegisterFile("master.proto", fileDescriptor0) } var fileDescriptor0 = []byte{ - // 855 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x9c, 0x55, 0xcf, 0x6f, 0xdc, 0x44, - 0x14, 0xae, 0xbd, 0x9b, 0xec, 0xfa, 0x6d, 0x36, 0xdd, 0x4c, 0x22, 0xe4, 0x2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, 0xfe, 0x6f, 0x15, 0xcf, 0xfe, 0xf2, 0x60, 0x70, 0x83, 0xf4, 0x1e, 0x31, 0x27, 0x17, - 0x30, 0xbe, 0x41, 0x91, 0x6f, 0x7e, 0x1b, 0x27, 0x5b, 0x7c, 0xd6, 0xe8, 0xf4, 0xe9, 0x43, 0x68, - 0xdb, 0xab, 0xe8, 0x51, 0xec, 0xbd, 0xf0, 0xc8, 0x35, 0x8c, 0x2f, 0x11, 0xab, 0x79, 0x29, 0x04, - 0x66, 0x1a, 0x73, 0xf2, 0x6c, 0x2b, 0xe8, 0x81, 0x21, 0x9d, 0x3e, 0x79, 0xef, 0x6b, 0xdd, 0xbe, - 0xc9, 0x65, 0xfc, 0x1e, 0x0e, 0xb6, 0xb5, 0xd9, 0x49, 0xf8, 0xc0, 0x24, 0x4d, 0x9f, 0xff, 0x87, - 0xa8, 0xd1, 0xa3, 0xc5, 0xbe, 0xfd, 0x6b, 0x7e, 0xf9, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa1, - 0x9f, 0x87, 0x2e, 0x45, 0x07, 0x00, 0x00, + // 971 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x9c, 0x56, 0xcd, 0x6e, 0x23, 0x45, + 0x17, 0x4d, 0xb7, 0x7f, 0xfb, 0x3a, 0xce, 0x38, 0x95, 0xe8, 0x53, 0x8f, 0x67, 0xbe, 0x19, 0xd3, + 0x6c, 0x8c, 0x40, 0xd1, 0x10, 0x96, 0x08, 0x21, 0xc6, 0x0a, 0x22, 0x4a, 0x60, 0x42, 0x07, 0x66, + 0xc1, 0xa6, 0x29, 0x77, 0xdf, 0x44, 0xa5, 0xf4, 0x1f, 0x55, 0xe5, 0xc4, 0x9e, 0x0d, 0xef, 0xc5, + 0x82, 0x15, 0x3b, 0x1e, 0x85, 0x1d, 0x4f, 0x80, 0xea, 0xa7, 0xdb, 0x6d, 0x27, 0x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, 0xe3, 0x19, 0x78, 0x06, 0x9e, 0x4e, 0xca, + 0x8b, 0x04, 0xed, 0xfb, 0xd0, 0x57, 0xc0, 0x77, 0x45, 0xa2, 0xcb, 0xba, 0x3a, 0x8c, 0x35, 0x7e, + 0x04, 0xad, 0xab, 0x5a, 0x7c, 0x35, 0xac, 0x24, 0x72, 0x1f, 0x93, 0xe8, 0xde, 0xcb, 0x57, 0x0b, + 0xd2, 0x6e, 0x0a, 0x52, 0x7b, 0xd1, 0x69, 0x78, 0x71, 0xfc, 0x9b, 0x0b, 0xbd, 0x4b, 0xa4, 0x77, + 0x88, 0x09, 0x39, 0x85, 0xe1, 0x25, 0xe6, 0xc9, 0xfa, 0x15, 0x3e, 0x6c, 0xd8, 0x5b, 0xa3, 0xe3, + 0xe7, 0x0f, 0xa1, 0x15, 0xff, 0x60, 0x67, 0xea, 0xbc, 0x72, 0xc8, 0x05, 0x0c, 0xcf, 0x10, 0xcb, + 0x59, 0x91, 0xe7, 0x18, 0x4b, 0x4c, 0xc8, 0x8b, 0x46, 0xd2, 0x03, 0x3d, 0x3f, 0x7e, 0x7a, 0xef, + 0xf1, 0xab, 0x4a, 0xc4, 0xae, 0xf8, 0x3d, 0xec, 0x36, 0x4b, 0x7d, 0x63, 0xc1, 0x07, 0x1a, 0x73, + 0xfc, 0xf2, 0x3d, 0x3d, 0x12, 0xec, 0x90, 0x2f, 0xa1, 0x6b, 0xc4, 0x27, 0x7e, 0x23, 0x78, 0xa3, + 0xb8, 0x36, 0x78, 0x6d, 0x3a, 0x15, 0xec, 0xcc, 0xbb, 0xfa, 0x2f, 0xe6, 0xb3, 0x7f, 0x02, 0x00, + 0x00, 0xff, 0xff, 0xbc, 0xef, 0x85, 0x4d, 0xd5, 0x08, 0x00, 0x00, } diff --git a/weed/server/master_grpc_server_lookup.go b/weed/server/master_grpc_server_lookup.go deleted file mode 100644 index 05458f1cf..000000000 --- a/weed/server/master_grpc_server_lookup.go +++ /dev/null @@ -1,29 +0,0 @@ -package weed_server - -import ( - "context" - - "github.com/chrislusf/seaweedfs/weed/pb/master_pb" -) - -func (ms *MasterServer) LookupVolume(ctx context.Context, req *master_pb.LookupVolumeRequest) (*master_pb.LookupVolumeResponse, error) { - resp := &master_pb.LookupVolumeResponse{} - volumeLocations := ms.lookupVolumeId(req.VolumeIds, req.Collection) - - for _, result := range volumeLocations { - var locations []*master_pb.Location - for _, loc := range result.Locations { - locations = append(locations, &master_pb.Location{ - Url: loc.Url, - PublicUrl: loc.PublicUrl, - }) - } - resp.VolumeIdLocations = append(resp.VolumeIdLocations, &master_pb.LookupVolumeResponse_VolumeIdLocation{ - VolumeId: result.VolumeId, - Locations: locations, - Error: result.Error, - }) - } - - return resp, nil -} diff --git a/weed/server/master_grpc_server_volume.go b/weed/server/master_grpc_server_volume.go new file mode 100644 index 000000000..26dec1577 --- /dev/null +++ b/weed/server/master_grpc_server_volume.go @@ -0,0 +1,86 @@ +package weed_server + +import ( + "context" + "fmt" + + "github.com/chrislusf/seaweedfs/weed/pb/master_pb" + "github.com/chrislusf/seaweedfs/weed/topology" + "github.com/chrislusf/seaweedfs/weed/storage" +) + +func (ms *MasterServer) LookupVolume(ctx context.Context, req *master_pb.LookupVolumeRequest) (*master_pb.LookupVolumeResponse, error) { + resp := &master_pb.LookupVolumeResponse{} + volumeLocations := ms.lookupVolumeId(req.VolumeIds, req.Collection) + + for _, result := range volumeLocations { + var locations []*master_pb.Location + for _, loc := range result.Locations { + locations = append(locations, &master_pb.Location{ + Url: loc.Url, + PublicUrl: loc.PublicUrl, + }) + } + resp.VolumeIdLocations = append(resp.VolumeIdLocations, &master_pb.LookupVolumeResponse_VolumeIdLocation{ + VolumeId: result.VolumeId, + Locations: locations, + Error: result.Error, + }) + } + + return resp, nil +} + +func (ms *MasterServer) Assign(ctx context.Context, req *master_pb.AssignRequest) (*master_pb.AssignResponse, error) { + + if req.Count == 0 { + req.Count = 1 + } + + if req.Replication == "" { + req.Replication = ms.defaultReplicaPlacement + } + replicaPlacement, err := storage.NewReplicaPlacementFromString(req.Replication) + if err != nil { + return nil, err + } + ttl, err := storage.ReadTTL(req.Ttl) + if err != nil { + return nil, err + } + + option := &topology.VolumeGrowOption{ + Collection: req.Collection, + ReplicaPlacement: replicaPlacement, + Ttl: ttl, + Prealloacte: ms.preallocate, + DataCenter: req.DataCenter, + Rack: req.Rack, + DataNode: req.DataNode, + } + + if !ms.Topo.HasWritableVolume(option) { + if ms.Topo.FreeSpace() <= 0 { + return nil, fmt.Errorf("No free volumes left!") + } + ms.vgLock.Lock() + if !ms.Topo.HasWritableVolume(option) { + if _, err = ms.vg.AutomaticGrowByType(option, ms.Topo); err != nil { + ms.vgLock.Unlock() + return nil, fmt.Errorf("Cannot grow volume group! %v", err) + } + } + ms.vgLock.Unlock() + } + fid, count, dn, err := ms.Topo.PickForWrite(req.Count, option) + if err != nil { + return nil, fmt.Errorf("%v", err) + } + + return &master_pb.AssignResponse{ + Fid: fid, + Url: dn.Url(), + PublicUrl: dn.PublicUrl, + Count: count, + }, nil +}