feat: more straightforward log for force_shutdown reason

This commit is contained in:
Zhongwen Deng 2023-04-10 10:07:58 +08:00
parent e186477531
commit c68909767a
3 changed files with 15 additions and 10 deletions

View File

@ -246,7 +246,7 @@ do_check_oom([]) ->
ok; ok;
do_check_oom([{Val, Max, Reason} | Rest]) -> do_check_oom([{Val, Max, Reason} | Rest]) ->
case is_integer(Max) andalso (0 < Max) andalso (Max < Val) of case is_integer(Max) andalso (0 < Max) andalso (Max < Val) of
true -> {shutdown, Reason}; true -> {shutdown, #{reason => Reason, value => Val, max => Max}};
false -> do_check_oom(Rest) false -> do_check_oom(Rest)
end. end.

View File

@ -2642,20 +2642,22 @@ to_atom(Str) when is_list(Str) ->
to_atom(Bin) when is_binary(Bin) -> to_atom(Bin) when is_binary(Bin) ->
binary_to_atom(Bin, utf8). binary_to_atom(Bin, utf8).
validate_heap_size(Siz) -> validate_heap_size(Siz) when is_integer(Siz) ->
MaxSiz = MaxSiz =
case erlang:system_info(wordsize) of case erlang:system_info(wordsize) of
% arch_64 % arch_64
8 -> 8 -> (1 bsl 59) - 1;
(1 bsl 59) - 1;
% arch_32 % arch_32
4 -> 4 -> (1 bsl 27) - 1
(1 bsl 27) - 1
end, end,
case Siz > MaxSiz of case Siz > MaxSiz of
true -> error(io_lib:format("force_shutdown_policy: heap-size ~ts is too large", [Siz])); true ->
false -> ok {error, #{reason => max_heap_size_too_large, maximum => MaxSiz}};
end. false ->
ok
end;
validate_heap_size(_SizStr) ->
{error, invalid_heap_size}.
validate_alarm_actions(Actions) -> validate_alarm_actions(Actions) ->
UnSupported = lists:filter( UnSupported = lists:filter(

View File

@ -146,7 +146,10 @@ t_check(_) ->
[self() ! {msg, I} || I <- lists:seq(1, 5)], [self() ! {msg, I} || I <- lists:seq(1, 5)],
?assertEqual(ok, emqx_misc:check_oom(Policy)), ?assertEqual(ok, emqx_misc:check_oom(Policy)),
[self() ! {msg, I} || I <- lists:seq(1, 6)], [self() ! {msg, I} || I <- lists:seq(1, 6)],
?assertEqual({shutdown, message_queue_too_long}, emqx_misc:check_oom(Policy)). ?assertEqual(
{shutdown, #{reason => message_queue_too_long, value => 11, max => 10}},
emqx_misc:check_oom(Policy)
).
drain() -> drain() ->
drain([]). drain([]).