Skip to content

Commit

Permalink
storage: Fixes for leo-project#713
Browse files Browse the repository at this point in the history
  • Loading branch information
mocchira committed Apr 20, 2017
1 parent 4f3115e commit 67c8427
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions apps/leo_storage/src/leo_storage_replicator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
is_reply = false ::boolean()
}).

-define(LEO_STORAGE_REPLICATOR_MSG_TAG, 'leo_storage_replicator').

%%--------------------------------------------------------------------
%% API
Expand Down Expand Up @@ -108,7 +109,8 @@ replicate_1([], Ref,_From, #state{method = Method,
key = Key,
callback = Callback}) ->
receive
{Ref, Reply} ->
%% Receive only messages sent from SubParent (_From in this context)
{?LEO_STORAGE_REPLICATOR_MSG_TAG, Ref, Reply} ->
Callback(Reply)
after
(?DEF_REQ_TIMEOUT + timer:seconds(1)) ->
Expand Down Expand Up @@ -149,6 +151,7 @@ replicate_1([#redundant_node{node = Node,
%% for unavailable node
replicate_1([#redundant_node{node = Node,
available = false}|Rest], Ref, From, State) ->
%% This message is sent to SubParent
erlang:send(From, {Ref, {error, {Node, nodedown}}}),
replicate_1(Rest, Ref, From, State).

Expand All @@ -158,10 +161,12 @@ replicate_1([#redundant_node{node = Node,
loop(0, 0,_ResL,_Ref,_From, #state{is_reply = true}) ->
ok;
loop(0, 0, ResL, Ref, From, #state{method = Method}) ->
erlang:send(From, {Ref, {ok, Method, hd(ResL)}});
%% This message is sent to Parent so need to add a tag
erlang:send(From, {?LEO_STORAGE_REPLICATOR_MSG_TAG, Ref, {ok, Method, hd(ResL)}});
loop(_, W,_ResL, Ref, From, #state{num_of_nodes = N,
errors = E}) when (N - W) < length(E) ->
erlang:send(From, {Ref, {error, E}});
%% This message is sent to Parent so need to add a tag
erlang:send(From, {?LEO_STORAGE_REPLICATOR_MSG_TAG, Ref, {error, E}});
loop(N, W, ResL, Ref, From, #state{method = Method,
addr_id = AddrId,
key = Key,
Expand All @@ -174,7 +179,8 @@ loop(N, W, ResL, Ref, From, #state{method = Method,
{W_1, State_1} =
case ((W - 1) < 1) of
true when IsReply == false ->
erlang:send(From, {Ref, {ok, Method, hd(ResL_1)}}),
%% This message is sent to Parent so need to add a tag
erlang:send(From, {?LEO_STORAGE_REPLICATOR_MSG_TAG, Ref, {ok, Method, hd(ResL_1)}}),
{0, State#state{is_reply = true}};
true ->
{0, State};
Expand All @@ -186,7 +192,8 @@ loop(N, W, ResL, Ref, From, #state{method = Method,
{W_1, State_1} =
case ((W - 1) < 1) of
true when IsReply == false ->
erlang:send(From, {Ref, {ok, Method, 0}}),
%% This message is sent to Parent so need to add a tag
erlang:send(From, {?LEO_STORAGE_REPLICATOR_MSG_TAG, Ref, {ok, Method, 0}}),
{0, State#state{is_reply = true}};
true ->
{0, State};
Expand Down Expand Up @@ -238,6 +245,7 @@ replicate_fun(Ref, #req_params{pid = Pid,
{req_id, ReqId}, {cause, Cause}]),
{Ref, {error, {node(), Cause}}}
end,
%% This message is sent to SubParent
erlang:send(Pid, Ret).


Expand Down

0 comments on commit 67c8427

Please sign in to comment.