Search code examples
gorpcdistributed-systemconsensusraft

RPC call cannot find method


I'm trying to implement Raft consensus algorithm but for some reason having trouble using RPC calls. I'm using labrpc.go to make calls.

My function signature:

func (rf *Raft) RequestVotes(args RequestVoteArgs, reply *RequestVoteReply) bool

and the call I'm making

if err := rf.peers[peerIdx].Call("Raft.RequestVotes", args, &reply); err == false {

Raft struct:

type Raft struct {
... 
peers     []*labrpc.ClientEnd // RPC end points of all peers
...
}

But I keep getting this error:

labrpc.Service.dispatch(): unknown method RequestVotes in Raft.RequestVotes; expecting one of []

I also have several other Raft. methods, so should the expecting one of [] be non-empty?


Solution

  • The RPC methods weren't being recognized as RPC methods as I was explicitly returning bool. Changing the code to return void (removing the return entirely) fixed the issue.

    Updated function signature:

    func (rf *Raft) RequestVotes(args RequestVoteArgs, reply *RequestVoteReply) {