Skip to content

Commit

Permalink
Use cets:insert_new/2
Browse files Browse the repository at this point in the history
And retry
  • Loading branch information
arcusfelis committed Jul 31, 2023
1 parent 6df515b commit ac50890
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
{cache_tab, "1.0.30"},
{segmented_cache, "0.3.0"},
{worker_pool, "6.0.1"},
{cets, {git, "https://github.com/esl/cets.git", {branch, "main"}}},
{cets, {git, "https://github.com/esl/cets.git", {branch, "mu-insert-new"}}},

%%% HTTP tools
{graphql, {git, "https://github.com/esl/graphql-erlang.git", {branch, "master"}}},
Expand Down
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.9.0">>},1},
{<<"cets">>,
{git,"https://github.com/esl/cets.git",
{ref,"458e2e1df3fb51896fe334385bb0d2c9c53ef87f"}},
{ref,"659e0f666782407db99022a4abf3ea8b4dbb0167"}},
0},
{<<"cowboy">>,{pkg,<<"cowboy">>,<<"2.9.0">>},0},
{<<"cowboy_swagger">>,{pkg,<<"cowboy_swagger">>,<<"2.5.1">>},0},
Expand Down
16 changes: 11 additions & 5 deletions src/muc/mongoose_muc_online_cets.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,23 @@ handle_conflict(_Rec1, Rec2) ->
Room :: mod_muc:room(),
Pid :: pid()) -> ok | {exists, pid()} | {error, term()}.
register_room(HostType, MucHost, Room, Pid) ->
register_room(HostType, MucHost, Room, Pid, 3).

Check warning on line 48 in src/muc/mongoose_muc_online_cets.erl

View check run for this annotation

Codecov / codecov/patch

src/muc/mongoose_muc_online_cets.erl#L48

Added line #L48 was not covered by tests

register_room(_HostType, _MucHost, _Room, _Pid, 0) ->
{error, failed_to_register};

Check warning on line 51 in src/muc/mongoose_muc_online_cets.erl

View check run for this annotation

Codecov / codecov/patch

src/muc/mongoose_muc_online_cets.erl#L51

Added line #L51 was not covered by tests
register_room(HostType, MucHost, Room, Pid, Retries) ->
Tab = table_name(HostType),
Rec = {{MucHost, Room}, Pid},
case find_room_pid(HostType, MucHost, Room) of

Check warning on line 55 in src/muc/mongoose_muc_online_cets.erl

View check run for this annotation

Codecov / codecov/patch

src/muc/mongoose_muc_online_cets.erl#L53-L55

Added lines #L53 - L55 were not covered by tests
%% Race condition is possible
%% TODO use cets:insert_new/2 once available
%% Otherwise cets:insert could overwrite an existing registration
{ok, OtherPid} ->
{exists, OtherPid};

Check warning on line 57 in src/muc/mongoose_muc_online_cets.erl

View check run for this annotation

Codecov / codecov/patch

src/muc/mongoose_muc_online_cets.erl#L57

Added line #L57 was not covered by tests
{error, not_found} ->
cets:insert(Tab, Rec),
ok
case cets:insert_new(Tab, Rec) of

Check warning on line 59 in src/muc/mongoose_muc_online_cets.erl

View check run for this annotation

Codecov / codecov/patch

src/muc/mongoose_muc_online_cets.erl#L59

Added line #L59 was not covered by tests
true ->
ok;

Check warning on line 61 in src/muc/mongoose_muc_online_cets.erl

View check run for this annotation

Codecov / codecov/patch

src/muc/mongoose_muc_online_cets.erl#L61

Added line #L61 was not covered by tests
false ->
register_room(HostType, MucHost, Room, Pid, Retries - 1)

Check warning on line 63 in src/muc/mongoose_muc_online_cets.erl

View check run for this annotation

Codecov / codecov/patch

src/muc/mongoose_muc_online_cets.erl#L63

Added line #L63 was not covered by tests
end
end.

%% Race condition is possible between register and room_destroyed
Expand Down

0 comments on commit ac50890

Please sign in to comment.