Skip to content

Commit

Permalink
Merge pull request #292 from cloudamqp/4_0
Browse files Browse the repository at this point in the history
Ensure Mnesia is running when Khepri is used as main metadata store
  • Loading branch information
michaelklishin authored Oct 2, 2024
2 parents 1187327 + 028b624 commit 18d8135
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ of some kind.

The most recent release of this plugin targets RabbitMQ 4.0.x.

This plugin currently only supports Mnesia for metadata store (do not use it with Khepri).
This plugin can be enabled on a RabbitMQ cluster that uses either Mnesia or Khepri as metadata store.

Warning: the plugin must be disabled during Khepri migration. One
needs to disable this plugin before enabling the `khepri_db` feature
flag and enable it after. This will result in losing all previous
delayed messages.

## Supported Erlang/OTP Versions

Expand Down
26 changes: 26 additions & 0 deletions src/rabbit_delayed_message.erl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ delay_message(Exchange, Message, Delay) ->
infinity).

setup_mnesia() ->
case rabbit_khepri:is_enabled() of
true ->
ensure_mnesia_running();
false ->
%% Mnesia should already be running
ok
end,
_ = mnesia:create_table(?TABLE_NAME, [{record_name, delay_entry},
{attributes,
record_info(fields, delay_entry)},
Expand All @@ -97,6 +104,25 @@ setup_mnesia() ->
{disc_copies, [node()]}]),
rabbit_table:wait([?TABLE_NAME, ?INDEX_TABLE_NAME]).

ensure_mnesia_running() ->
case rabbit_mnesia:is_running() of
false ->
ensure_mnesia_disc_schema(),
rabbit_mnesia:start_mnesia(_CheckConsistency = false);
true ->
ok
end.

ensure_mnesia_disc_schema() ->
case mnesia:system_info(use_dir) of
true ->
%% There is a disc schema already
ok;
false ->
rabbit_misc:ensure_ok(mnesia:create_schema([node()]),
{?MODULE, cannot_create_mnesia_schema})
end.

disable_plugin() ->
_ = mnesia:delete_table(?INDEX_TABLE_NAME),
_ = mnesia:delete_table(?TABLE_NAME),
Expand Down

0 comments on commit 18d8135

Please sign in to comment.