[erlang-questions] rpc:multicall/5 docs misleading?

Ignas Vyšniauskas baliulia@REDACTED
Wed Feb 27 12:04:31 CET 2013


the docs for `rpc:multicall/5` claim:

> In contrast to an RPC, a multicall is an RPC which is sent concurrently from
> one client to multiple servers. This is useful for collecting some
> information from a set of nodes, or for calling a function on a set of nodes
> to achieve some side effects. It is *semantically the same as iteratively
> making a series of RPCs on all the nodes* <..>

So, I would expect that, since this works:

    get_results(Nodes) ->
        lists:zip(Nodes, [rpc:call(N, erlang, now, []) || N <- Nodes]).

this would also work:

    get_results(Nodes) ->
        {Results, BadNodes} = rpc:multicall(Nodes, erlang, now, []),
        lists:zip(Nodes, Results).

but the `lists:zip/2` will fail if some node is non-reachable during the
multicall since Results will be a shorter list, so in order to really be
semantically the same (assuming `Nodes` does not contain duplicate entries),
you would need:

    get_results(Nodes) ->
        {Results, BadNodes} = rpc:multicall(Nodes, erlang, now, []),
        FullResults = lists:append(
            lists:zip(Nodes -- BadNodes, Results),
            lists:zip(BadNodes, {badrpc, nodedown})
        %% restore original order
        [{N, Res} || N <- Nodes, {M, Res} <- FullResults, N == M].

Which, at least to me, is a bit unexpected given the docs.

I would suggest either clarifying the docs or, better, changing the
so that it becomes more useful. Clearly the returned `BadNodes` are just a
leftover from the response from `gen_server:multicall/4` and IMHO useless in
this case as it provides no information as to what went wrong and only
introduces confusion.


More information about the erlang-questions mailing list