Explorar o código

feat: more straightforward log for force_shutdown reason

Zhongwen Deng %!s(int64=2) %!d(string=hai) anos
pai
achega
c68909767a

+ 1 - 1
apps/emqx/src/emqx_misc.erl

@@ -246,7 +246,7 @@ do_check_oom([]) ->
     ok;
 do_check_oom([{Val, Max, Reason} | Rest]) ->
     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)
     end.
 

+ 10 - 8
apps/emqx/src/emqx_schema.erl

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

+ 4 - 1
apps/emqx/test/emqx_misc_SUITE.erl

@@ -146,7 +146,10 @@ t_check(_) ->
     [self() ! {msg, I} || I <- lists:seq(1, 5)],
     ?assertEqual(ok, emqx_misc:check_oom(Policy)),
     [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([]).