Skip to content

Commit e778f71

Browse files
committed
Add core_started boot state
1 parent f7b5aa1 commit e778f71

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

deps/rabbit/apps/rabbitmq_prelaunch/src/rabbit_boot_state.erl

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313
-export([get/0,
1414
set/1,
15-
wait_for/2]).
15+
wait_for/2,
16+
has_reached/1,
17+
has_reached_and_is_active/1]).
1618

1719
-define(PT_KEY_BOOT_STATE, {?MODULE, boot_state}).
1820

19-
-type boot_state() :: 'stopped' | 'booting' | 'ready' | 'stopping'.
21+
-type boot_state() :: 'stopped' | 'booting' | 'core_started' | 'ready' | 'stopping'.
2022

2123
-export_type([boot_state/0]).
2224

@@ -36,15 +38,15 @@ set(BootState) ->
3638

3739
-spec wait_for(boot_state(), timeout()) -> ok | {error, timeout}.
3840
wait_for(BootState, infinity) ->
39-
case is_reached(BootState) of
41+
case has_reached(BootState) of
4042
true -> ok;
4143
false -> Wait = 200,
4244
timer:sleep(Wait),
4345
wait_for(BootState, infinity)
4446
end;
4547
wait_for(BootState, Timeout)
4648
when is_integer(Timeout) andalso Timeout >= 0 ->
47-
case is_reached(BootState) of
49+
case has_reached(BootState) of
4850
true -> ok;
4951
false -> Wait = 200,
5052
timer:sleep(Wait),
@@ -53,24 +55,35 @@ wait_for(BootState, Timeout)
5355
wait_for(_, _) ->
5456
{error, timeout}.
5557

56-
boot_state_idx(stopped) -> 0;
57-
boot_state_idx(booting) -> 1;
58-
boot_state_idx(ready) -> 2;
59-
boot_state_idx(stopping) -> 3.
58+
boot_state_idx(stopped) -> 0;
59+
boot_state_idx(booting) -> 1;
60+
boot_state_idx(core_started) -> 2;
61+
boot_state_idx(ready) -> 3;
62+
boot_state_idx(stopping) -> 4.
6063

6164
is_valid(BootState) ->
6265
is_integer(boot_state_idx(BootState)).
6366

64-
is_reached(TargetBootState) ->
65-
is_reached(?MODULE:get(), TargetBootState).
67+
has_reached(TargetBootState) ->
68+
has_reached(?MODULE:get(), TargetBootState).
6669

67-
is_reached(CurrentBootState, CurrentBootState) ->
70+
has_reached(CurrentBootState, CurrentBootState) ->
6871
true;
69-
is_reached(stopping, stopped) ->
72+
has_reached(stopping, stopped) ->
7073
false;
71-
is_reached(_CurrentBootState, stopped) ->
74+
has_reached(_CurrentBootState, stopped) ->
7275
true;
73-
is_reached(stopped, _TargetBootState) ->
76+
has_reached(stopped, _TargetBootState) ->
7477
true;
75-
is_reached(CurrentBootState, TargetBootState) ->
78+
has_reached(CurrentBootState, TargetBootState) ->
7679
boot_state_idx(TargetBootState) =< boot_state_idx(CurrentBootState).
80+
81+
has_reached_and_is_active(TargetBootState) ->
82+
case ?MODULE:get() of
83+
stopped ->
84+
false;
85+
CurrentBootState ->
86+
has_reached(CurrentBootState, TargetBootState)
87+
andalso
88+
not has_reached(CurrentBootState, stopping)
89+
end.

deps/rabbit/src/rabbit.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ start(normal, []) ->
893893

894894
ok = rabbit_boot_steps:run_boot_steps([rabbit | Plugins]),
895895
run_postlaunch_phase(Plugins),
896+
rabbit_boot_state:set(core_started),
896897
{ok, SupPid}
897898
catch
898899
throw:{error, _} = Error ->

deps/rabbit/src/rabbit_direct.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ auth_fun({Username, Password}, VHost, ExtraAuthProps) ->
7575
connect(Creds, VHost, Protocol, Pid, Infos) ->
7676
ExtraAuthProps = extract_extra_auth_props(Creds, VHost, Pid, Infos),
7777
AuthFun = auth_fun(Creds, VHost, ExtraAuthProps),
78-
case rabbit:is_running() of
78+
case rabbit_boot_state:has_reached_and_is_active(core_started) of
7979
true ->
8080
case whereis(rabbit_direct_client_sup) of
8181
undefined ->

0 commit comments

Comments
 (0)