@@ -72,8 +72,18 @@ stop_child({VHost, ShovelName} = Name) ->
72
72
case get ({shovel_worker_autodelete , Name }) of
73
73
true -> ok ; % % [1]
74
74
_ ->
75
- ok = mirrored_supervisor :terminate_child (? SUPERVISOR , id (Name )),
76
- ok = mirrored_supervisor :delete_child (? SUPERVISOR , id (Name )),
75
+ case mirrored_supervisor :terminate_child (? SUPERVISOR , id (Name )) of
76
+ ok ->
77
+ ok = mirrored_supervisor :delete_child (? SUPERVISOR , id (Name ));
78
+ {error , not_found } ->
79
+ % % try older format, pre 3.13.0 and 3.12.8. See rabbitmq/rabbitmq-server#9894.
80
+ case mirrored_supervisor :terminate_child (? SUPERVISOR , old_id (Name )) of
81
+ ok ->
82
+ ok = mirrored_supervisor :delete_child (? SUPERVISOR , old_id (Name ));
83
+ {error , not_found } ->
84
+ ok
85
+ end
86
+ end ,
77
87
rabbit_shovel_status :remove (Name )
78
88
end ,
79
89
rabbit_shovel_locks :unlock (LockId ),
@@ -90,41 +100,47 @@ stop_child({VHost, ShovelName} = Name) ->
90
100
cleanup_specs () ->
91
101
Children = mirrored_supervisor :which_children (? SUPERVISOR ),
92
102
93
- % % older format, pre 3.13.0 and 3.12.8. See rabbitmq/rabbitmq-server#9894
94
- OldStyleSpecsSet = sets :from_list ([element (1 , S ) || S <- Children ]),
95
- NewStyleSpecsSet = sets :from_list ([element (2 , element (1 , S )) || S <- Children ]),
96
- ParamsSet = sets :from_list ([ {proplists :get_value (vhost , S ), proplists :get_value (name , S )}
97
- || S <- rabbit_runtime_parameters :list_component (<<" shovel" >>) ]),
98
- F = fun (Name , ok ) ->
103
+ SupIdSet = sets :from_list ([element (1 , S ) || S <- Children ]),
104
+ ParamsSet = params_to_child_ids (rabbit_khepri :is_enabled ()),
105
+ F = fun (SupId , ok ) ->
99
106
try
100
107
% % The supervisor operation is very unlikely to fail, it's the schema
101
108
% % data stores that can make a fuss about a non-existent or non-standard value passed in.
102
109
% % For example, an old style Shovel name is an invalid Khepri query path element. MK.
103
- _ = mirrored_supervisor :delete_child (? SUPERVISOR , id ( Name ) )
110
+ _ = mirrored_supervisor :delete_child (? SUPERVISOR , SupId )
104
111
catch _ :_ :_Stacktrace ->
105
112
ok
106
113
end ,
107
114
ok
108
115
end ,
109
- % % Khepri won't handle values in OldStyleSpecsSet in its path well. At the same time,
110
- % % those older elements simply cannot exist in Khepri because having Khepri enabled
111
- % % means a cluster-wide move to 3.13+, so we can conditionally compute what specs we care about. MK.
112
- AllSpecs =
113
- case rabbit_khepri :is_enabled () of
114
- true -> NewStyleSpecsSet ;
115
- false -> sets :union (NewStyleSpecsSet , OldStyleSpecsSet )
116
- end ,
117
116
% % Delete any supervisor children that do not have their respective runtime parameters in the database.
118
- SetToCleanUp = sets :subtract (AllSpecs , ParamsSet ),
117
+ SetToCleanUp = sets :subtract (SupIdSet , ParamsSet ),
119
118
ok = sets :fold (F , ok , SetToCleanUp ).
120
119
120
+ params_to_child_ids (_KhepriEnabled = true ) ->
121
+ % % Old id format simply cannot exist in Khepri because having Khepri enabled
122
+ % % means a cluster-wide move to 3.13+, so we can conditionally compute what specs we care about. MK.
123
+ sets :from_list ([id ({proplists :get_value (vhost , S ), proplists :get_value (name , S )})
124
+ || S <- rabbit_runtime_parameters :list_component (<<" shovel" >>)]);
125
+ params_to_child_ids (_KhepriEnabled = false ) ->
126
+ sets :from_list (
127
+ lists :flatmap (
128
+ fun (S ) ->
129
+ Name = {proplists :get_value (vhost , S ), proplists :get_value (name , S )},
130
+ % % Supervisor Id format was different pre 3.13.0 and 3.12.8.
131
+ % % Try both formats to cover the transitionary mixed version cluster period.
132
+ [id (Name ), old_id (Name )]
133
+ end ,
134
+ rabbit_runtime_parameters :list_component (<<" shovel" >>))).
135
+
121
136
% %----------------------------------------------------------------------------
122
137
123
138
init ([]) ->
124
139
{ok , {{one_for_one , 3 , 10 }, []}}.
125
140
126
141
id ({V , S } = Name ) ->
127
- {[V , S ], Name };
142
+ {[V , S ], Name }.
143
+
128
144
% % older format, pre 3.13.0 and 3.12.8. See rabbitmq/rabbitmq-server#9894
129
- id ( Other ) ->
130
- Other .
145
+ old_id ({ _V , _S } = Name ) ->
146
+ Name .
0 commit comments