r/mit6824clojure • • Aug 25 '20

Lab code for Raft: Synchronous RPC calls

In the provided lab code, the RPC call function blocks and returns the response. I don't think we should assume that the underlying transport will support correlating responses with requests , nor does Raft make that assumption. For example, Raft would just work on top of UDP. I believe we should tweak the provided code so that we get responses asynchronously. What do you think?

3 Upvotes

3 comments sorted by

2

u/siclait Aug 27 '20

I think that would be inconsistent with the provided Go code. As far as I can tell, the Go "rpc" library's provided Call function is synchronous ( https://golang.org/pkg/net/rpc/#Client.Call ). So far I've tried to maintain parity between the Go and Clojure code. It makes it possible to form cross-language study groups and to refer back to the original class materials.

2

u/ErnestoGarciaGarcia Aug 28 '20 edited Aug 29 '20

It's ok to align with the original Go code. We can modify it in raft.core, like for example:

(defn send-rpc! [{:keys [me peers] :as raft} server service-method args]
  (log me "Sending to" server service-method args)
  (future
    (try
      (let [response (lab-rpc/call! (nth peers server) service-method args)]
        (if (some? response)
          (on-response raft server service-method response)
          (log me "Request timed out" service-method args)))
      (catch Throwable e
        (log me "Error sending" service-method args "\n" e)))))

Thanks for the lab's code, btw!

1

u/siclait Sep 02 '20

That's interesting - I have something like that in my implementation too.

The intent is for raft.core to just contain sample code to get people going. Everyone is free to rewrite any / all the code in that file. Since people are free to add this already, is there still value in adding this function to the default code in raft.core?