[erlang-questions] noob gen_leader question

db <>
Fri Apr 18 20:45:23 CEST 2008


Here is the module used to run gdict and it's corresponding output:

-module(gen_leader_for_dummies).
-export([main/0]).

-define(DUMP(X), io:format("~p:~p - ~p = ~p~n", [?MODULE, ?
LINE, ??X, X])).

main() ->

    ?DUMP(node()),
    ?DUMP(nodes()),

    %CandidateNodes and WorkerNodes are disjoint set of nodes	
    CandidateNodes = [],
    WorkerNodes = [],

    ?DUMP(CandidateNodes),
    ?DUMP(WorkerNodes),
    {ok, D} = gdict:new(dummy, CandidateNodes, WorkerNodes),
    ?DUMP(D),
    ?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)).

()1> gen_leader_for_dummies:main().
gen_leader_for_dummies:9 - "node ( )" = 
gen_leader_for_dummies:10 - "nodes ( )" = []
gen_leader_for_dummies:15 - "CandidateNodes" = []
gen_leader_for_dummies:16 - "WorkerNodes" = []
init({dict,0,16,16,8,80,48,
           {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
           {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]}}})
gen_leader_for_dummies:18 - "D" = <0.72.0>
elected([], {election,<0.72.0>,
                      [],
                      [],
                      [],
                      {[],1},
                      [],
                      [{#Ref<0.0.0.197>},{#Ref<0.0.0.196>}],
                      []})
gen_leader_for_dummies:19 - "gdict : append ( a , 1 , D )" = ok
gen_leader_for_dummies:20 - "gdict : append ( b , 2 , D )" = ok
gen_leader_for_dummies:21 - "gdict : append ( c , 3 , D )" = ok
gen_leader_for_dummies:22 - "gdict : find ( a , D )" = {ok,[1]}
gen_leader_for_dummies:23 - "gdict : find ( b , D )" = {ok,[2]}
gen_leader_for_dummies:24 - "gdict : find ( c , D )" = {ok,[3]}
ok


On Fri, Apr 18, 2008 at 1:13 PM, db <> wrote:
> I reran the gdict example and election record shows  as down.
>  Even though this is not the case, but simply  is not the
>  current leader.  There is no distinction made between node being down
>  and nodes that aren't elected leader in actual election record/tuple.
>
>  Also, what is buffered field in the election record definition?
-
rk

That which we persist in doing becomes easier for us to do; not that
the nature of the thing itself is changed, but that our power to do is
increased.
-Ralph Waldo Emerson



More information about the erlang-questions mailing list