@@ -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,23 +100,26 @@ 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 = sets :from_list (
105
+ lists :flatmap (
106
+ fun (S ) ->
107
+ Name = {proplists :get_value (vhost , S ), proplists :get_value (name , S )},
108
+ % % Supervisor Id format was different pre 3.13.0 and 3.12.8.
109
+ % % Try both formats to cover the transitionary mixed version cluster period.
110
+ [id (Name ), old_id (Name )]
111
+ end ,
112
+ rabbit_runtime_parameters :list_component (<<" shovel" >>))),
113
+ F = fun (SupId , ok ) ->
99
114
try
100
- _ = mirrored_supervisor :delete_child (? SUPERVISOR , id ( Name ) )
115
+ _ = mirrored_supervisor :delete_child (? SUPERVISOR , SupId )
101
116
catch _ :_ :_Stacktrace ->
102
117
ok
103
118
end ,
104
119
ok
105
120
end ,
106
- % % Try both formats to cover the transitionary mixed version cluster period.
107
- AllSpecs = sets :union (NewStyleSpecsSet , OldStyleSpecsSet ),
108
121
% % Delete any supervisor children that do not have their respective runtime parameters in the database.
109
- SetToCleanUp = sets :subtract (AllSpecs , ParamsSet ),
122
+ SetToCleanUp = sets :subtract (SupIdSet , ParamsSet ),
110
123
ok = sets :fold (F , ok , SetToCleanUp ).
111
124
112
125
% %----------------------------------------------------------------------------
@@ -115,7 +128,8 @@ init([]) ->
115
128
{ok , {{one_for_one , 3 , 10 }, []}}.
116
129
117
130
id ({V , S } = Name ) ->
118
- {[V , S ], Name };
131
+ {[V , S ], Name }.
132
+
119
133
% % older format, pre 3.13.0 and 3.12.8. See rabbitmq/rabbitmq-server#9894
120
- id ( Other ) ->
121
- Other .
134
+ old_id ({ _V , _S } = Name ) ->
135
+ Name .
0 commit comments