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

Dist blocker #4234

Merged
merged 9 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
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
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,"0321fa355d6bfb0f28ff244e34b22deec707dbee"}},
{ref,"0f69ec9eaed6e9567337b845661045d2ce04ad20"}},
0},
{<<"cowboy">>,{pkg,<<"cowboy">>,<<"2.9.0">>},0},
{<<"cowboy_swagger">>,{pkg,<<"cowboy_swagger">>,<<"2.5.1">>},0},
Expand Down
4 changes: 3 additions & 1 deletion src/ejabberd_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).

init([]) ->
DistBlocker = worker_spec(cets_dist_blocker),
Hooks = worker_spec(gen_hook),
Cleaner = worker_spec(mongoose_cleaner),
Router = worker_spec(ejabberd_router),
Expand All @@ -64,7 +65,8 @@ init([]) ->
IQSupervisor =
ejabberd_tmp_sup_spec(ejabberd_iq_sup, [ejabberd_iq_sup, mongoose_iq_worker]),
{ok, {{one_for_one, 10, 1},
[StartIdServer,
[DistBlocker,
StartIdServer,
PG,
Hooks,
Cleaner,
Expand Down
14 changes: 8 additions & 6 deletions src/mongoose_cleaner.erl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
%%%===================================================================

init([]) ->
cets_dist_blocker:add_cleaner(self()),
case net_kernel:monitor_nodes(true) of
ok ->
{ok, #state{}};
Expand All @@ -56,6 +57,7 @@
text => <<"mongoose_cleaner received nodenown event">>,
down_node => Node}),
cleanup_modules(Node),
cets_dist_blocker:cleaning_done(self(), Node),
{noreply, State};
handle_info(_Info, State) ->
{noreply, State}.
Expand All @@ -75,15 +77,15 @@
LockRequest = {LockKey, self()},
C = fun () -> run_node_cleanup(Node) end,
Nodes = [node() | nodes()],
Retries = 1,
Retries = 10,
case global:trans(LockRequest, C, Nodes, Retries) of
aborted ->
?LOG_INFO(#{what => cleaner_trans_aborted,
text => <<"mongoose_cleaner failed to get global lock">>,
lock_key => LockKey}),
{ok, aborted};
?LOG_ERROR(#{what => cleaner_trans_aborted,

Check warning on line 83 in src/mongoose_cleaner.erl

View check run for this annotation

Codecov / codecov/patch

src/mongoose_cleaner.erl#L83

Added line #L83 was not covered by tests
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a warning would be better, as with many nodes IMO this is quite likely to happen, and it doesn't have any immediate bad consequences, like lost data, lack of functionality etc.

text => <<"mongoose_cleaner failed to get the global lock, run cleanup anyway">>,
remote_node => Node, lock_key => LockKey, retries => Retries}),
C();

Check warning on line 86 in src/mongoose_cleaner.erl

View check run for this annotation

Codecov / codecov/patch

src/mongoose_cleaner.erl#L85-L86

Added lines #L85 - L86 were not covered by tests
Result ->
{ok, Result}
Result
end.

run_node_cleanup(Node) ->
Expand Down
13 changes: 9 additions & 4 deletions test/mongoose_cleanup_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ opts() ->
{auth, ?HOST} => config_parser_helper:extra_auth(),
{modules, ?HOST} => #{}}.

meck_mods(bosh) -> [exometer, mod_bosh_socket];
meck_mods(s2s) -> [exometer, mongoose_bin];
meck_mods(component) -> [exometer];
meck_mods(_) -> [exometer, ejabberd_sm, ejabberd_local].
meck_mods(bosh) -> [exometer, mod_bosh_socket, cets_dist_blocker];
meck_mods(s2s) -> [exometer, mongoose_bin, cets_dist_blocker];
meck_mods(component) -> [exometer, cets_dist_blocker];
meck_mods(_) -> [exometer, ejabberd_sm, ejabberd_local, cets_dist_blocker].

%% -----------------------------------------------------
%% Tests
Expand Down Expand Up @@ -306,6 +306,11 @@ setup_meck([mod_bosh_socket | R]) ->
meck:new(mod_bosh_socket, [passthrough]),
meck:expect(mod_bosh_socket, start_supervisor, fun() -> {ok, self()} end),
setup_meck(R);
setup_meck([cets_dist_blocker | R]) ->
meck:new(cets_dist_blocker, [passthrough]),
meck:expect(cets_dist_blocker, add_cleaner, fun(_Pid) -> ok end),
meck:expect(cets_dist_blocker, cleaning_done, fun(_Pid, _Node) -> ok end),
setup_meck(R);
setup_meck([]) ->
ok.

Expand Down