Skip to content

Commit

Permalink
Retry cleaning 100 times
Browse files Browse the repository at this point in the history
Run cleaning anyway if failed to get a lock
  • Loading branch information
arcusfelis committed Mar 11, 2024
1 parent 79d301a commit 0c5cdae
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/mongoose_cleaner.erl
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,27 @@ code_change(_OldVsn, State, _Extra) ->
%%%===================================================================

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

cleanup_modules(Node, 0) ->
?LOG_ERROR(#{what => cleaning_without_lock,

Check warning on line 79 in src/mongoose_cleaner.erl

View check run for this annotation

Codecov / codecov/patch

src/mongoose_cleaner.erl#L79

Added line #L79 was not covered by tests
text => <<"mongoose_cleaner failed to get lock for the node, perform cleaning anyway">>,
remote_node => Node}),
run_node_cleanup(Node),
ok;

Check warning on line 83 in src/mongoose_cleaner.erl

View check run for this annotation

Codecov / codecov/patch

src/mongoose_cleaner.erl#L81-L83

Added lines #L81 - L83 were not covered by tests
cleanup_modules(Node, Retries) ->
LockKey = ?NODE_CLEANUP_LOCK(Node),
LockRequest = {LockKey, self()},
C = fun () -> run_node_cleanup(Node) end,
Nodes = [node() | nodes()],
Retries = 1,
case global:trans(LockRequest, C, Nodes, Retries) of
case global:trans(LockRequest, C, Nodes, 1) of
aborted ->
?LOG_ERROR(#{what => cleaner_trans_aborted,

Check warning on line 91 in src/mongoose_cleaner.erl

View check run for this annotation

Codecov / codecov/patch

src/mongoose_cleaner.erl#L91

Added line #L91 was not covered by tests
text => <<"mongoose_cleaner failed to get global lock">>,
lock_key => LockKey}),
remote_node => Node, lock_key => LockKey, retries => Retries}),

Check warning on line 93 in src/mongoose_cleaner.erl

View check run for this annotation

Codecov / codecov/patch

src/mongoose_cleaner.erl#L93

Added line #L93 was not covered by tests
%% Wait and retry
timer:sleep(rand:uniform(1000)),
cleanup_modules(Node);
cleanup_modules(Node, Retries - 1);

Check warning on line 96 in src/mongoose_cleaner.erl

View check run for this annotation

Codecov / codecov/patch

src/mongoose_cleaner.erl#L95-L96

Added lines #L95 - L96 were not covered by tests
Result ->
{ok, Result}
end.
Expand Down

0 comments on commit 0c5cdae

Please sign in to comment.