2
2
% % License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
% % file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
4
% %
5
- % % Copyright (c) 2007 -2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
5
+ % % Copyright (c) 2022 -2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
6
6
% %
7
7
8
8
-module (rabbit_db_msup_m2k_converter ).
19
19
copy_to_khepri /3 ,
20
20
delete_from_khepri /3 ]).
21
21
22
- -record (? MODULE , {record_converters :: [ module ()] }).
22
+ -record (? MODULE , {}).
23
23
24
24
-spec init_copy_to_khepri (StoreId , MigrationId , Tables ) -> Ret when
25
25
StoreId :: khepri :store_id (),
@@ -33,8 +33,7 @@ init_copy_to_khepri(_StoreId, _MigrationId, Tables) ->
33
33
% % Clean up any previous attempt to copy the Mnesia table to Khepri.
34
34
lists :foreach (fun clear_data_in_khepri /1 , Tables ),
35
35
36
- Converters = discover_converters (? MODULE ),
37
- SubState = #? MODULE {record_converters = Converters },
36
+ SubState = #? MODULE {},
38
37
{ok , SubState }.
39
38
40
39
-spec copy_to_khepri (Table , Record , State ) -> Ret when
@@ -47,17 +46,13 @@ init_copy_to_khepri(_StoreId, _MigrationId, Tables) ->
47
46
% % @private
48
47
49
48
copy_to_khepri (mirrored_sup_childspec = Table ,
50
- # mirrored_sup_childspec {} = Record0 ,
49
+ # mirrored_sup_childspec {key = { Group , Id } = Key } = Record ,
51
50
State ) ->
52
- #? MODULE {record_converters = Converters } =
53
- rabbit_db_m2k_converter :get_sub_state (? MODULE , State ),
54
- Record = upgrade_record (Converters , Table , Record0 ),
55
- # mirrored_sup_childspec {key = {Group , {SimpleId , _ }} = Key } = Record ,
56
51
? LOG_DEBUG (
57
52
" Mnesia->Khepri data copy: [~0p ] key: ~0p " ,
58
53
[Table , Key ],
59
54
#{domain => ? KMM_M2K_TABLE_COPY_LOG_DOMAIN }),
60
- Path = rabbit_db_msup :khepri_mirrored_supervisor_path (Group , SimpleId ),
55
+ Path = rabbit_db_msup :khepri_mirrored_supervisor_path (Group , Id ),
61
56
rabbit_db_m2k_converter :with_correlation_id (
62
57
fun (CorrId ) ->
63
58
Extra = #{async => CorrId },
@@ -81,10 +76,8 @@ copy_to_khepri(Table, Record, State) ->
81
76
Reason :: any ().
82
77
% % @private
83
78
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 ),
87
- {Group , Id } = Key = upgrade_key (Converters , Table , Key0 ),
79
+ delete_from_khepri (
80
+ mirrored_sup_childspec = Table , {Group , Id } = Key , State ) ->
88
81
? LOG_DEBUG (
89
82
" Mnesia->Khepri data delete: [~0p ] key: ~0p " ,
90
83
[Table , Key ],
@@ -109,39 +102,3 @@ clear_data_in_khepri(mirrored_sup_childspec) ->
109
102
ok -> ok ;
110
103
Error -> throw (Error )
111
104
end .
112
-
113
- % % Khepri paths don't support tuples or records, so the key part of the
114
- % % #mirrored_sup_childspec{} used by some plugins must be transformed in a
115
- % % valid Khepri path during the migration from Mnesia to Khepri.
116
- % % `rabbit_db_msup_m2k_converter` iterates over all declared converters, which
117
- % % must implement `rabbit_mnesia_to_khepri_record_converter` behaviour callbacks.
118
- % %
119
- % % This mechanism could be reused by any other rabbit_db_*_m2k_converter
120
-
121
- discover_converters (MigrationMod ) ->
122
- Apps = rabbit_misc :rabbitmq_related_apps (),
123
- AttrsPerApp = rabbit_misc :module_attributes_from_apps (
124
- rabbit_mnesia_records_to_khepri_db , Apps ),
125
- discover_converters (MigrationMod , AttrsPerApp , []).
126
-
127
- discover_converters (MigrationMod , [{_App , _AppMod , AppConverters } | Rest ],
128
- Converters0 ) ->
129
- Converters =
130
- lists :foldl (fun ({Module , Mod }, Acc ) when Module =:= MigrationMod ->
131
- [Mod | Acc ];
132
- (_ , Acc ) ->
133
- Acc
134
- end , Converters0 , AppConverters ),
135
- discover_converters (MigrationMod , Rest , Converters );
136
- discover_converters (_MigrationMod , [], Converters ) ->
137
- Converters .
138
-
139
- upgrade_record (Converters , Table , Record ) ->
140
- lists :foldl (fun (Mod , Record0 ) ->
141
- Mod :upgrade_record (Table , Record0 )
142
- end , Record , Converters ).
143
-
144
- upgrade_key (Converters , Table , Key ) ->
145
- lists :foldl (fun (Mod , Key0 ) ->
146
- Mod :upgrade_key (Table , Key0 )
147
- end , Key , Converters ).
0 commit comments