-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Acquire locks when starting mirrored supervisor children
Unlike pg2, pg in Erlang 24 is eventually consistent. So this reintroduces some of the same kind of locking mirrored_supervisor used to rely on implicitly via pg2. Per discussion with @lhoguin. Closes #3260. References #3132, #3154. (cherry picked from commit 22add3c)
- Loading branch information
1 parent
a9b1c86
commit 3106ac3
Showing
2 changed files
with
54 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
%% This Source Code Form is subject to the terms of the Mozilla Public | ||
%% License, v. 2.0. If a copy of the MPL was not distributed with this | ||
%% file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
%% | ||
%% Copyright (c) 2007-2021 VMware, Inc. or its affiliates. All rights reserved. | ||
%% | ||
|
||
-module(mirrored_supervisor_locks). | ||
|
||
-export([lock/1, unlock/1]). | ||
|
||
-define(KEY_PREFIX, mirrored_supervisor). | ||
|
||
%% | ||
%% API | ||
%% | ||
|
||
lock(Group) -> | ||
Nodes = nodes(), | ||
%% about 300s, same as rabbit_nodes:lock_retries/0 default | ||
LockId = case global:set_lock({?KEY_PREFIX, Group}, Nodes, 80) of | ||
true -> Group; | ||
false -> undefined | ||
end, | ||
LockId. | ||
|
||
unlock(LockId) -> | ||
Nodes = nodes(), | ||
case LockId of | ||
undefined -> ok; | ||
Value -> global:del_lock({?KEY_PREFIX, Value}, Nodes) | ||
end, | ||
ok. |