Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

concurrent mget bug for non existing keys #11

Merged
merged 1 commit into from Apr 14, 2012

Conversation

Projects
None yet
2 participants

When you are calling mget with many spawned process some of them may not respond due a bug on erldis_client:parse_state/3. This patch resolve the problem.

If you want to reproduce the error try this:

-module(mytest).
-author('gustavo.chain@inakanetworks.com').
-vsn('').

-export([init/0]).
-export([mget/1, mget/3, cc_mget/2]).

-define(LINK, erldis_pool_sup:get_random_pid({"10.211.55.3",6379})).

init() ->
    {ok, Pid} = erldis_pool_sup:start_link([{{"10.211.55.3", 6379}, 1}]),
    Pid.

mget(List) ->
    R = erldis:mget(?LINK, List),
    io:format("~p: ~p\n", [self(), R]),
    R.
mget(List, Pid, N) ->
    try
%       io:format("Calling mget~n"),
        mget(List),
%       io:format("Called mget~n"),
        Pid ! {ok, N}
    catch _:X ->
        {error, X, erlang:get_stacktrace()}
    end.

%cc_mget(List) ->
%   lists:foreach(fun(X) -> spawn(?MODULE, mget, [List, X]) end, lists:seq(1, N)).


cc_mget(0, _) ->
    cc_mget_receive(0);
cc_mget(N, Keys) ->
    spawn(?MODULE, mget, [Keys, self(), N]),
    cc_mget(N - 1, Keys).

cc_mget_receive(N) ->
    receive
        {ok, _} ->
            cc_mget_receive(N + 1)
    after 3000 ->
            io:format("Finish with ~p!~n", [N])
    end.

@cstar cstar added a commit that referenced this pull request Apr 14, 2012

@cstar cstar Merge pull request #11 from gchaincl/master
concurrent mget bug for non existing keys
32d5d84

@cstar cstar merged commit 32d5d84 into cstar:master Apr 14, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment