From 671159cc879be66e09ddc8eff6d0a1f8492bdea5 Mon Sep 17 00:00:00 2001 From: boyce Date: Wed, 20 Mar 2019 13:39:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=9B=86=E7=BE=A4=E7=BB=93?= =?UTF-8?q?=E7=82=B9=E9=85=8D=E7=BD=AE=E8=87=AA=E5=B7=B1=E8=BA=AB=E7=9A=84?= =?UTF-8?q?=E7=BB=93=E7=82=B9=E5=90=8D=E7=A7=B0=EF=BC=8C=E5=AF=BC=E8=87=B4?= =?UTF-8?q?rpc=20call=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cluster/cluster.go | 4 ++-- cluster/config.go | 15 ++++++++++++++- rpc/server.go | 12 ++++++------ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/cluster/cluster.go b/cluster/cluster.go index 4bc6520..5998648 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -221,8 +221,8 @@ func (slf *CCluster) Call(NodeServiceMethod string, args interface{}, reply inte var callServiceName string nodeidList := slf.GetNodeList(NodeServiceMethod, &callServiceName) if len(nodeidList) > 1 || len(nodeidList) < 1 { - service.GetLogger().Printf(sysmodule.LEVER_ERROR, "CCluster.Call(%s) not find nodes.", NodeServiceMethod) - return fmt.Errorf("CCluster.Call(%s) not find nodes.", NodeServiceMethod) + service.GetLogger().Printf(sysmodule.LEVER_ERROR, "CCluster.Call(%s) find nodes count %d is error.", NodeServiceMethod, len(nodeidList)) + return fmt.Errorf("CCluster.Call(%s) find nodes count %d is error.", NodeServiceMethod, len(nodeidList)) } nodeid := nodeidList[0] diff --git a/cluster/config.go b/cluster/config.go index 3aad6d0..1758c88 100644 --- a/cluster/config.go +++ b/cluster/config.go @@ -81,7 +81,10 @@ func ReadCfg(path string, nodeid int) (*ClusterConfig, error) { for _, cn := range custerNodeName { for _, n := range c.mapIdNode { if n.NodeName == cn { - c.mapClusterNodeService[n.NodeName] = append(c.mapClusterNodeService[n.NodeName], n) + nodeList := c.mapClusterNodeService[n.NodeName] + if IsExistsNode(nodeList, &n) == false { + c.mapClusterNodeService[n.NodeName] = append(c.mapClusterNodeService[n.NodeName], n) + } } } } @@ -143,3 +146,13 @@ func (slf *ClusterConfig) HasLocalService(serviceName string) bool { _, ok := slf.currentNode.ServiceList[serviceName] return ok == true } + +func IsExistsNode(nodelist []CNode, pNode *CNode) bool { + for _, node := range nodelist { + if node.NodeID == pNode.NodeID { + return true + } + } + + return false +} diff --git a/rpc/server.go b/rpc/server.go index a7530d5..a182090 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -312,7 +312,7 @@ func suitableMethods(prefix string, typ reflect.Type, reportErr bool) map[string // Method needs three ins: receiver, *args, *reply. if mtype.NumIn() != 3 { if reportErr { - //log.Printf("rpc.Register: method %q has %d input parameters; needs exactly three\n", mname, mtype.NumIn()) + log.Printf("rpc.Register: method %q has %d input parameters; needs exactly three\n", mname, mtype.NumIn()) } continue } @@ -320,7 +320,7 @@ func suitableMethods(prefix string, typ reflect.Type, reportErr bool) map[string argType := mtype.In(1) if !isExportedOrBuiltinType(argType) { if reportErr { - //log.Printf("rpc.Register: argument type of method %q is not exported: %q\n", mname, argType) + log.Printf("rpc.Register: argument type of method %q is not exported: %q\n", mname, argType) } continue } @@ -328,28 +328,28 @@ func suitableMethods(prefix string, typ reflect.Type, reportErr bool) map[string replyType := mtype.In(2) if replyType.Kind() != reflect.Ptr { if reportErr { - //log.Printf("rpc.Register: reply type of method %q is not a pointer: %q\n", mname, replyType) + log.Printf("rpc.Register: reply type of method %q is not a pointer: %q\n", mname, replyType) } continue } // Reply type must be exported. if !isExportedOrBuiltinType(replyType) { if reportErr { - //log.Printf("rpc.Register: reply type of method %q is not exported: %q\n", mname, replyType) + log.Printf("rpc.Register: reply type of method %q is not exported: %q\n", mname, replyType) } continue } // Method needs one out. if mtype.NumOut() != 1 { if reportErr { - //log.Printf("rpc.Register: method %q has %d output parameters; needs exactly one\n", mname, mtype.NumOut()) + log.Printf("rpc.Register: method %q has %d output parameters; needs exactly one\n", mname, mtype.NumOut()) } continue } // The return type of the method must be error. if returnType := mtype.Out(0); returnType != typeOfError { if reportErr { - //log.Printf("rpc.Register: return type of method %q is %q, must be error\n", mname, returnType) + log.Printf("rpc.Register: return type of method %q is %q, must be error\n", mname, returnType) } continue }