修改集群结点配置自己身的结点名称,导致rpc call失败

This commit is contained in:
boyce
2019-03-20 13:39:42 +08:00
parent ffe2e967f8
commit 671159cc87
3 changed files with 22 additions and 9 deletions

View File

@@ -221,8 +221,8 @@ func (slf *CCluster) Call(NodeServiceMethod string, args interface{}, reply inte
var callServiceName string var callServiceName string
nodeidList := slf.GetNodeList(NodeServiceMethod, &callServiceName) nodeidList := slf.GetNodeList(NodeServiceMethod, &callServiceName)
if len(nodeidList) > 1 || len(nodeidList) < 1 { if len(nodeidList) > 1 || len(nodeidList) < 1 {
service.GetLogger().Printf(sysmodule.LEVER_ERROR, "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) not find nodes.", NodeServiceMethod) return fmt.Errorf("CCluster.Call(%s) find nodes count %d is error.", NodeServiceMethod, len(nodeidList))
} }
nodeid := nodeidList[0] nodeid := nodeidList[0]

View File

@@ -81,7 +81,10 @@ func ReadCfg(path string, nodeid int) (*ClusterConfig, error) {
for _, cn := range custerNodeName { for _, cn := range custerNodeName {
for _, n := range c.mapIdNode { for _, n := range c.mapIdNode {
if n.NodeName == cn { 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] _, ok := slf.currentNode.ServiceList[serviceName]
return ok == true return ok == true
} }
func IsExistsNode(nodelist []CNode, pNode *CNode) bool {
for _, node := range nodelist {
if node.NodeID == pNode.NodeID {
return true
}
}
return false
}

View File

@@ -312,7 +312,7 @@ func suitableMethods(prefix string, typ reflect.Type, reportErr bool) map[string
// Method needs three ins: receiver, *args, *reply. // Method needs three ins: receiver, *args, *reply.
if mtype.NumIn() != 3 { if mtype.NumIn() != 3 {
if reportErr { 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 continue
} }
@@ -320,7 +320,7 @@ func suitableMethods(prefix string, typ reflect.Type, reportErr bool) map[string
argType := mtype.In(1) argType := mtype.In(1)
if !isExportedOrBuiltinType(argType) { if !isExportedOrBuiltinType(argType) {
if reportErr { 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 continue
} }
@@ -328,28 +328,28 @@ func suitableMethods(prefix string, typ reflect.Type, reportErr bool) map[string
replyType := mtype.In(2) replyType := mtype.In(2)
if replyType.Kind() != reflect.Ptr { if replyType.Kind() != reflect.Ptr {
if reportErr { 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 continue
} }
// Reply type must be exported. // Reply type must be exported.
if !isExportedOrBuiltinType(replyType) { if !isExportedOrBuiltinType(replyType) {
if reportErr { 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 continue
} }
// Method needs one out. // Method needs one out.
if mtype.NumOut() != 1 { if mtype.NumOut() != 1 {
if reportErr { 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 continue
} }
// The return type of the method must be error. // The return type of the method must be error.
if returnType := mtype.Out(0); returnType != typeOfError { if returnType := mtype.Out(0); returnType != typeOfError {
if reportErr { 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 continue
} }