Skip to content

Commit

Permalink
Remove two layers of retries in cleanup_modules
Browse files Browse the repository at this point in the history
Let global:trans do retries, retry outside transaction anyway
if getting lock is not possible
  • Loading branch information
arcusfelis committed Mar 11, 2024
1 parent 0c5cdae commit fd73bb2
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions src/mongoose_cleaner.erl
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,19 @@ code_change(_OldVsn, State, _Extra) ->
%%%===================================================================

cleanup_modules(Node) ->
cleanup_modules(Node, 100).

cleanup_modules(Node, 0) ->
?LOG_ERROR(#{what => cleaning_without_lock,
text => <<"mongoose_cleaner failed to get lock for the node, perform cleaning anyway">>,
remote_node => Node}),
run_node_cleanup(Node),
ok;
cleanup_modules(Node, Retries) ->
LockKey = ?NODE_CLEANUP_LOCK(Node),
LockRequest = {LockKey, self()},
C = fun () -> run_node_cleanup(Node) end,
Nodes = [node() | nodes()],
case global:trans(LockRequest, C, Nodes, 1) of
Retries = 10,
case global:trans(LockRequest, C, Nodes, Retries) of
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
text => <<"mongoose_cleaner failed to get global lock">>,
text => <<"mongoose_cleaner failed to get the global lock, run cleanup anyway">>,
remote_node => Node, lock_key => LockKey, retries => Retries}),
%% Wait and retry
timer:sleep(rand:uniform(1000)),
cleanup_modules(Node, Retries - 1);
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

0 comments on commit fd73bb2

Please sign in to comment.