Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storage: Make insert_messages not being invoked multiple times #793

Merged
merged 3 commits into from
Jul 26, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions apps/leo_storage/src/leo_storage_handler_del_directory.erl
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ handle_info({failed, MQId, Type, Directory}, State) ->
timestamp = leo_date:now()}),
{noreply, State};

handle_info({enqueuing, MQId, Type, Directory}, State) ->
{ok, State_1} = run(Type, ?STATE_ENQUEUING, MQId, Directory, State),
{noreply, State_1};
%handle_info({enqueuing, MQId, Type, Directory}, State) ->
% {ok, State_1} = run(Type, ?STATE_ENQUEUING, MQId, Directory, State),
% {noreply, State_1};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove 218-220L which is unnecessary.


handle_info({enqueued, MQId, Type, Directory}, State) ->
{ok, State_1} = run(Type, ?STATE_MONITORING, MQId, Directory, State),
Expand Down Expand Up @@ -268,7 +268,7 @@ dequeue(#state{num_of_workers = NumOfWorkers} = State) ->
end, [], DelBucketStateList))),
case List of
[H|_] ->
Ret = dequeue_1(DelBucketStateList, H),
Ret = dequeue_1(State, DelBucketStateList, H),
{Ret, State};
[] ->
{ok, State}
Expand All @@ -281,15 +281,16 @@ dequeue(#state{num_of_workers = NumOfWorkers} = State) ->
end.

%% @private
-spec(dequeue_1(DelBucketStateList, MQId) ->
-spec(dequeue_1(State, DelBucketStateList, MQId) ->
ok |
not_found |
{error, Cause} when DelBucketStateList::[],
{error, Cause} when State::#state{},
DelBucketStateList::[],
MQId::mq_id(),
Cause::any()).
dequeue_1([],_) ->
dequeue_1(_,[],_) ->
not_found;
dequeue_1([{_, DelBucketStateBin}|DelBucketStateList], MQId) ->
dequeue_1(State, [{_, DelBucketStateBin}|DelBucketStateList], MQId) ->
case catch binary_to_term(DelBucketStateBin) of
#del_dir_state{type = Type,
directory = Directory,
Expand All @@ -299,9 +300,15 @@ dequeue_1([{_, DelBucketStateBin}|DelBucketStateList], MQId) ->
fun() ->
insert_messages(From, MQId, Type, Directory)
end),
% receive 'enqueuing' message here to change the state from STATE_PENDING to STATE_ENQUEUING
% for preventing insert_messages from being invoked multiple times.
receive
{enqueuing, MQId, Type, Directory} ->
run(Type, ?STATE_ENQUEUING, MQId, Directory, State)
end,
ok;
#del_dir_state{} ->
dequeue_1(DelBucketStateList, MQId);
dequeue_1(State, DelBucketStateList, MQId);
{_, Cause} ->
?error("dequeue_1/2", [{cause, Cause}]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?error("dequeue_1/3", [{cause, Cause}]), is correct not dequeue_1/2.

{error, Cause}
Expand Down