[erlang-questions] Trying to use gen_leader and gdict

Ulf Wiger (TN/EAB) <>
Mon Oct 8 10:24:20 CEST 2007


Try the following:

1) You should identify nodes as _either_ candidates _or_ workers,
    not both at the same time. I'm not sure what the actual effect
    will be (I think they will count as candidates)

2) Make sure that a gdict instance is also started on at least
    one of the candidate nodes.

3) The candidates must be aware of the nodes intending to function
    as workers.

In your test, it appears as if you run the test on , but
this node is neither a candidate nor a worker, at least in the
command you issue on  It's not clear whether any
gen_leader instances are running on  or , but even
if there are,  will not be included if it's not listed
either as a worker or candidate on  or 

There is currently no facility in gen_leader to add candidates
or workers dynamically. It can be done during a code change.
More dynamic behaviour will hopefully be added eventually.

BR,
Ulf W


Jack Orenstein wrote:
> On Oct 2, 2007, at 3:40 AM, Ulf Wiger (TN/EAB) wrote:
> 
>> Jack Orenstein wrote:
>>> I am running Erlang R11B on OS X and have been investigating
>>> gen_leader.  I'm having some trouble with the gdict example included
>>> with gen_leader. I wrote the following program to use gdict:
>>> ...
>>> This causes a timeout:
>>>      zack$ time erl -sname z -noshell -s test main -s init stop
>>>      init({dict,0,
>>>                 16,
>>>                 16,
>>>                 8,
>>>                 80,
>>>                 48,
>>>                 {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
>>>                 {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}})
>>>      {"init terminating in do_boot",{timeout,{gen_leader,leader_call, 
>>> [<0.34.0>,{store,#Fun<gdict.0.10659195>}]}}}
>>> ...
>>> Can anyone see what I'm doing wrong?
>>
>> You're not doing anything wrong. There's a bug in gen_leader.
>> When you start gen_leader with only one candidate node, it
>> will still go into a receive loop waiting for responses from
>> other candidates.
> 
> Thanks for your response. I'm seeing the same problem with three nodes 
> (one running the test, two candidates/workers).
> 
> Here is my modified test:
> 
> -module(test).
> -export([main/0]).
> 
> -define(DUMP(X), io:format("~p:~p - ~p = ~p~n", [?MODULE, ?LINE, ??X, X])).
> 
> main() ->
>     rpc:call(, hello, hello, []),
>     rpc:call(, hello, hello, []),
>     Nodes = nodes(),
>     {ok, D} = gdict:new(test, Nodes, Nodes),
>     ?DUMP(D),
>     ?DUMP(node()),
>     ?DUMP(Nodes),
>     ?DUMP(gdict:append(a, 1, D)),
>     ?DUMP(gdict:append(b, 2, D)),
>     ?DUMP(gdict:append(c, 3, D)),
>     ?DUMP(gdict:find(a, D)),
>     ?DUMP(gdict:find(b, D)),
>     ?DUMP(gdict:find(c, D)).
> 
> I started two nodes (, ) and ran the test. Here is the 
> output, with timing (I added some ?DUMP calls to gdict and gen_leader too):
> 
> gdict:42 - "Name" = test
> gdict:43 - "Candidates" = []
> gdict:44 - "Workers" = []
> init({dict,0,
>            16,
>            16,
>            8,
>            80,
>            48,
>            {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
>            {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}})
> gdict:46 - "GenLeaderStart" = {ok,<0.42.0>}
> test:11 - "D" = <0.42.0>
> test:12 - "node ( )" = 
> test:13 - "Nodes" = []
> gdict:61 - "Key" = a
> gdict:62 - "Value" = 1
> gen_leader:259 - "Name" = <0.42.0>
> gen_leader:260 - "Request" = {store,#Fun<gdict.0.10659195>}
> {"init terminating in 
> do_boot",{timeout,{gen_leader,leader_call,[<0.42.0>,{store,#Fun<gdict.0.10659195>}]}}} 
> 
> 
> Crash dump was written to: erl_crash.dump
> init terminating in do_boot ()
> 
> real    0m5.986s
> user    0m0.199s
> sys    0m0.389s
> 
> 
> 
> Jack




More information about the erlang-questions mailing list