@@ -35,28 +35,38 @@ adjust(Name, Def) ->
3535 end ,
3636 start_child (Name , Def ).
3737
38- start_child (Name , Def ) ->
38+ start_child ({VHost , ShovelName } = Name , Def ) ->
39+ rabbit_log_shovel :debug (" Asked to start a dynamic Shovel named '~s ' in virtual host '~s '" , [ShovelName , VHost ]),
40+ LockId = rabbit_shovel_locks :lock (Name ),
3941 cleanup_specs (),
40- case mirrored_supervisor :start_child (
42+ rabbit_log_shovel :debug (" Starting a mirrored supervisor named '~s ' in virtual host '~s '" , [ShovelName , VHost ]),
43+ Result = case mirrored_supervisor :start_child (
4144 ? SUPERVISOR ,
4245 {Name , {rabbit_shovel_dyn_worker_sup , start_link , [Name , Def ]},
4346 transient , ? WORKER_WAIT , worker , [rabbit_shovel_dyn_worker_sup ]}) of
4447 {ok , _Pid } -> ok ;
4548 {error , {already_started , _Pid }} -> ok
46- end .
49+ end ,
50+ % % release the lock if we managed to acquire one
51+ rabbit_shovel_locks :unlock (LockId ),
52+ Result .
4753
4854child_exists (Name ) ->
4955 lists :any (fun ({N , _ , _ , _ }) -> N =:= Name end ,
5056 mirrored_supervisor :which_children (? SUPERVISOR )).
5157
52- stop_child (Name ) ->
58+ stop_child ({VHost , ShovelName } = Name ) ->
59+ rabbit_log_shovel :debug (" Asked to stop a dynamic Shovel named '~s ' in virtual host '~s '" , [ShovelName , VHost ]),
60+ LockId = rabbit_shovel_locks :lock (Name ),
5361 case get ({shovel_worker_autodelete , Name }) of
5462 true -> ok ; % % [1]
5563 _ ->
5664 ok = mirrored_supervisor :terminate_child (? SUPERVISOR , Name ),
5765 ok = mirrored_supervisor :delete_child (? SUPERVISOR , Name ),
5866 rabbit_shovel_status :remove (Name )
59- end .
67+ end ,
68+ rabbit_shovel_locks :unlock (LockId ),
69+ ok .
6070
6171% % [1] An autodeleting worker removes its own parameter, and thus ends
6272% % up here via the parameter callback. It is a transient worker that
0 commit comments