8585 query_index := non_neg_integer (),
8686 queries_waiting_heartbeats := queue :queue ({non_neg_integer (), consistent_query_ref ()}),
8787 pending_consistent_queries := [consistent_query_ref ()],
88- voter => 'maybe' (ra_voter ()),
8988 commit_latency => 'maybe' (non_neg_integer ())
9089 }.
9190
@@ -397,11 +396,15 @@ handle_leader({PeerId, #append_entries_reply{term = Term, success = true,
397396 Peer = Peer0 #{match_index => max (MI , LastIdx ),
398397 next_index => max (NI , NextIdx )},
399398 State1 = put_peer (PeerId , Peer , State0 ),
400- {State2 , Effects0 } = evaluate_quorum (State1 , []),
399+ Effects00 = ra_voter :maybe_promote (PeerId , State1 , []),
400+
401+ {State2 , Effects0 } = evaluate_quorum (State1 , Effects00 ),
401402
402403 {State , Effects1 } = process_pending_consistent_queries (State2 ,
403404 Effects0 ),
405+
404406 Effects = [{next_event , info , pipeline_rpcs } | Effects1 ],
407+
405408 case State of
406409 #{cluster := #{Id := _ }} ->
407410 % leader is in the cluster
@@ -1106,14 +1109,12 @@ handle_follower({ra_log_event, Evt}, State = #{log := Log0}) ->
11061109 % simply forward all other events to ra_log
11071110 {Log , Effects } = ra_log :handle_event (Evt , Log0 ),
11081111 {follower , State #{log => Log }, Effects };
1109- handle_follower (# pre_vote_rpc {}, #{voter := {no , _ }} = State ) ->
1110- % % ignore elections, non-voter
1112+ handle_follower (# pre_vote_rpc {},
1113+ #{cfg := # cfg {log_id = LogId }, voter := {no , _ } = Voter } = State ) ->
1114+ ? WARN (" ~w : follower ignored request_vote_rpc, non voter: ~p " , [LogId , Voter ]),
11111115 {follower , State , []};
11121116handle_follower (# pre_vote_rpc {} = PreVote , State ) ->
11131117 process_pre_vote (follower , PreVote , State );
1114- handle_follower (# request_vote_rpc {}, #{voter := {no , _ }} = State ) ->
1115- % % ignore elections, non-voter
1116- {follower , State , []};
11171118handle_follower (# request_vote_rpc {candidate_id = Cand , term = Term },
11181119 #{current_term := Term , voted_for := VotedFor ,
11191120 cfg := # cfg {log_id = LogId }} = State )
@@ -1211,8 +1212,10 @@ handle_follower(#append_entries_reply{}, State) ->
12111212 % % handle to avoid logging as unhandled
12121213 % % could receive a lot of these shortly after standing down as leader
12131214 {follower , State , []};
1214- handle_follower (election_timeout , #{voter := {no , _ }} = State ) ->
1215- % % ignore elections, non-voter
1215+ handle_follower (election_timeout ,
1216+ #{cfg := # cfg {log_id = LogId }, voter := {no , _ } = Voter } = State ) ->
1217+ ? WARN (" ~w : follower ignored election_timeout, non voter: ~p " ,
1218+ [LogId , Voter ]),
12161219 {follower , State , []};
12171220handle_follower (election_timeout , State ) ->
12181221 call_for_election (pre_vote , State );
@@ -1381,6 +1384,7 @@ overview(#{cfg := #cfg{effective_machine_module = MacMod} = Cfg,
13811384 last_applied ,
13821385 cluster ,
13831386 leader_id ,
1387+ voter ,
13841388 voted_for ,
13851389 cluster_change_permitted ,
13861390 cluster_index_term ,
@@ -2099,8 +2103,8 @@ new_peer() ->
20992103 match_index => 0 ,
21002104 commit_index_sent => 0 ,
21012105 query_index => 0 ,
2102- status => normal ,
2103- voter => yes }.
2106+ voter => yes ,
2107+ status => normal }.
21042108
21052109new_peer_with (Map ) ->
21062110 maps :merge (new_peer (), Map ).
@@ -2336,7 +2340,7 @@ apply_with({Idx, Term, {'$ra_cluster_change', CmdMeta, NewCluster, ReplyType}},
23362340 [log_id (State0 ), maps :keys (NewCluster )]),
23372341 % % we are recovering and should apply the cluster change
23382342 State0 #{cluster => NewCluster ,
2339- voter => ra_voter :peer_status ( id (State0 ), NewCluster ),
2343+ voter => ra_voter :status ( NewCluster , id (State0 )),
23402344 cluster_change_permitted => true ,
23412345 cluster_index_term => {Idx , Term }};
23422346 _ ->
@@ -2488,7 +2492,7 @@ append_log_leader({'$ra_maybe_join', From, JoiningNode, ReplyMode},
24882492 #{JoiningNode := _ } ->
24892493 already_member (State );
24902494 _ ->
2491- Cluster = OldCluster #{JoiningNode => new_peer_with (#{voter => ra_voter :new_nonvoter (State )})},
2495+ Cluster = OldCluster #{JoiningNode => new_peer_with (#{voter => ra_voter :new_nonvoter (State )})},
24922496 append_cluster_change (Cluster , From , ReplyMode , State )
24932497 end ;
24942498append_log_leader ({'$ra_leave' , From , LeavingServer , ReplyMode },
@@ -2520,7 +2524,6 @@ pre_append_log_follower({Idx, Term, Cmd} = Entry,
25202524 case Cmd of
25212525 {'$ra_cluster_change' , _ , Cluster , _ } ->
25222526 State #{cluster => Cluster ,
2523- voter => ra_voter :peer_status (id (State ), Cluster ),
25242527 cluster_index_term => {Idx , Term }};
25252528 _ ->
25262529 % revert back to previous cluster
@@ -2532,7 +2535,7 @@ pre_append_log_follower({Idx, Term, Cmd} = Entry,
25322535pre_append_log_follower ({Idx , Term , {'$ra_cluster_change' , _ , Cluster , _ }},
25332536 State ) ->
25342537 State #{cluster => Cluster ,
2535- voter => ra_voter :peer_status ( id (State ), Cluster ),
2538+ voter => ra_voter :status ( Cluster , id (State )),
25362539 cluster_index_term => {Idx , Term }};
25372540pre_append_log_follower (_ , State ) ->
25382541 State .
@@ -2609,6 +2612,8 @@ query_indexes(#{cfg := #cfg{id = Id},
26092612 query_index := QueryIndex }) ->
26102613 maps :fold (fun (PeerId , _ , Acc ) when PeerId == Id ->
26112614 Acc ;
2615+ (_K , #{voter := {no , _ }}, Acc ) ->
2616+ Acc ;
26122617 (_K , #{query_index := Idx }, Acc ) ->
26132618 [Idx | Acc ]
26142619 end , [QueryIndex ], Cluster ).
@@ -2619,6 +2624,8 @@ match_indexes(#{cfg := #cfg{id = Id},
26192624 {LWIdx , _ } = ra_log :last_written (Log ),
26202625 maps :fold (fun (PeerId , _ , Acc ) when PeerId == Id ->
26212626 Acc ;
2627+ (_K , #{voter := {no , _ }}, Acc ) ->
2628+ Acc ;
26222629 (_K , #{match_index := Idx }, Acc ) ->
26232630 [Idx | Acc ]
26242631 end , [LWIdx ], Cluster ).
0 commit comments