Skip to content

Commit b6ba894

Browse files
the-mikedavismichaelklishin
authored andcommitted
Read the msup converter's sub-state from the converter state
This was originally part of the async migration PR that introduced `with_correlation_id/2` but was dropped since there weren't any converters at the time that needed it. We read the sub-state right out of the `sub_states` map in `rabbit_db_m2k_converter`'s state. This must be done in a function in `rabbit_db_m2k_converter` since the state record is opaque.
1 parent 174caaa commit b6ba894

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

deps/rabbit/src/rabbit_db_m2k_converter.erl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
-include_lib("rabbit_common/include/rabbit.hrl").
1616

1717
%% Functions for `rabbit_db_*_m2k_converter' modules to call.
18-
-export([with_correlation_id/2]).
18+
-export([with_correlation_id/2,
19+
get_sub_state/2]).
1920

2021
%% `mnesia_to_khepri_converter' callbacks.
2122
-export([init_copy_to_khepri/4,
@@ -68,6 +69,14 @@ with_correlation_id(
6869
run_async_fun(Fun, State0)
6970
end.
7071

72+
-spec get_sub_state(Module, State) -> Ret when
73+
Module :: module(),
74+
State :: state(),
75+
Ret :: any().
76+
77+
get_sub_state(Module, #?MODULE{sub_states = SubStates}) ->
78+
maps:get(Module, SubStates).
79+
7180
%% `mnesia_to_khepri_converter' callbacks
7281

7382
-spec init_copy_to_khepri(StoreId, MigrationId, Tables, Migrations) ->

deps/rabbit/src/rabbit_db_msup_m2k_converter.erl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
copy_to_khepri/3,
2020
delete_from_khepri/3]).
2121

22-
-record(?MODULE, {store_id :: khepri:store_id(),
23-
record_converters :: [module()]}).
22+
-record(?MODULE, {record_converters :: [module()]}).
2423

2524
-spec init_copy_to_khepri(StoreId, MigrationId, Tables) -> Ret when
2625
StoreId :: khepri:store_id(),
@@ -30,14 +29,13 @@
3029
Priv :: #?MODULE{}.
3130
%% @private
3231

33-
init_copy_to_khepri(StoreId, _MigrationId, Tables) ->
32+
init_copy_to_khepri(_StoreId, _MigrationId, Tables) ->
3433
%% Clean up any previous attempt to copy the Mnesia table to Khepri.
3534
lists:foreach(fun clear_data_in_khepri/1, Tables),
3635

3736
Converters = discover_converters(?MODULE),
38-
State = #?MODULE{store_id = StoreId,
39-
record_converters = Converters},
40-
{ok, State}.
37+
SubState = #?MODULE{record_converters = Converters},
38+
{ok, SubState}.
4139

4240
-spec copy_to_khepri(Table, Record, State) -> Ret when
4341
Table :: mnesia_to_khepri:mnesia_table(),
@@ -50,7 +48,9 @@ init_copy_to_khepri(StoreId, _MigrationId, Tables) ->
5048

5149
copy_to_khepri(mirrored_sup_childspec = Table,
5250
#mirrored_sup_childspec{} = Record0,
53-
#?MODULE{record_converters = Converters} = State) ->
51+
State) ->
52+
#?MODULE{record_converters = Converters} =
53+
rabbit_db_m2k_converter:get_sub_state(?MODULE, State),
5454
Record = upgrade_record(Converters, Table, Record0),
5555
#mirrored_sup_childspec{key = {Group, {SimpleId, _}} = Key} = Record,
5656
?LOG_DEBUG(
@@ -81,8 +81,9 @@ copy_to_khepri(Table, Record, State) ->
8181
Reason :: any().
8282
%% @private
8383

84-
delete_from_khepri(
85-
mirrored_sup_childspec = Table, Key0, #?MODULE{record_converters = Converters} = State) ->
84+
delete_from_khepri(mirrored_sup_childspec = Table, Key0, State) ->
85+
#?MODULE{record_converters = Converters} =
86+
rabbit_db_m2k_converter:get_sub_state(?MODULE, State),
8687
{Group, Id} = Key = upgrade_key(Converters, Table, Key0),
8788
?LOG_DEBUG(
8889
"Mnesia->Khepri data delete: [~0p] key: ~0p",

0 commit comments

Comments
 (0)