RPC 响应不正确
RPC response not correct
我正在尝试使用一个远程过程,该过程将在结构中设置回复,并使用布尔状态和字符串作为下一个输入。
在此过程中,我将布尔状态设置为 true 并将一个值放入输入中。
但是在客户端中,它得到一个错误的状态和空字符串。
在程序中:
func(c *Coordinator)MapJob(req mr.MapRequest, reply *mr.MapResponse) error {
//logic to set up response...
reply = &mr.MapResponse{
Status: newStatus,
Input: newIn,
}
fmt.Printf("[REPLY] %+v\n", reply)
return nil
}
打印[REPLY] &{Status:true Input:1.txt}
在客户端中:
err := client.Call("Coordinator.MapJob", req, &reply)
fmt.Printf("reply from procedure %+v\n", reply)
打印:reply from procedure {Status:false Input:}
我在这里错过了什么?
我把整个代码放在 https://github.com/Brotchu/ProjectMR
该过程在协调器中定义,客户端在工作人员中定义。
可能太多了就不贴在这里了。
客户端结构看起来仅由零值(false
和空字符串)组成。
我认为 client.Call
调用不会改变回复。我认为这是因为 MapJob
也不会改变回复。
reply = &mr.MapResponse{
Status: newStatus,
Input: newIn,
}
应该是
reply.Status = newStatus
reply.Input = newIn
您必须更改通话期间传递的回复值,因此替换
reply = &mr.MapResponse{
Status: newStatus,
Input: newIn,
}
有
*reply = mr.MapResponse{
Status: newStatus,
Input: newIn,
}
我正在尝试使用一个远程过程,该过程将在结构中设置回复,并使用布尔状态和字符串作为下一个输入。 在此过程中,我将布尔状态设置为 true 并将一个值放入输入中。 但是在客户端中,它得到一个错误的状态和空字符串。 在程序中:
func(c *Coordinator)MapJob(req mr.MapRequest, reply *mr.MapResponse) error {
//logic to set up response...
reply = &mr.MapResponse{
Status: newStatus,
Input: newIn,
}
fmt.Printf("[REPLY] %+v\n", reply)
return nil
}
打印[REPLY] &{Status:true Input:1.txt}
在客户端中:
err := client.Call("Coordinator.MapJob", req, &reply)
fmt.Printf("reply from procedure %+v\n", reply)
打印:reply from procedure {Status:false Input:}
我在这里错过了什么? 我把整个代码放在 https://github.com/Brotchu/ProjectMR 该过程在协调器中定义,客户端在工作人员中定义。 可能太多了就不贴在这里了。
客户端结构看起来仅由零值(false
和空字符串)组成。
我认为 client.Call
调用不会改变回复。我认为这是因为 MapJob
也不会改变回复。
reply = &mr.MapResponse{
Status: newStatus,
Input: newIn,
}
应该是
reply.Status = newStatus
reply.Input = newIn
您必须更改通话期间传递的回复值,因此替换
reply = &mr.MapResponse{
Status: newStatus,
Input: newIn,
}
有
*reply = mr.MapResponse{
Status: newStatus,
Input: newIn,
}