cabol / shards

Partitioned ETS tables for Erlang and Elixir

Home Page:https://hexdocs.pm/shards

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix `shards_dist` and `shards` specs to consider the case when `rpc` returns `{badrpc, Reason}`

cabol opened this issue · comments

Currently, the module shards_dist uses rpc to run distributed calls, and in the specs the case whet rpc returns {badrpc, Reason} is not being considered.

I see two ways to handle this:

  1. Just fix the specs considering this case (specs have to be fixed not only in shards_dist but also in shards, since it is a wrapper on top of it). In this case we can create a type like:
-type rpc_res(R) :: R | {badrpc, Reason :: term()}

And re use it from the the specs, like so:

-spec update_counter(
        Tab      :: atom(),
        Key      :: term(),
        UpdateOp :: term(),
        State    :: shards_state:state()
      ) -> rpc_res(integer() | [integer()]).
  1. Handle the {badrpc, Reason} internally and raise an exception with the corresponding error.
%% @private
rpc_call(Node, Module, Function, Args) ->
  handle_rpc_res(rpc:call(Node, Module, Function, Args)).

%% @private
handle_rpc_res({badrpc, {'EXIT', {Reason, _}}}) ->
  error(Reason);
handle_rpc_res(Res) ->
  Res.

And reuse the private function rpc_call/4 internally.

Evaluate both alternatives and come up with the best approach.

In my opinion, I rather receive the {:bad_rpc, error} so I can pattern match against it and handle the different outcomes, such as the example I referenced in #42.
So I vote for solution 1.

Let's go for option one then!!

I'll close this issue since it doesn't apply anymore, with shards v1 the distributed module shards_dist will be in a separate repo, so by the time there is a first implementation ready, we will keep this in mind.