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 }