From 212798dc0465948e243ca8266eef9e366f702f5b Mon Sep 17 00:00:00 2001 From: boyce Date: Fri, 7 May 2021 15:22:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=82=BB=E5=B1=85master?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=8F=91=E7=8E=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cluster/cluster.go | 39 +++++-- cluster/dynamicdiscovery.go | 118 ++++++++++++++------- cluster/parsecfg.go | 10 +- rpc/dynamicdiscover.pb.go | 202 ++++++++++++++++-------------------- rpc/dynamicdiscover.proto | 11 +- rpc/server.go | 2 +- 6 files changed, 211 insertions(+), 171 deletions(-) diff --git a/cluster/cluster.go b/cluster/cluster.go index 7a91bae..e502961 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -27,6 +27,7 @@ type NodeInfo struct { ServiceList []string //所有的服务列表 PublicServiceList []string //对外公开的服务列表 DiscoveryService []string //筛选发现的服务,如果不配置,不进行筛选 + NeighborService []string status NodeStatus } @@ -37,8 +38,8 @@ type NodeRpcInfo struct { var cluster Cluster type Cluster struct { - localNodeInfo NodeInfo //本结点配置信息 - discoveryNodeList []NodeInfo //配置发现Master结点 + localNodeInfo NodeInfo //本结点配置信息 + masterDiscoveryNodeList []NodeInfo //配置发现Master结点 localServiceCfg map[string]interface{} //map[serviceName]配置数据* mapRpc map[int] NodeRpcInfo //nodeId @@ -84,6 +85,10 @@ func (cls *Cluster) DiscardNode(nodeId int){ } func (cls *Cluster) DelNode(nodeId int,immediately bool){ + //不删除 + if cls.GetMasterDiscoveryNodeInfo(nodeId)!=nil || nodeId == cls.localNodeInfo.NodeId { + return + } cls.locker.Lock() nodeInfo,ok := cls.mapIdNode[nodeId] if ok == false { @@ -104,6 +109,7 @@ func (cls *Cluster) DelNode(nodeId int,immediately bool){ nodeInfo.status = Discard rpc.client.Unlock() cls.locker.Unlock() + log.Release("Discard node %d %s",nodeInfo.NodeId,nodeInfo.ListenAddr) return } rpc.client.Unlock() @@ -120,6 +126,8 @@ func (cls *Cluster) DelNode(nodeId int,immediately bool){ if ok == true { rpc.client.Close(false) } + + log.Release("remove node %d %s",nodeInfo.NodeId,nodeInfo.ListenAddr) } func (cls *Cluster) serviceDiscoveryDelNode (nodeId int,immediately bool){ @@ -175,7 +183,8 @@ func (cls *Cluster) serviceDiscoverySetNodeInfo (nodeInfo *NodeInfo){ } cls.mapIdNode[nodeInfo.NodeId] = *nodeInfo - log.Debug("Discovery nodeId: %d discovery service:%+v",nodeInfo.NodeId,nodeInfo.PublicServiceList) + log.Release("Discovery nodeId: %d services:%+v",nodeInfo.NodeId,nodeInfo.PublicServiceList) + //已经存在连接,则不需要进行设置 if _,rpcInfoOK := cls.mapRpc[nodeInfo.NodeId];rpcInfoOK == true { return @@ -226,7 +235,7 @@ func (cls *Cluster) checkDynamicDiscovery(localNodeId int) (bool,bool){ var hasMaster bool //是否配置Master服务 //遍历所有结点 - for _,nodeInfo := range cls.discoveryNodeList{ + for _,nodeInfo := range cls.masterDiscoveryNodeList{ if nodeInfo.NodeId == localNodeId { localMaster = true } @@ -237,8 +246,12 @@ func (cls *Cluster) checkDynamicDiscovery(localNodeId int) (bool,bool){ return localMaster,hasMaster } -func (cls *Cluster) appendService(serviceName string){ +func (cls *Cluster) appendService(serviceName string,bPublicService bool){ cls.localNodeInfo.ServiceList = append(cls.localNodeInfo.ServiceList,serviceName) + if bPublicService { + cls.localNodeInfo.PublicServiceList = append(cls.localNodeInfo.PublicServiceList,serviceName) + } + if _,ok:=cls.mapServiceNode[serviceName];ok==false { cls.mapServiceNode[serviceName] = map[int]struct{}{} } @@ -246,7 +259,17 @@ func (cls *Cluster) appendService(serviceName string){ } func (cls *Cluster) GetDiscoveryNodeList() []NodeInfo{ - return cls.discoveryNodeList + return cls.masterDiscoveryNodeList +} + +func (cls *Cluster) GetMasterDiscoveryNodeInfo(nodeId int) *NodeInfo{ + for i:=0;i 0 { + willDelNodeId = append(willDelNodeId, int(req.DelNodeId)) + } + + //删除不必要的结点 + for _, nodeId := range willDelNodeId { + dc.funDelService(nodeId, false) + } + } + + for _, nodeInfo := range req.NodeInfo { + //不对本地结点或者不存在任何公开服务的结点 + if int(nodeInfo.NodeId) == dc.localNodeId { + continue + } + + //遍历所有的公开服务,并筛选之 + for _, serviceName := range nodeInfo.PublicServiceList { + //只有存在配置时才做筛选 + if len(mapMasterDiscoveryService)>0 { + if _, ok := mapMasterDiscoveryService[serviceName]; ok == false { + continue } } - }) + + nInfo := mapNodeInfo[nodeInfo.NodeId] + if nInfo == nil { + nInfo = &rpc.NodeInfo{} + nInfo.NodeId = nodeInfo.NodeId + nInfo.NodeName = nodeInfo.NodeName + nInfo.ListenAddr = nodeInfo.ListenAddr + mapNodeInfo[nodeInfo.NodeId] = nInfo + } + + nInfo.PublicServiceList = append(nInfo.PublicServiceList, serviceName) + } } - //忽略本地结点 - if req.DelNodeId != int32(dc.localNodeId) && req.DelNodeId>0 { - willDelNodeId = append(willDelNodeId, int(req.DelNodeId)) - } - - //删除不必要的结点 - for _,nodeId := range willDelNodeId { - dc.funDelService(nodeId,false) - } - - //发现新结点 - for _, nodeInfo := range req.NodeInfo { + //设置新结点 + for _, nodeInfo := range mapNodeInfo { dc.setNodeInfo(nodeInfo) } @@ -186,8 +227,8 @@ func (dc *DynamicDiscoveryClient) RPC_SubServiceDiscover(req *rpc.SubscribeDisco } func (dc *DynamicDiscoveryClient) isDiscoverNode(nodeId int) bool{ - for i:=0;i< len(cluster.discoveryNodeList);i++{ - if cluster.discoveryNodeList[i].NodeId == nodeId { + for i:=0;i< len(cluster.masterDiscoveryNodeList);i++{ + if cluster.masterDiscoveryNodeList[i].NodeId == nodeId { return true } } @@ -196,7 +237,8 @@ func (dc *DynamicDiscoveryClient) isDiscoverNode(nodeId int) bool{ } func (dc *DynamicDiscoveryClient) OnNodeConnected(nodeId int) { - if dc.isDiscoverNode(nodeId) == false { + nodeInfo := cluster.GetMasterDiscoveryNodeInfo(nodeId) + if nodeInfo == nil { return } @@ -205,12 +247,14 @@ func (dc *DynamicDiscoveryClient) OnNodeConnected(nodeId int) { req.NodeInfo.NodeId = int32(cluster.localNodeInfo.NodeId) req.NodeInfo.NodeName = cluster.localNodeInfo.NodeName req.NodeInfo.ListenAddr = cluster.localNodeInfo.ListenAddr - req.NodeInfo.PublicServiceList = cluster.localNodeInfo.PublicServiceList + //DiscoveryNode配置中没有配置NeighborService,则同步当前结点所有服务 + if len(nodeInfo.NeighborService)==0{ + req.NodeInfo.PublicServiceList = cluster.localNodeInfo.PublicServiceList + } - //如果是连接发现主服成功,则同步服务信息 - err := dc.AsyncCallNode(nodeId, DynamicDiscoveryMasterNameRpcMethod, &req, func(res *rpc.ServiceDiscoverRes, err error) { + //向Master服务同步本Node服务信息 + err := dc.AsyncCallNode(nodeId, DynamicDiscoveryMasterNameRpcMethod, &req, func(res *rpc.Empty, err error) { if err != nil { - cluster.DelNode(nodeId,true) log.Error("call %s is fail :%s", DynamicDiscoveryMasterNameRpcMethod, err.Error()) return } diff --git a/cluster/parsecfg.go b/cluster/parsecfg.go index 756047c..9cafc13 100644 --- a/cluster/parsecfg.go +++ b/cluster/parsecfg.go @@ -11,7 +11,7 @@ import ( var json = jsoniter.ConfigCompatibleWithStandardLibrary type NodeInfoList struct { - DiscoveryNode []NodeInfo //用于服务发现Node + MasterDiscoveryNode []NodeInfo //用于服务发现Node NodeList []NodeInfo } @@ -65,7 +65,7 @@ func (cls *Cluster) readServiceConfig(filepath string) (map[string]interface{}, func (cls *Cluster) readLocalClusterConfig(nodeId int) ([]NodeInfo,[]NodeInfo,error) { var nodeInfoList []NodeInfo - var discoverNodeList []NodeInfo + var masterDiscoverNodeList []NodeInfo clusterCfgPath :=strings.TrimRight(configDir,"/") +"/cluster" fileInfoList,err := ioutil.ReadDir(clusterCfgPath) if err != nil { @@ -80,7 +80,7 @@ func (cls *Cluster) readLocalClusterConfig(nodeId int) ([]NodeInfo,[]NodeInfo,er if err != nil { return nil,nil,fmt.Errorf("read file path %s is error:%+v" ,filePath,err) } - discoverNodeList = append(discoverNodeList,localNodeInfoList.DiscoveryNode...) + masterDiscoverNodeList = append(masterDiscoverNodeList,localNodeInfoList.MasterDiscoveryNode...) for _,nodeInfo := range localNodeInfoList.NodeList { if nodeInfo.NodeId == nodeId || nodeId == 0 { nodeInfoList = append(nodeInfoList,nodeInfo) @@ -105,7 +105,7 @@ func (cls *Cluster) readLocalClusterConfig(nodeId int) ([]NodeInfo,[]NodeInfo,er } - return discoverNodeList,nodeInfoList,nil + return masterDiscoverNodeList,nodeInfoList,nil } func (cls *Cluster) readLocalService(localNodeId int) error { @@ -193,7 +193,7 @@ func (cls *Cluster) InitCfg(localNodeId int) error{ if cls.checkDiscoveryNodeList(discoveryNode) ==false { return fmt.Errorf("DiscoveryNode config is error!") } - cls.discoveryNodeList = discoveryNode + cls.masterDiscoveryNodeList = discoveryNode //读取本地服务配置 err = cls.readLocalService(localNodeId) diff --git a/rpc/dynamicdiscover.pb.go b/rpc/dynamicdiscover.pb.go index ee8c5fc..b5f6e0a 100644 --- a/rpc/dynamicdiscover.pb.go +++ b/rpc/dynamicdiscover.pb.go @@ -151,9 +151,10 @@ func (m *ServiceDiscoverReq) GetNodeInfo() *NodeInfo { //Master->Client type SubscribeDiscoverNotify struct { - IsFull bool `protobuf:"varint,1,opt,name=IsFull,proto3" json:"IsFull,omitempty"` - DelNodeId int32 `protobuf:"varint,2,opt,name=DelNodeId,proto3" json:"DelNodeId,omitempty"` - NodeInfo []*NodeInfo `protobuf:"bytes,3,rep,name=nodeInfo,proto3" json:"nodeInfo,omitempty"` + MasterNodeId int32 `protobuf:"varint,1,opt,name=MasterNodeId,proto3" json:"MasterNodeId,omitempty"` + IsFull bool `protobuf:"varint,2,opt,name=IsFull,proto3" json:"IsFull,omitempty"` + DelNodeId int32 `protobuf:"varint,3,opt,name=DelNodeId,proto3" json:"DelNodeId,omitempty"` + NodeInfo []*NodeInfo `protobuf:"bytes,4,rep,name=nodeInfo,proto3" json:"nodeInfo,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -192,6 +193,13 @@ func (m *SubscribeDiscoverNotify) XXX_DiscardUnknown() { var xxx_messageInfo_SubscribeDiscoverNotify proto.InternalMessageInfo +func (m *SubscribeDiscoverNotify) GetMasterNodeId() int32 { + if m != nil { + return m.MasterNodeId + } + return 0 +} + func (m *SubscribeDiscoverNotify) GetIsFull() bool { if m != nil { return m.IsFull @@ -214,25 +222,24 @@ func (m *SubscribeDiscoverNotify) GetNodeInfo() []*NodeInfo { } //Master->Client -type ServiceDiscoverRes struct { - NodeInfo []*NodeInfo `protobuf:"bytes,1,rep,name=nodeInfo,proto3" json:"nodeInfo,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` +type Empty struct { + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } -func (m *ServiceDiscoverRes) Reset() { *m = ServiceDiscoverRes{} } -func (m *ServiceDiscoverRes) String() string { return proto.CompactTextString(m) } -func (*ServiceDiscoverRes) ProtoMessage() {} -func (*ServiceDiscoverRes) Descriptor() ([]byte, []int) { +func (m *Empty) Reset() { *m = Empty{} } +func (m *Empty) String() string { return proto.CompactTextString(m) } +func (*Empty) ProtoMessage() {} +func (*Empty) Descriptor() ([]byte, []int) { return fileDescriptor_9bfdd3ec0419520f, []int{3} } -func (m *ServiceDiscoverRes) XXX_Unmarshal(b []byte) error { +func (m *Empty) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *ServiceDiscoverRes) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *Empty) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_ServiceDiscoverRes.Marshal(b, m, deterministic) + return xxx_messageInfo_Empty.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -242,55 +249,49 @@ func (m *ServiceDiscoverRes) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } -func (m *ServiceDiscoverRes) XXX_Merge(src proto.Message) { - xxx_messageInfo_ServiceDiscoverRes.Merge(m, src) +func (m *Empty) XXX_Merge(src proto.Message) { + xxx_messageInfo_Empty.Merge(m, src) } -func (m *ServiceDiscoverRes) XXX_Size() int { +func (m *Empty) XXX_Size() int { return m.Size() } -func (m *ServiceDiscoverRes) XXX_DiscardUnknown() { - xxx_messageInfo_ServiceDiscoverRes.DiscardUnknown(m) +func (m *Empty) XXX_DiscardUnknown() { + xxx_messageInfo_Empty.DiscardUnknown(m) } -var xxx_messageInfo_ServiceDiscoverRes proto.InternalMessageInfo - -func (m *ServiceDiscoverRes) GetNodeInfo() []*NodeInfo { - if m != nil { - return m.NodeInfo - } - return nil -} +var xxx_messageInfo_Empty proto.InternalMessageInfo func init() { proto.RegisterType((*NodeInfo)(nil), "rpc.NodeInfo") proto.RegisterType((*ServiceDiscoverReq)(nil), "rpc.ServiceDiscoverReq") proto.RegisterType((*SubscribeDiscoverNotify)(nil), "rpc.SubscribeDiscoverNotify") - proto.RegisterType((*ServiceDiscoverRes)(nil), "rpc.ServiceDiscoverRes") + proto.RegisterType((*Empty)(nil), "rpc.Empty") } func init() { proto.RegisterFile("rpc/dynamicdiscover.proto", fileDescriptor_9bfdd3ec0419520f) } var fileDescriptor_9bfdd3ec0419520f = []byte{ - // 295 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x91, 0xcd, 0x4a, 0xfc, 0x30, - 0x14, 0xc5, 0xc9, 0xf4, 0xdf, 0xf9, 0xb7, 0x57, 0x5c, 0x18, 0x41, 0xa3, 0x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 0xa2, 0xcd, 0x6b, 0xa6, 0x65, 0x3e, 0x48, 0xa4, 0xaa, 0x91, 0xcb, 0xf5, 0x26, - 0xf7, 0xac, 0xbe, 0x6b, 0x8b, 0xc2, 0x68, 0x78, 0xd4, 0x12, 0x3e, 0x03, 0x7f, 0x2a, 0x0a, 0xbb, - 0x92, 0x91, 0x59, 0xc9, 0x67, 0xe1, 0xdb, 0x6c, 0x27, 0x74, 0x76, 0xcd, 0xfe, 0xcb, 0x7c, 0xfd, - 0xc3, 0xfc, 0x2e, 0x81, 0xdb, 0xc3, 0x97, 0x3e, 0x40, 0xaf, 0x7d, 0x80, 0xde, 0xfa, 0x00, 0x3d, - 0xb8, 0xc9, 0x44, 0x57, 0x2c, 0x1f, 0x9b, 0x7f, 0xbc, 0x7a, 0x0f, 0x00, 0x00, 0xff, 0xff, 0x9d, - 0x3f, 0x5b, 0x31, 0xe4, 0x01, 0x00, 0x00, + // 305 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x91, 0xd1, 0x4a, 0xc3, 0x30, + 0x18, 0x85, 0x89, 0x5d, 0xb7, 0xee, 0x57, 0x2f, 0x8c, 0xa0, 0x51, 0xa4, 0x94, 0x5e, 0x55, 0x90, + 0x0e, 0xf4, 0x01, 0x44, 0x99, 0xc2, 0x40, 0xc7, 0xc8, 0xee, 0xbc, 0x6b, 0x93, 0x0c, 0x02, 0x5d, + 0x13, 0xd3, 0x6c, 0xb0, 0x97, 0xf1, 0xd2, 0x67, 0xf1, 0xd2, 0x47, 0x90, 0x3d, 0x89, 0x2c, 0x66, + 0x73, 0x43, 0xf0, 0x2e, 0xdf, 0x7f, 0x72, 0xc2, 0x39, 0x7f, 0xe0, 0xcc, 0x68, 0xd6, 0xe3, 0x8b, + 0xba, 0x98, 0x4a, 0xc6, 0x65, 0xc3, 0xd4, 0x5c, 0x98, 0x5c, 0x1b, 0x65, 0x15, 0x0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0x32, 0x46, 0x5f, 0xcb, 0x18, 0xbd, 0x84, 0x79, 0xcf, 0x68, 0x56, 0xb6, + 0xdd, 0xa7, 0xdd, 0x7c, 0x07, 0x00, 0x00, 0xff, 0xff, 0xa7, 0x79, 0x82, 0x2a, 0xd1, 0x01, 0x00, + 0x00, } func (m *NodeInfo) Marshal() (dAtA []byte, err error) { @@ -432,13 +433,13 @@ func (m *SubscribeDiscoverNotify) MarshalToSizedBuffer(dAtA []byte) (int, error) i = encodeVarintDynamicdiscover(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 } } if m.DelNodeId != 0 { i = encodeVarintDynamicdiscover(dAtA, i, uint64(m.DelNodeId)) i-- - dAtA[i] = 0x10 + dAtA[i] = 0x18 } if m.IsFull { i-- @@ -448,12 +449,17 @@ func (m *SubscribeDiscoverNotify) MarshalToSizedBuffer(dAtA []byte) (int, error) dAtA[i] = 0 } i-- + dAtA[i] = 0x10 + } + if m.MasterNodeId != 0 { + i = encodeVarintDynamicdiscover(dAtA, i, uint64(m.MasterNodeId)) + i-- dAtA[i] = 0x8 } return len(dAtA) - i, nil } -func (m *ServiceDiscoverRes) Marshal() (dAtA []byte, err error) { +func (m *Empty) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -463,12 +469,12 @@ func (m *ServiceDiscoverRes) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *ServiceDiscoverRes) MarshalTo(dAtA []byte) (int, error) { +func (m *Empty) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *ServiceDiscoverRes) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *Empty) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -477,20 +483,6 @@ func (m *ServiceDiscoverRes) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= len(m.XXX_unrecognized) copy(dAtA[i:], m.XXX_unrecognized) } - if len(m.NodeInfo) > 0 { - for iNdEx := len(m.NodeInfo) - 1; iNdEx >= 0; iNdEx-- { - { - size, err := m.NodeInfo[iNdEx].MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintDynamicdiscover(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - } - } return len(dAtA) - i, nil } @@ -559,6 +551,9 @@ func (m *SubscribeDiscoverNotify) Size() (n int) { } var l int _ = l + if m.MasterNodeId != 0 { + n += 1 + sovDynamicdiscover(uint64(m.MasterNodeId)) + } if m.IsFull { n += 2 } @@ -577,18 +572,12 @@ func (m *SubscribeDiscoverNotify) Size() (n int) { return n } -func (m *ServiceDiscoverRes) Size() (n int) { +func (m *Empty) Size() (n int) { if m == nil { return 0 } var l int _ = l - if len(m.NodeInfo) > 0 { - for _, e := range m.NodeInfo { - l = e.Size() - n += 1 + l + sovDynamicdiscover(uint64(l)) - } - } if m.XXX_unrecognized != nil { n += len(m.XXX_unrecognized) } @@ -910,6 +899,25 @@ func (m *SubscribeDiscoverNotify) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MasterNodeId", wireType) + } + m.MasterNodeId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowDynamicdiscover + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MasterNodeId |= int32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field IsFull", wireType) } @@ -929,7 +937,7 @@ func (m *SubscribeDiscoverNotify) Unmarshal(dAtA []byte) error { } } m.IsFull = bool(v != 0) - case 2: + case 3: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field DelNodeId", wireType) } @@ -948,7 +956,7 @@ func (m *SubscribeDiscoverNotify) Unmarshal(dAtA []byte) error { break } } - case 3: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field NodeInfo", wireType) } @@ -1007,7 +1015,7 @@ func (m *SubscribeDiscoverNotify) Unmarshal(dAtA []byte) error { } return nil } -func (m *ServiceDiscoverRes) Unmarshal(dAtA []byte) error { +func (m *Empty) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1030,46 +1038,12 @@ func (m *ServiceDiscoverRes) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: ServiceDiscoverRes: wiretype end group for non-group") + return fmt.Errorf("proto: Empty: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: ServiceDiscoverRes: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: Empty: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NodeInfo", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDynamicdiscover - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthDynamicdiscover - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthDynamicdiscover - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.NodeInfo = append(m.NodeInfo, &NodeInfo{}) - if err := m.NodeInfo[len(m.NodeInfo)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipDynamicdiscover(dAtA[iNdEx:]) diff --git a/rpc/dynamicdiscover.proto b/rpc/dynamicdiscover.proto index a8bd01e..f5a80c9 100644 --- a/rpc/dynamicdiscover.proto +++ b/rpc/dynamicdiscover.proto @@ -17,13 +17,12 @@ message ServiceDiscoverReq{ //Master->Client message SubscribeDiscoverNotify{ - bool IsFull = 1; - int32 DelNodeId = 2; - repeated NodeInfo nodeInfo = 3; + int32 MasterNodeId = 1; + bool IsFull = 2; + int32 DelNodeId = 3; + repeated NodeInfo nodeInfo = 4; } - //Master->Client -message ServiceDiscoverRes{ - repeated NodeInfo nodeInfo = 1; +message Empty{ } \ No newline at end of file diff --git a/rpc/server.go b/rpc/server.go index cb0904b..bc32eda 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -112,7 +112,7 @@ func (agent *RpcAgent) Run() { for { data,err := agent.conn.ReadMsg() if err != nil { - log.Error("read message: %v,remoteAddress:%s", err,agent.conn.RemoteAddr().String()) + log.Error("remoteAddress:%s,read message: %v,",agent.conn.RemoteAddr().String(),err) //will close tcpconn break }