mirror of
https://github.com/FlourishingWorld/hk4e.git
synced 2026-02-04 14:12:27 +08:00
完善文档
This commit is contained in:
@@ -32,7 +32,7 @@ type DiscoveryNATSRPCServer interface {
|
||||
// 获取区服密钥信息
|
||||
GetRegionEc2B(ctx context.Context, req *NullMsg) (*RegionEc2B, error)
|
||||
// 获取负载最小的网关服务器的地址和端口
|
||||
GetGateServerAddr(ctx context.Context, req *NullMsg) (*GateServerAddr, error)
|
||||
GetGateServerAddr(ctx context.Context, req *GetGateServerAddrReq) (*GateServerAddr, error)
|
||||
}
|
||||
|
||||
// RegisterDiscoveryNATSRPCServer register Discovery service
|
||||
@@ -53,7 +53,7 @@ type DiscoveryNATSRPCClient interface {
|
||||
// 获取区服密钥信息
|
||||
GetRegionEc2B(ctx context.Context, req *NullMsg, opt ...natsrpc.CallOption) (*RegionEc2B, error)
|
||||
// 获取负载最小的网关服务器的地址和端口
|
||||
GetGateServerAddr(ctx context.Context, req *NullMsg, opt ...natsrpc.CallOption) (*GateServerAddr, error)
|
||||
GetGateServerAddr(ctx context.Context, req *GetGateServerAddrReq, opt ...natsrpc.CallOption) (*GateServerAddr, error)
|
||||
}
|
||||
|
||||
type _DiscoveryNATSRPCClient struct {
|
||||
@@ -96,7 +96,7 @@ func (c *_DiscoveryNATSRPCClient) GetRegionEc2B(ctx context.Context, req *NullMs
|
||||
err := c.c.Request(ctx, "GetRegionEc2B", req, rep, opt...)
|
||||
return rep, err
|
||||
}
|
||||
func (c *_DiscoveryNATSRPCClient) GetGateServerAddr(ctx context.Context, req *NullMsg, opt ...natsrpc.CallOption) (*GateServerAddr, error) {
|
||||
func (c *_DiscoveryNATSRPCClient) GetGateServerAddr(ctx context.Context, req *GetGateServerAddrReq, opt ...natsrpc.CallOption) (*GateServerAddr, error) {
|
||||
rep := &GateServerAddr{}
|
||||
err := c.c.Request(ctx, "GetGateServerAddr", req, rep, opt...)
|
||||
return rep, err
|
||||
|
||||
@@ -159,6 +159,7 @@ type RegisterServerReq struct {
|
||||
|
||||
ServerType string `protobuf:"bytes,1,opt,name=server_type,json=serverType,proto3" json:"server_type,omitempty"`
|
||||
GateServerAddr *GateServerAddr `protobuf:"bytes,2,opt,name=gate_server_addr,json=gateServerAddr,proto3" json:"gate_server_addr,omitempty"`
|
||||
Version string `protobuf:"bytes,3,opt,name=version,proto3" json:"version,omitempty"`
|
||||
}
|
||||
|
||||
func (x *RegisterServerReq) Reset() {
|
||||
@@ -207,6 +208,13 @@ func (x *RegisterServerReq) GetGateServerAddr() *GateServerAddr {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (x *RegisterServerReq) GetVersion() string {
|
||||
if x != nil {
|
||||
return x.Version
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type RegisterServerRsp struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -372,6 +380,53 @@ func (x *KeepaliveServerReq) GetAppId() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
type GetGateServerAddrReq struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"`
|
||||
}
|
||||
|
||||
func (x *GetGateServerAddrReq) Reset() {
|
||||
*x = GetGateServerAddrReq{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_api_proto_msgTypes[7]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *GetGateServerAddrReq) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*GetGateServerAddrReq) ProtoMessage() {}
|
||||
|
||||
func (x *GetGateServerAddrReq) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_api_proto_msgTypes[7]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use GetGateServerAddrReq.ProtoReflect.Descriptor instead.
|
||||
func (*GetGateServerAddrReq) Descriptor() ([]byte, []int) {
|
||||
return file_api_proto_rawDescGZIP(), []int{7}
|
||||
}
|
||||
|
||||
func (x *GetGateServerAddrReq) GetVersion() string {
|
||||
if x != nil {
|
||||
return x.Version
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type RegionEc2B struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -383,7 +438,7 @@ type RegionEc2B struct {
|
||||
func (x *RegionEc2B) Reset() {
|
||||
*x = RegionEc2B{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_api_proto_msgTypes[7]
|
||||
mi := &file_api_proto_msgTypes[8]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -396,7 +451,7 @@ func (x *RegionEc2B) String() string {
|
||||
func (*RegionEc2B) ProtoMessage() {}
|
||||
|
||||
func (x *RegionEc2B) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_api_proto_msgTypes[7]
|
||||
mi := &file_api_proto_msgTypes[8]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -409,7 +464,7 @@ func (x *RegionEc2B) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use RegionEc2B.ProtoReflect.Descriptor instead.
|
||||
func (*RegionEc2B) Descriptor() ([]byte, []int) {
|
||||
return file_api_proto_rawDescGZIP(), []int{7}
|
||||
return file_api_proto_rawDescGZIP(), []int{8}
|
||||
}
|
||||
|
||||
func (x *RegionEc2B) GetData() []byte {
|
||||
@@ -431,7 +486,7 @@ type GateServerAddr struct {
|
||||
func (x *GateServerAddr) Reset() {
|
||||
*x = GateServerAddr{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_api_proto_msgTypes[8]
|
||||
mi := &file_api_proto_msgTypes[9]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -444,7 +499,7 @@ func (x *GateServerAddr) String() string {
|
||||
func (*GateServerAddr) ProtoMessage() {}
|
||||
|
||||
func (x *GateServerAddr) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_api_proto_msgTypes[8]
|
||||
mi := &file_api_proto_msgTypes[9]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -457,7 +512,7 @@ func (x *GateServerAddr) ProtoReflect() protoreflect.Message {
|
||||
|
||||
// Deprecated: Use GateServerAddr.ProtoReflect.Descriptor instead.
|
||||
func (*GateServerAddr) Descriptor() ([]byte, []int) {
|
||||
return file_api_proto_rawDescGZIP(), []int{8}
|
||||
return file_api_proto_rawDescGZIP(), []int{9}
|
||||
}
|
||||
|
||||
func (x *GateServerAddr) GetIpAddr() string {
|
||||
@@ -485,63 +540,68 @@ var file_api_proto_rawDesc = []byte{
|
||||
0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x22, 0x2a, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72,
|
||||
0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x49, 0x64, 0x52, 0x73, 0x70, 0x12, 0x15, 0x0a, 0x06, 0x61,
|
||||
0x70, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70,
|
||||
0x49, 0x64, 0x22, 0x78, 0x0a, 0x11, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65,
|
||||
0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65,
|
||||
0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65,
|
||||
0x72, 0x76, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x42, 0x0a, 0x10, 0x67, 0x61, 0x74, 0x65,
|
||||
0x5f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01,
|
||||
0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x61,
|
||||
0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x52, 0x0e, 0x67, 0x61,
|
||||
0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x22, 0x3f, 0x0a, 0x11,
|
||||
0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x73,
|
||||
0x70, 0x12, 0x15, 0x0a, 0x06, 0x61, 0x70, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x12, 0x13, 0x0a, 0x05, 0x67, 0x73, 0x5f, 0x69,
|
||||
0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x67, 0x73, 0x49, 0x64, 0x22, 0x49, 0x0a,
|
||||
0x0f, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71,
|
||||
0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x54, 0x79, 0x70,
|
||||
0x65, 0x12, 0x15, 0x0a, 0x06, 0x61, 0x70, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||
0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x22, 0x4c, 0x0a, 0x12, 0x4b, 0x65, 0x65, 0x70,
|
||||
0x61, 0x6c, 0x69, 0x76, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1f,
|
||||
0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12,
|
||||
0x15, 0x0a, 0x06, 0x61, 0x70, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||
0x05, 0x61, 0x70, 0x70, 0x49, 0x64, 0x22, 0x20, 0x0a, 0x0a, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e,
|
||||
0x45, 0x63, 0x32, 0x62, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01,
|
||||
0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x3d, 0x0a, 0x0e, 0x47, 0x61, 0x74, 0x65,
|
||||
0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x70,
|
||||
0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x69, 0x70, 0x41,
|
||||
0x64, 0x64, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28,
|
||||
0x0d, 0x52, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x32, 0xad, 0x03, 0x0a, 0x09, 0x44, 0x69, 0x73, 0x63,
|
||||
0x6f, 0x76, 0x65, 0x72, 0x79, 0x12, 0x4c, 0x0a, 0x0e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65,
|
||||
0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61,
|
||||
0x70, 0x69, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65,
|
||||
0x72, 0x52, 0x65, 0x71, 0x1a, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e,
|
||||
0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x73,
|
||||
0x70, 0x22, 0x00, 0x12, 0x3e, 0x0a, 0x0c, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x53, 0x65, 0x72,
|
||||
0x76, 0x65, 0x72, 0x12, 0x19, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43,
|
||||
0x61, 0x6e, 0x63, 0x65, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x11,
|
||||
0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73,
|
||||
0x67, 0x22, 0x00, 0x12, 0x44, 0x0a, 0x0f, 0x4b, 0x65, 0x65, 0x70, 0x61, 0x6c, 0x69, 0x76, 0x65,
|
||||
0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x12, 0x1c, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70,
|
||||
0x69, 0x2e, 0x4b, 0x65, 0x65, 0x70, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65,
|
||||
0x72, 0x52, 0x65, 0x71, 0x1a, 0x11, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e,
|
||||
0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73, 0x67, 0x22, 0x00, 0x12, 0x4c, 0x0a, 0x0e, 0x47, 0x65, 0x74,
|
||||
0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x49, 0x64, 0x12, 0x1b, 0x2e, 0x6e, 0x6f,
|
||||
0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72,
|
||||
0x41, 0x70, 0x70, 0x49, 0x64, 0x52, 0x65, 0x71, 0x1a, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e,
|
||||
0x49, 0x64, 0x22, 0x92, 0x01, 0x0a, 0x11, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53,
|
||||
0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76,
|
||||
0x65, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73,
|
||||
0x65, 0x72, 0x76, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x42, 0x0a, 0x10, 0x67, 0x61, 0x74,
|
||||
0x65, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47,
|
||||
0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x52, 0x0e, 0x67,
|
||||
0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x12, 0x18, 0x0a,
|
||||
0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07,
|
||||
0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x3f, 0x0a, 0x11, 0x52, 0x65, 0x67, 0x69, 0x73,
|
||||
0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x73, 0x70, 0x12, 0x15, 0x0a, 0x06,
|
||||
0x61, 0x70, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70,
|
||||
0x70, 0x49, 0x64, 0x12, 0x13, 0x0a, 0x05, 0x67, 0x73, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01,
|
||||
0x28, 0x0d, 0x52, 0x04, 0x67, 0x73, 0x49, 0x64, 0x22, 0x49, 0x0a, 0x0f, 0x43, 0x61, 0x6e, 0x63,
|
||||
0x65, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1f, 0x0a, 0x0b, 0x73,
|
||||
0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
||||
0x52, 0x0a, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x15, 0x0a, 0x06,
|
||||
0x61, 0x70, 0x70, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70,
|
||||
0x70, 0x49, 0x64, 0x22, 0x4c, 0x0a, 0x12, 0x4b, 0x65, 0x65, 0x70, 0x61, 0x6c, 0x69, 0x76, 0x65,
|
||||
0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x65, 0x72,
|
||||
0x76, 0x65, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a,
|
||||
0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x54, 0x79, 0x70, 0x65, 0x12, 0x15, 0x0a, 0x06, 0x61, 0x70,
|
||||
0x70, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x61, 0x70, 0x70, 0x49,
|
||||
0x64, 0x22, 0x30, 0x0a, 0x14, 0x47, 0x65, 0x74, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76,
|
||||
0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x52, 0x65, 0x71, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72,
|
||||
0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73,
|
||||
0x69, 0x6f, 0x6e, 0x22, 0x20, 0x0a, 0x0a, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x45, 0x63, 0x32,
|
||||
0x62, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52,
|
||||
0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x3d, 0x0a, 0x0e, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72,
|
||||
0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x70, 0x5f, 0x61, 0x64,
|
||||
0x64, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x69, 0x70, 0x41, 0x64, 0x64, 0x72,
|
||||
0x12, 0x12, 0x0a, 0x04, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04,
|
||||
0x70, 0x6f, 0x72, 0x74, 0x32, 0xba, 0x03, 0x0a, 0x09, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65,
|
||||
0x72, 0x79, 0x12, 0x4c, 0x0a, 0x0e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65,
|
||||
0x72, 0x76, 0x65, 0x72, 0x12, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e,
|
||||
0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65,
|
||||
0x71, 0x1a, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x67,
|
||||
0x69, 0x73, 0x74, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x73, 0x70, 0x22, 0x00,
|
||||
0x12, 0x3e, 0x0a, 0x0c, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72,
|
||||
0x12, 0x19, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x43, 0x61, 0x6e, 0x63,
|
||||
0x65, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x11, 0x2e, 0x6e, 0x6f,
|
||||
0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73, 0x67, 0x22, 0x00,
|
||||
0x12, 0x44, 0x0a, 0x0f, 0x4b, 0x65, 0x65, 0x70, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x53, 0x65, 0x72,
|
||||
0x76, 0x65, 0x72, 0x12, 0x1c, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4b,
|
||||
0x65, 0x65, 0x70, 0x61, 0x6c, 0x69, 0x76, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x52, 0x65,
|
||||
0x71, 0x1a, 0x11, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x4e, 0x75, 0x6c,
|
||||
0x6c, 0x4d, 0x73, 0x67, 0x22, 0x00, 0x12, 0x4c, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72,
|
||||
0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x49, 0x64, 0x12, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e,
|
||||
0x61, 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x70, 0x70,
|
||||
0x49, 0x64, 0x52, 0x73, 0x70, 0x22, 0x00, 0x12, 0x3a, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, 0x65,
|
||||
0x67, 0x69, 0x6f, 0x6e, 0x45, 0x63, 0x32, 0x62, 0x12, 0x11, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e,
|
||||
0x61, 0x70, 0x69, 0x2e, 0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73, 0x67, 0x1a, 0x14, 0x2e, 0x6e, 0x6f,
|
||||
0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x45, 0x63, 0x32,
|
||||
0x62, 0x22, 0x00, 0x12, 0x42, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65,
|
||||
0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x12, 0x11, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e,
|
||||
0x61, 0x70, 0x69, 0x2e, 0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73, 0x67, 0x1a, 0x18, 0x2e, 0x6e, 0x6f,
|
||||
0x64, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65,
|
||||
0x72, 0x41, 0x64, 0x64, 0x72, 0x22, 0x00, 0x42, 0x13, 0x5a, 0x11, 0x68, 0x6b, 0x34, 0x65, 0x2f,
|
||||
0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x3b, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x33,
|
||||
0x49, 0x64, 0x52, 0x65, 0x71, 0x1a, 0x1b, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69,
|
||||
0x2e, 0x47, 0x65, 0x74, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x70, 0x70, 0x49, 0x64, 0x52,
|
||||
0x73, 0x70, 0x22, 0x00, 0x12, 0x3a, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x52, 0x65, 0x67, 0x69, 0x6f,
|
||||
0x6e, 0x45, 0x63, 0x32, 0x62, 0x12, 0x11, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69,
|
||||
0x2e, 0x4e, 0x75, 0x6c, 0x6c, 0x4d, 0x73, 0x67, 0x1a, 0x14, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e,
|
||||
0x61, 0x70, 0x69, 0x2e, 0x52, 0x65, 0x67, 0x69, 0x6f, 0x6e, 0x45, 0x63, 0x32, 0x62, 0x22, 0x00,
|
||||
0x12, 0x4f, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65,
|
||||
0x72, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1e, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69,
|
||||
0x2e, 0x47, 0x65, 0x74, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64,
|
||||
0x64, 0x72, 0x52, 0x65, 0x71, 0x1a, 0x18, 0x2e, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x61, 0x70, 0x69,
|
||||
0x2e, 0x47, 0x61, 0x74, 0x65, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x41, 0x64, 0x64, 0x72, 0x22,
|
||||
0x00, 0x42, 0x13, 0x5a, 0x11, 0x68, 0x6b, 0x34, 0x65, 0x2f, 0x6e, 0x6f, 0x64, 0x65, 0x2f, 0x61,
|
||||
0x70, 0x69, 0x3b, 0x61, 0x70, 0x69, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -556,32 +616,33 @@ func file_api_proto_rawDescGZIP() []byte {
|
||||
return file_api_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_api_proto_msgTypes = make([]protoimpl.MessageInfo, 9)
|
||||
var file_api_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
|
||||
var file_api_proto_goTypes = []interface{}{
|
||||
(*NullMsg)(nil), // 0: node.api.NullMsg
|
||||
(*GetServerAppIdReq)(nil), // 1: node.api.GetServerAppIdReq
|
||||
(*GetServerAppIdRsp)(nil), // 2: node.api.GetServerAppIdRsp
|
||||
(*RegisterServerReq)(nil), // 3: node.api.RegisterServerReq
|
||||
(*RegisterServerRsp)(nil), // 4: node.api.RegisterServerRsp
|
||||
(*CancelServerReq)(nil), // 5: node.api.CancelServerReq
|
||||
(*KeepaliveServerReq)(nil), // 6: node.api.KeepaliveServerReq
|
||||
(*RegionEc2B)(nil), // 7: node.api.RegionEc2b
|
||||
(*GateServerAddr)(nil), // 8: node.api.GateServerAddr
|
||||
(*NullMsg)(nil), // 0: node.api.NullMsg
|
||||
(*GetServerAppIdReq)(nil), // 1: node.api.GetServerAppIdReq
|
||||
(*GetServerAppIdRsp)(nil), // 2: node.api.GetServerAppIdRsp
|
||||
(*RegisterServerReq)(nil), // 3: node.api.RegisterServerReq
|
||||
(*RegisterServerRsp)(nil), // 4: node.api.RegisterServerRsp
|
||||
(*CancelServerReq)(nil), // 5: node.api.CancelServerReq
|
||||
(*KeepaliveServerReq)(nil), // 6: node.api.KeepaliveServerReq
|
||||
(*GetGateServerAddrReq)(nil), // 7: node.api.GetGateServerAddrReq
|
||||
(*RegionEc2B)(nil), // 8: node.api.RegionEc2b
|
||||
(*GateServerAddr)(nil), // 9: node.api.GateServerAddr
|
||||
}
|
||||
var file_api_proto_depIdxs = []int32{
|
||||
8, // 0: node.api.RegisterServerReq.gate_server_addr:type_name -> node.api.GateServerAddr
|
||||
9, // 0: node.api.RegisterServerReq.gate_server_addr:type_name -> node.api.GateServerAddr
|
||||
3, // 1: node.api.Discovery.RegisterServer:input_type -> node.api.RegisterServerReq
|
||||
5, // 2: node.api.Discovery.CancelServer:input_type -> node.api.CancelServerReq
|
||||
6, // 3: node.api.Discovery.KeepaliveServer:input_type -> node.api.KeepaliveServerReq
|
||||
1, // 4: node.api.Discovery.GetServerAppId:input_type -> node.api.GetServerAppIdReq
|
||||
0, // 5: node.api.Discovery.GetRegionEc2b:input_type -> node.api.NullMsg
|
||||
0, // 6: node.api.Discovery.GetGateServerAddr:input_type -> node.api.NullMsg
|
||||
7, // 6: node.api.Discovery.GetGateServerAddr:input_type -> node.api.GetGateServerAddrReq
|
||||
4, // 7: node.api.Discovery.RegisterServer:output_type -> node.api.RegisterServerRsp
|
||||
0, // 8: node.api.Discovery.CancelServer:output_type -> node.api.NullMsg
|
||||
0, // 9: node.api.Discovery.KeepaliveServer:output_type -> node.api.NullMsg
|
||||
2, // 10: node.api.Discovery.GetServerAppId:output_type -> node.api.GetServerAppIdRsp
|
||||
7, // 11: node.api.Discovery.GetRegionEc2b:output_type -> node.api.RegionEc2b
|
||||
8, // 12: node.api.Discovery.GetGateServerAddr:output_type -> node.api.GateServerAddr
|
||||
8, // 11: node.api.Discovery.GetRegionEc2b:output_type -> node.api.RegionEc2b
|
||||
9, // 12: node.api.Discovery.GetGateServerAddr:output_type -> node.api.GateServerAddr
|
||||
7, // [7:13] is the sub-list for method output_type
|
||||
1, // [1:7] is the sub-list for method input_type
|
||||
1, // [1:1] is the sub-list for extension type_name
|
||||
@@ -680,7 +741,7 @@ func file_api_proto_init() {
|
||||
}
|
||||
}
|
||||
file_api_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*RegionEc2B); i {
|
||||
switch v := v.(*GetGateServerAddrReq); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
@@ -692,6 +753,18 @@ func file_api_proto_init() {
|
||||
}
|
||||
}
|
||||
file_api_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*RegionEc2B); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_api_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*GateServerAddr); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -710,7 +783,7 @@ func file_api_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_api_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 9,
|
||||
NumMessages: 10,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
|
||||
@@ -16,7 +16,7 @@ service Discovery {
|
||||
// 获取区服密钥信息
|
||||
rpc GetRegionEc2b (NullMsg) returns (RegionEc2b) {}
|
||||
// 获取负载最小的网关服务器的地址和端口
|
||||
rpc GetGateServerAddr (NullMsg) returns (GateServerAddr) {}
|
||||
rpc GetGateServerAddr (GetGateServerAddrReq) returns (GateServerAddr) {}
|
||||
}
|
||||
|
||||
message NullMsg {
|
||||
@@ -33,6 +33,7 @@ message GetServerAppIdRsp {
|
||||
message RegisterServerReq {
|
||||
string server_type = 1;
|
||||
GateServerAddr gate_server_addr = 2;
|
||||
string version = 3;
|
||||
}
|
||||
|
||||
message RegisterServerRsp {
|
||||
@@ -50,6 +51,10 @@ message KeepaliveServerReq {
|
||||
string app_id = 2;
|
||||
}
|
||||
|
||||
message GetGateServerAddrReq {
|
||||
string version = 1;
|
||||
}
|
||||
|
||||
message RegionEc2b {
|
||||
bytes data = 1;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ import (
|
||||
"context"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"hk4e/common/region"
|
||||
"hk4e/node/api"
|
||||
@@ -35,28 +37,29 @@ type ServerInstance struct {
|
||||
appId string
|
||||
gateServerIpAddr string
|
||||
gateServerPort uint32
|
||||
version string
|
||||
lastAliveTime int64
|
||||
}
|
||||
|
||||
type DiscoveryService struct {
|
||||
regionEc2b *random.Ec2b
|
||||
// TODO 加锁
|
||||
serverInstanceMap map[string]map[string]*ServerInstance
|
||||
serverAppIdMap map[string]bool
|
||||
gsIdCounter uint32
|
||||
regionEc2b *random.Ec2b // 全局区服密钥信息
|
||||
serverInstanceMap map[string]*sync.Map // 全部服务器实例集合 key:服务器类型 value:服务器实例集合 -> key:appid value:服务器实例
|
||||
serverAppIdMap map[string]bool // 服务器appid集合 key:appid value:是否存在
|
||||
gsIdCounter uint32 // GSID计数器
|
||||
}
|
||||
|
||||
func NewDiscoveryService() *DiscoveryService {
|
||||
r := new(DiscoveryService)
|
||||
r.regionEc2b = region.NewRegionEc2b()
|
||||
logger.Info("region ec2b create ok, seed: %v", r.regionEc2b.Seed())
|
||||
r.serverInstanceMap = map[string]map[string]*ServerInstance{
|
||||
api.GATE: make(map[string]*ServerInstance),
|
||||
api.GS: make(map[string]*ServerInstance),
|
||||
api.FIGHT: make(map[string]*ServerInstance),
|
||||
api.PATHFINDING: make(map[string]*ServerInstance),
|
||||
}
|
||||
r.serverInstanceMap = make(map[string]*sync.Map)
|
||||
r.serverInstanceMap[api.GATE] = &sync.Map{}
|
||||
r.serverInstanceMap[api.GS] = &sync.Map{}
|
||||
r.serverInstanceMap[api.FIGHT] = &sync.Map{}
|
||||
r.serverInstanceMap[api.PATHFINDING] = &sync.Map{}
|
||||
r.serverAppIdMap = make(map[string]bool)
|
||||
r.gsIdCounter = 0
|
||||
go r.removeDeadServer()
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -84,8 +87,9 @@ func (s *DiscoveryService) RegisterServer(ctx context.Context, req *api.Register
|
||||
logger.Info("register new gate server, ip: %v, port: %v", req.GateServerAddr.IpAddr, req.GateServerAddr.Port)
|
||||
inst.gateServerIpAddr = req.GateServerAddr.IpAddr
|
||||
inst.gateServerPort = req.GateServerAddr.Port
|
||||
inst.version = req.Version
|
||||
}
|
||||
instMap[appId] = inst
|
||||
instMap.Store(appId, inst)
|
||||
logger.Info("new server appid is: %v", appId)
|
||||
rsp := &api.RegisterServerRsp{
|
||||
AppId: appId,
|
||||
@@ -103,11 +107,11 @@ func (s *DiscoveryService) CancelServer(ctx context.Context, req *api.CancelServ
|
||||
if !exist {
|
||||
return nil, errors.New("server type not exist")
|
||||
}
|
||||
_, exist = instMap[req.AppId]
|
||||
_, exist = instMap.Load(req.AppId)
|
||||
if !exist {
|
||||
return nil, errors.New("server not exist")
|
||||
}
|
||||
delete(instMap, req.AppId)
|
||||
instMap.Delete(req.AppId)
|
||||
return &api.NullMsg{}, nil
|
||||
}
|
||||
|
||||
@@ -117,12 +121,12 @@ func (s *DiscoveryService) KeepaliveServer(ctx context.Context, req *api.Keepali
|
||||
if !exist {
|
||||
return nil, errors.New("server type not exist")
|
||||
}
|
||||
inst, exist := instMap[req.AppId]
|
||||
inst, exist := instMap.Load(req.AppId)
|
||||
if !exist {
|
||||
return nil, errors.New("server not exist")
|
||||
}
|
||||
// TODO
|
||||
_ = inst
|
||||
serverInstance := inst.(*ServerInstance)
|
||||
serverInstance.lastAliveTime = time.Now().Unix()
|
||||
return &api.NullMsg{}, nil
|
||||
}
|
||||
|
||||
@@ -133,7 +137,7 @@ func (s *DiscoveryService) GetServerAppId(ctx context.Context, req *api.GetServe
|
||||
if !exist {
|
||||
return nil, errors.New("server type not exist")
|
||||
}
|
||||
if len(instMap) == 0 {
|
||||
if s.getServerInstanceMapLen(instMap) == 0 {
|
||||
return nil, errors.New("no server found")
|
||||
}
|
||||
inst := s.getRandomServerInstance(instMap)
|
||||
@@ -152,16 +156,28 @@ func (s *DiscoveryService) GetRegionEc2B(ctx context.Context, req *api.NullMsg)
|
||||
}
|
||||
|
||||
// GetGateServerAddr 获取负载最小的网关服务器的地址和端口
|
||||
func (s *DiscoveryService) GetGateServerAddr(ctx context.Context, req *api.NullMsg) (*api.GateServerAddr, error) {
|
||||
func (s *DiscoveryService) GetGateServerAddr(ctx context.Context, req *api.GetGateServerAddrReq) (*api.GateServerAddr, error) {
|
||||
logger.Debug("get gate server addr")
|
||||
instMap, exist := s.serverInstanceMap[api.GATE]
|
||||
if !exist {
|
||||
return nil, errors.New("gate server not exist")
|
||||
}
|
||||
if len(instMap) == 0 {
|
||||
if s.getServerInstanceMapLen(instMap) == 0 {
|
||||
return nil, errors.New("no gate server found")
|
||||
}
|
||||
inst := s.getRandomServerInstance(instMap)
|
||||
versionInstMap := sync.Map{}
|
||||
instMap.Range(func(key, value any) bool {
|
||||
serverInstance := value.(*ServerInstance)
|
||||
if serverInstance.version != req.Version {
|
||||
return true
|
||||
}
|
||||
versionInstMap.Store(key, serverInstance)
|
||||
return true
|
||||
})
|
||||
if s.getServerInstanceMapLen(&versionInstMap) == 0 {
|
||||
return nil, errors.New("no gate server found")
|
||||
}
|
||||
inst := s.getRandomServerInstance(&versionInstMap)
|
||||
logger.Debug("get gate server addr is, ip: %v, port: %v", inst.gateServerIpAddr, inst.gateServerPort)
|
||||
return &api.GateServerAddr{
|
||||
IpAddr: inst.gateServerIpAddr,
|
||||
@@ -169,13 +185,42 @@ func (s *DiscoveryService) GetGateServerAddr(ctx context.Context, req *api.NullM
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *DiscoveryService) getRandomServerInstance(instMap map[string]*ServerInstance) *ServerInstance {
|
||||
func (s *DiscoveryService) getRandomServerInstance(instMap *sync.Map) *ServerInstance {
|
||||
instList := make(ServerInstanceSortList, 0)
|
||||
for _, v := range instMap {
|
||||
instList = append(instList, v)
|
||||
}
|
||||
instMap.Range(func(key, value any) bool {
|
||||
instList = append(instList, value.(*ServerInstance))
|
||||
return true
|
||||
})
|
||||
sort.Stable(instList)
|
||||
index := random.GetRandomInt32(0, int32(len(instList)-1))
|
||||
inst := instList[index]
|
||||
return inst
|
||||
}
|
||||
|
||||
func (s *DiscoveryService) getServerInstanceMapLen(instMap *sync.Map) int {
|
||||
count := 0
|
||||
instMap.Range(func(key, value any) bool {
|
||||
count++
|
||||
return true
|
||||
})
|
||||
return count
|
||||
}
|
||||
|
||||
// 定时移除掉线服务器
|
||||
func (s *DiscoveryService) removeDeadServer() {
|
||||
ticker := time.NewTicker(time.Second * 60)
|
||||
for {
|
||||
<-ticker.C
|
||||
nowTime := time.Now().Unix()
|
||||
for _, instMap := range s.serverInstanceMap {
|
||||
instMap.Range(func(key, value any) bool {
|
||||
serverInstance := value.(*ServerInstance)
|
||||
if nowTime-serverInstance.lastAliveTime > 60 {
|
||||
logger.Warn("remove dead server, server type: %v, appid: %v", serverInstance.serverType, serverInstance.appId)
|
||||
instMap.Delete(key)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user