1%% This Source Code Form is subject to the terms of the Mozilla Public 2%% License, v. 2.0. If a copy of the MPL was not distributed with this 3%% file, You can obtain one at https://mozilla.org/MPL/2.0/. 4%% 5%% Copyright (c) 2007-2021 VMware, Inc. or its affiliates. All rights reserved. 6%% 7 8-module(rabbit_shovel_locks). 9 10-export([lock/1, unlock/1]). 11 12%% 13%% API 14%% 15 16lock(Name) -> 17 Nodes = rabbit_nodes:all_running(), 18 Retries = rabbit_nodes:lock_retries(), 19 %% try to acquire a lock to avoid duplicate starts 20 LockId = case global:set_lock({dynamic_shovel, Name}, Nodes, Retries) of 21 true -> Name; 22 false -> undefined 23 end, 24 LockId. 25 26unlock(LockId) -> 27 Nodes = rabbit_nodes:all_running(), 28 case LockId of 29 undefined -> ok; 30 Value -> global:del_lock({dynamic_shovel, Value}, Nodes) 31 end, 32 ok. 33