diff options
author | Maxim Fedorov <dane@whatsapp.com> | 2020-01-25 19:05:41 -0800 |
---|---|---|
committer | Maxim Fedorov <dane@whatsapp.com> | 2020-02-05 21:41:10 -0800 |
commit | 9279f3ce3e42444191208b8e6f75377b2895adf1 (patch) | |
tree | dd9c935462cc872ee1ea55072cef9d1b9af15965 /lib/kernel/src/kernel.erl | |
parent | c15eb5fdf721afed280afdbe0fff37706eef979c (diff) | |
download | erlang-9279f3ce3e42444191208b8e6f75377b2895adf1.tar.gz |
pg: distributed named process groups
Replacement for pg2 module. Differences (compared to pg2):
* non-existent and empty group treated the same (empty list of pids),
thus create/1 and delete/1 have no effect (and not implemented).
which_groups() return only non-empty groups
* no cluster lock required, and no dependency on global
* all join/leave operations require local process (it's not possible to join
a process from a different node)
* multi-join: join/leave several processes with a single call
Empty groups are not supported: unlike a process, group does not have
originating node. So it's possible that during net split one node deletes
the group, that still exists for another partition. pg2 will re-create deleted
group as soon as net split converges, which is quite unexpected.
Process groups can be organised into multiple scopes. Scopes are
completely independent of each other. A process may join any
number of groups in any number of scopes. Scopes are designed to
decouple single mesh into a set of overlay networks, reducing
amount of traffic required to propagate group membership
information.
Diffstat (limited to 'lib/kernel/src/kernel.erl')
-rw-r--r-- | lib/kernel/src/kernel.erl | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/kernel/src/kernel.erl b/lib/kernel/src/kernel.erl index 8877ceea8e..83f3fbecd5 100644 --- a/lib/kernel/src/kernel.erl +++ b/lib/kernel/src/kernel.erl @@ -64,7 +64,7 @@ config_change(Changed, New, Removed) -> %%% (file,code, | erl_dist (A)| | safe_sup (1)| %%% rpc, ...) ------------- ------------- %%% | | -%%% (net_kernel, (disk_log, pg2, +%%% (net_kernel, (disk_log, pg, %%% auth, ...) ...) %%% %%% The rectangular boxes are supervisors. All supervisors except @@ -180,7 +180,7 @@ init(safe) -> Boot = start_boot_server(), DiskLog = start_disk_log(), - Pg2 = start_pg2(), + Pg = start_pg2() ++ start_pg(), %% Run the on_load handlers for all modules that have been %% loaded so far. Running them at this point means that @@ -188,7 +188,7 @@ init(safe) -> %% (and in particular call code:priv_dir/1 or code:lib_dir/1). init:run_on_load_handlers(), - {ok, {SupFlags, Boot ++ DiskLog ++ Pg2}}. + {ok, {SupFlags, Boot ++ DiskLog ++ Pg}}. start_distribution() -> Rpc = #{id => rex, @@ -279,6 +279,19 @@ start_disk_log() -> [] end. +start_pg() -> + case application:get_env(kernel, start_pg) of + {ok, true} -> + [#{id => pg, + start => {pg, start_link, []}, + restart => permanent, + shutdown => 1000, + type => worker, + modules => [pg]}]; + _ -> + [] + end. + start_pg2() -> case application:get_env(kernel, start_pg2) of {ok, true} -> |