Skip to content

Commit 348c6d4

Browse files
committed
rabbit_db: Register projections during virgin db init
This covers a specific case where we need to register projections not covered by the enable callback of the `khepri_db` feature flag. The feature flag may be enabled if a node has been part of a cluster which enabled the flag, but the metadata store might be reset. Upon init the feature flag will be enabled but the store will be empty and the projections will not exist, so operations like inserting default data will fail when asserting that a vhost exists for example. This fixes the `cluster_management_SUITE:forget_cluster_node_in_khepri/1` case when running the suite with `RABBITMQ_METADATA_STORE=khepri`, which fails as mentioned above. We could run projection registration always when using Khepri (i.e. the `init_using_khepri/0` function) but once projections are registered the command is idempotent so there's no need to, and the commands are somewhat large.
1 parent 5eafdb4 commit 348c6d4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

deps/rabbit/src/rabbit_db.erl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ init() ->
6767
end,
6868

6969
Ret = case rabbit_khepri:is_enabled() of
70-
true -> init_using_khepri();
71-
false -> init_using_mnesia()
70+
true -> init_using_khepri(IsVirgin);
71+
false -> init_using_mnesia(IsVirgin)
7272
end,
7373
case Ret of
7474
ok ->
@@ -91,23 +91,29 @@ pre_init(IsVirgin) ->
9191
OtherMembers = rabbit_nodes:nodes_excl_me(Members),
9292
rabbit_db_cluster:ensure_feature_flags_are_in_sync(OtherMembers, IsVirgin).
9393

94-
init_using_mnesia() ->
94+
init_using_mnesia(_IsVirgin) ->
9595
?LOG_DEBUG(
9696
"DB: initialize Mnesia",
9797
#{domain => ?RMQLOG_DOMAIN_DB}),
9898
ok = rabbit_mnesia:init(),
9999
?assertEqual(rabbit:data_dir(), mnesia_dir()),
100100
rabbit_sup:start_child(mnesia_sync).
101101

102-
init_using_khepri() ->
102+
init_using_khepri(IsVirgin) ->
103103
case rabbit_khepri:members() of
104104
[] ->
105105
timer:sleep(1000),
106-
init_using_khepri();
106+
init_using_khepri(IsVirgin);
107107
Members ->
108108
?LOG_WARNING(
109109
"Found the following metadata store members: ~p", [Members],
110-
#{domain => ?RMQLOG_DOMAIN_DB})
110+
#{domain => ?RMQLOG_DOMAIN_DB}),
111+
case IsVirgin of
112+
true ->
113+
rabbit_khepri:register_projections();
114+
false ->
115+
ok
116+
end
111117
end.
112118

113119
init_finished() ->

0 commit comments

Comments
 (0)