Skip to content

Commit bfe22a0

Browse files
committed
Replace gen_leader with locks_leader for gproc_dist
Port distributed registry to locks_leader: optional locks application, conditional gproc_dist start when locks_server is present, and optional peer connect via {gproc, gproc_dist} node list. Testing: Common Test gproc_dist_SUITE with peer nodes and per-node disk logs; eunit keeps local coverage (dist eunit generator removed). Drop rebar.config.script that previously gated gen_leader.
1 parent 5107b38 commit bfe22a0

13 files changed

Lines changed: 599 additions & 280 deletions

‎Makefile‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
## DEALINGS IN THE SOFTWARE.
2222
REBAR3=$(shell which rebar3 || echo ./rebar3)
2323

24-
.PHONY: all compile clean eunit test doc check dialyzer
24+
.PHONY: all compile clean eunit ct test doc check dialyzer
2525

2626
DIRS=src
2727

@@ -35,10 +35,18 @@ compile:
3535
clean:
3636
$(REBAR3) clean
3737

38+
# Local / non-distributed eunit only. gproc_dist lives under CT
39+
# (see gproc_dist_SUITE); the old dist eunit generator is disabled.
3840
eunit:
3941
$(REBAR3) eunit
4042

41-
test: eunit
43+
# Distributed suite: locks_leader peers + per-node disk logs.
44+
ct:
45+
@epmd -daemon 2>/dev/null || true
46+
$(REBAR3) ct --suite test/gproc_dist_SUITE
47+
48+
# Full local gate (matches intended CI split).
49+
test: eunit ct
4250

4351
doc:
4452
$(REBAR3) as edown edoc

‎rebar.config‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
{erl_opts, [debug_info]}.
33

44
{deps, [
5-
{gen_leader, ".*",
6-
{git, "https://github.com/garret-smith/gen_leader_revival.git", "HEAD"}}
5+
{locks, {git, "https://github.com/uwiger/locks.git", {ref, "d6ef026"}}}
76
]}.
87

98
{dialyzer, [{plt_apps, all_deps},
10-
{plt_extra_apps, [mnesia, runtime_tools, gen_leader]},
9+
{plt_extra_apps, [mnesia, runtime_tools, locks]},
1110
{warnings, [no_unused,
1211
no_improper_lists, no_fun_app, no_match,
1312
no_opaque, no_fail_call,

‎rebar.config.script‎

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎src/gproc.app.src‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
{vsn, "zomp"},
99
{id, "GPROC"},
1010
{registered, [ ] },
11-
{applications, [ kernel, stdlib ] },
11+
%% locks is optional: listed in both applications and optional_applications
12+
%% so the app controller starts it automatically when present, but gproc
13+
%% still loads if locks is absent (local-only installs).
14+
{applications, [ kernel, stdlib, locks ] },
15+
{optional_applications, [ locks ] },
1216
{mod, {gproc_app, []} },
1317
{licenses, ["Apache-2.0"]},
1418
{links, [{"Github", "https://github.com/uwiger/gproc"}]}

‎src/gproc.erl‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@
4141
%% starting the `gproc' and `gproc_dist' servers. Default is `[]'. It is
4242
%% likely that `{priority, high | max}' and/or increasing `min_heap_size'
4343
%% will improve performance.
44+
%% * `{gproc_dist, all | [node()] | {[node()], list()}}' - When `locks' is
45+
%% available and `gproc_dist' is started, an explicit node list causes
46+
%% `net_kernel:connect_node/1' for each peer before joining the society.
47+
%% `all' / `true' do not connect (already-connected nodes are discovered
48+
%% via locks_pg). Under gen_leader this env also controlled whether dist
49+
%% started; now dist starts whenever `locks' is running
50+
%% (see optional_applications).
4451
%%
4552
%% @end
4653

@@ -191,6 +198,7 @@
191198
ok
192199
end).
193200

201+
194202
-define(PID_IS_DEAD(Pid),
195203
(node(Pid) == node() andalso is_process_alive(Pid) == false)).
196204

@@ -706,7 +714,6 @@ await(Node, Key, Timeout) when is_atom(Node) ->
706714
?CATCH_GPROC_ERROR(await1(Node, Key, Timeout), [Node, Key, Timeout]).
707715

708716
await1({T,g,_} = Key, Timeout) when T=:=n; T=:=a; T=:=rc ->
709-
?CHK_DIST,
710717
request_wait(Key, Timeout);
711718
await1({T,l,_} = Key, Timeout) when T=:=n; T=:=a; T=:=rc ->
712719
case ets:lookup(?TAB, {Key, T}) of
@@ -860,7 +867,6 @@ nb_wait(Node, Key) ->
860867
?CATCH_GPROC_ERROR(nb_wait1(Node, Key), [Node, Key]).
861868

862869
nb_wait1({T,g,_} = Key) when T=:=n; T=:=a; T=:=rc ->
863-
?CHK_DIST,
864870
call({await, Key, self()}, g);
865871
nb_wait1({T,l,_} = Key) when T=:=n; T=:=a; T=:=rc ->
866872
call({await, Key, self()}, l);
@@ -901,7 +907,6 @@ cancel_wait(N, Key, Ref) ->
901907

902908

903909
cancel_wait1({_,g,_} = Key, Ref) ->
904-
?CHK_DIST,
905910
cast({cancel_wait, self(), Key, Ref}, g),
906911
ok;
907912
cancel_wait1({_,l,_} = Key, Ref) ->
@@ -917,7 +922,6 @@ cancel_wait_or_monitor(Key) ->
917922
?CATCH_GPROC_ERROR(cancel_wait_or_monitor1(Key), [Key]).
918923

919924
cancel_wait_or_monitor1({_,g,_} = Key) ->
920-
?CHK_DIST,
921925
cast({cancel_wait_or_monitor, self(), Key}, g),
922926
ok;
923927
cancel_wait_or_monitor1({_,l,_} = Key) ->
@@ -2610,12 +2614,14 @@ call(Req) ->
26102614
call(Req, l) ->
26112615
chk_reply(gen_server:call(?MODULE, Req));
26122616
call(Req, g) ->
2617+
?CHK_DIST,
26132618
chk_reply(gproc_dist:leader_call(Req)).
26142619

26152620
call(N, Req, l) ->
26162621
chk_reply(gen_server:call({?MODULE, N}, Req));
26172622
call(undefined, Req, g) ->
26182623
%% we always call the leader
2624+
?CHK_DIST,
26192625
chk_reply(gproc_dist:leader_call(Req)).
26202626

26212627

@@ -2632,6 +2638,7 @@ cast(Msg) ->
26322638
cast(Msg, l) ->
26332639
gen_server:cast(?MODULE, Msg);
26342640
cast(Msg, g) ->
2641+
?CHK_DIST,
26352642
gproc_dist:leader_cast(Msg).
26362643

26372644
cast(N, Msg, l) ->

‎src/gproc_app.erl‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ start() ->
4040
start(normal, []).
4141

4242
start(_Type, StartArgs) ->
43+
%% locks is optional_applications: ensure_all_started(gproc) will start it
44+
%% as a dep, but ensure_started/start(gproc) will not. Pull locks in here
45+
%% when it is loadable so gproc_sup can start gproc_dist; ignore failure
46+
%% when locks is not present (local-only install).
47+
_ = application:ensure_all_started(locks),
4348
case gproc_sup:start_link(StartArgs) of
4449
{ok, Pid} ->
4550
{ok, Pid};

0 commit comments

Comments
 (0)