chore(emqx_retainer): avoid race condition
This commit is contained in:
parent
70625b1942
commit
1f238f4c26
|
@ -205,14 +205,18 @@ store_retained(Msg = #message{topic = Topic, payload = Payload}, Env) ->
|
||||||
msg = Msg,
|
msg = Msg,
|
||||||
expiry_time = get_expiry_time(Msg, Env)});
|
expiry_time = get_expiry_time(Msg, Env)});
|
||||||
{true, false} ->
|
{true, false} ->
|
||||||
case mnesia:dirty_read(?TAB, Topic) of
|
{atomic, _} = mnesia:transaction(
|
||||||
[_] ->
|
fun() ->
|
||||||
mnesia:dirty_write(?TAB, #retained{topic = topic2tokens(Topic),
|
case mnesia:read(?TAB, Topic) of
|
||||||
msg = Msg,
|
[_] ->
|
||||||
expiry_time = get_expiry_time(Msg, Env)});
|
mnesia:write(?TAB, #retained{topic = topic2tokens(Topic),
|
||||||
[] ->
|
msg = Msg,
|
||||||
?LOG(error, "Cannot retain message(topic=~s) for table is full!", [Topic])
|
expiry_time = get_expiry_time(Msg, Env)}, write);
|
||||||
end;
|
[] ->
|
||||||
|
?LOG(error, "Cannot retain message(topic=~s) for table is full!", [Topic])
|
||||||
|
end
|
||||||
|
end),
|
||||||
|
ok;
|
||||||
{true, _} ->
|
{true, _} ->
|
||||||
?LOG(error, "Cannot retain message(topic=~s) for table is full!", [Topic]);
|
?LOG(error, "Cannot retain message(topic=~s) for table is full!", [Topic]);
|
||||||
{_, true} ->
|
{_, true} ->
|
||||||
|
|
Loading…
Reference in New Issue