4141
4242% % API
4343-export ([
44- start_catchup_request /6 ,
44+ start_catchup_request /5 ,
4545 cancel_catchup_request /2 ,
4646 is_catching_up /2
4747]).
8181
8282% % An entry in the catchup request ETS table representing a request to
8383% % trigger log catchup for a particular peer.
84- -define (CATCHUP_REQUEST (Peer , FollowerLastIndex , LeaderTerm , LeaderCommitIndex , Witness ), {Peer , FollowerLastIndex , LeaderTerm , LeaderCommitIndex , Witness }).
84+ -define (CATCHUP_REQUEST (Peer , FollowerLastIndex , LeaderTerm , LeaderCommitIndex ), {Peer , FollowerLastIndex , LeaderTerm , LeaderCommitIndex }).
8585
8686% % An entry in the catchup ETS table that indicates an in-progress log
8787% % catchup to the specified node.
@@ -116,9 +116,9 @@ start_link(#raft_options{log_catchup_name = Name} = Options) ->
116116
117117% % Submit a request to trigger log catchup for a particular follower starting at the index provided.
118118-spec start_catchup_request (Catchup :: atom (), Peer :: # raft_identity {}, FollowerLastIndex :: wa_raft_log :log_index (),
119- LeaderTerm :: wa_raft_log :log_term (), LeaderCommitIndex :: wa_raft_log :log_index (), Witness :: boolean () ) -> ok .
120- start_catchup_request (Catchup , Peer , FollowerLastIndex , LeaderTerm , LeaderCommitIndex , Witness ) ->
121- ets :insert (Catchup , ? CATCHUP_REQUEST (Peer , FollowerLastIndex , LeaderTerm , LeaderCommitIndex , Witness )),
119+ LeaderTerm :: wa_raft_log :log_term (), LeaderCommitIndex :: wa_raft_log :log_index ()) -> ok .
120+ start_catchup_request (Catchup , Peer , FollowerLastIndex , LeaderTerm , LeaderCommitIndex ) ->
121+ ets :insert (Catchup , ? CATCHUP_REQUEST (Peer , FollowerLastIndex , LeaderTerm , LeaderCommitIndex )),
122122 ok .
123123
124124% % Cancel a request to trigger log catchup for a particular follower.
@@ -206,8 +206,8 @@ handle_info(timeout, #state{name = Name} = State) ->
206206 {noreply , State , ? IDLE_TIMEOUT };
207207 Requests ->
208208 % Select a random log catchup request to process.
209- ? CATCHUP_REQUEST (Peer , FollowerLastIndex , LeaderTerm , LeaderCommitIndex , Witness ) = lists :nth (rand :uniform (length (Requests )), Requests ),
210- NewState = send_logs (Peer , FollowerLastIndex , LeaderTerm , LeaderCommitIndex , Witness , State ),
209+ ? CATCHUP_REQUEST (Peer , FollowerLastIndex , LeaderTerm , LeaderCommitIndex ) = lists :nth (rand :uniform (length (Requests )), Requests ),
210+ NewState = send_logs (Peer , FollowerLastIndex , LeaderTerm , LeaderCommitIndex , State ),
211211 % erlint-ignore garbage_collect
212212 erlang :garbage_collect (),
213213 {noreply , NewState , ? CONTINUE_TIMEOUT }
@@ -224,8 +224,8 @@ terminate(_Reason, #state{name = Name}) ->
224224% % Private functions - Send logs to follower
225225% %
226226
227- -spec send_logs (# raft_identity {}, wa_raft_log :log_index (), wa_raft_log :log_term (), wa_raft_log :log_index (), boolean (), # state {}) -> # state {}.
228- send_logs (Peer , NextLogIndex , LeaderTerm , LeaderCommitIndex , Witness , # state {name = Name , lockouts = Lockouts } = State ) ->
227+ -spec send_logs (# raft_identity {}, wa_raft_log :log_index (), wa_raft_log :log_term (), wa_raft_log :log_index (), # state {}) -> # state {}.
228+ send_logs (Peer , NextLogIndex , LeaderTerm , LeaderCommitIndex , # state {name = Name , lockouts = Lockouts } = State ) ->
229229 StartMillis = erlang :system_time (millisecond ),
230230 LockoutMillis = maps :get (Peer , Lockouts , 0 ),
231231 NewState = case LockoutMillis =< StartMillis of
@@ -235,7 +235,7 @@ send_logs(Peer, NextLogIndex, LeaderTerm, LeaderCommitIndex, Witness, #state{nam
235235 true ->
236236 counters :add (Counters , ? COUNTER_CONCURRENT_CATCHUP , 1 ),
237237 ets :insert (? MODULE , ? CATCHUP_RECORD (Name , Peer )),
238- try send_logs_impl (Peer , NextLogIndex , LeaderTerm , LeaderCommitIndex , Witness , State ) catch
238+ try send_logs_impl (Peer , NextLogIndex , LeaderTerm , LeaderCommitIndex , State ) catch
239239 T :E :S ->
240240 ? RAFT_COUNT ('raft.catchup.error' ),
241241 ? LOG_ERROR (" Catchup[~p , term ~p ] bulk logs transfer to ~0p failed with ~0p ~0p at ~p " ,
@@ -258,22 +258,15 @@ send_logs(Peer, NextLogIndex, LeaderTerm, LeaderCommitIndex, Witness, #state{nam
258258 ets :delete (? MODULE , Name ),
259259 NewState .
260260
261- -spec send_logs_impl (# raft_identity {}, wa_raft_log :log_index (), wa_raft_log :log_term (), wa_raft_log :log_index (), boolean (), # state {}) -> term ().
262- send_logs_impl (# raft_identity {node = PeerNode } = Peer , NextLogIndex , LeaderTerm , LeaderCommitIndex , Witness ,
261+ -spec send_logs_impl (# raft_identity {}, wa_raft_log :log_index (), wa_raft_log :log_term (), wa_raft_log :log_index (), # state {}) -> term ().
262+ send_logs_impl (# raft_identity {node = PeerNode } = Peer , NextLogIndex , LeaderTerm , LeaderCommitIndex ,
263263 # state {application = App , name = Name , self = Self , identifier = Identifier , distribution_module = DistributionModule , server_name = Server , log = Log } = State ) ->
264264 PrevLogIndex = NextLogIndex - 1 ,
265265 {ok , PrevLogTerm } = wa_raft_log :term (Log , PrevLogIndex ),
266266
267267 LogBatchEntries = ? RAFT_CATCHUP_MAX_ENTRIES_PER_BATCH (App ),
268- Entries = case Witness of
269- false ->
270- LogBatchBytes = ? RAFT_CATCHUP_MAX_BYTES_PER_BATCH (App ),
271- {ok , E } = wa_raft_log :get (Log , NextLogIndex , LogBatchEntries , LogBatchBytes ),
272- E ;
273- true ->
274- {ok , T } = wa_raft_log :get_terms (Log , NextLogIndex , min (LogBatchEntries , LeaderCommitIndex - NextLogIndex + 1 )),
275- [{Term , []} || Term <- T ]
276- end ,
268+ LogBatchBytes = ? RAFT_CATCHUP_MAX_BYTES_PER_BATCH (App ),
269+ {ok , Entries } = wa_raft_log :get (Log , NextLogIndex , LogBatchEntries , LogBatchBytes ),
277270
278271 case Entries of
279272 [] ->
@@ -287,7 +280,7 @@ send_logs_impl(#raft_identity{node = PeerNode} = Peer, NextLogIndex, LeaderTerm,
287280
288281 try wa_raft_server :parse_rpc (Self , DistributionModule :call (Dest , Identifier , Command , Timeout )) of
289282 {LeaderTerm , _ , ? APPEND_ENTRIES_RESPONSE (PrevLogIndex , true , FollowerEndIndex )} ->
290- send_logs_impl (Peer , FollowerEndIndex + 1 , LeaderTerm , LeaderCommitIndex , Witness , State );
283+ send_logs_impl (Peer , FollowerEndIndex + 1 , LeaderTerm , LeaderCommitIndex , State );
291284 {LeaderTerm , _ , ? APPEND_ENTRIES_RESPONSE (PrevLogIndex , false , _FollowerEndIndex )} ->
292285 exit (append_failed );
293286 {LeaderTerm , _ , Other } ->
0 commit comments