|
12 | 12 | -module(wa_raft_server). |
13 | 13 | -compile(warn_missing_spec_all). |
14 | 14 | -behaviour(gen_statem). |
| 15 | +-compile({inline, [require_valid_state/1]}). |
15 | 16 |
|
16 | 17 | %%------------------------------------------------------------------------------ |
17 | 18 | %% RAFT Server - OTP Supervision |
|
180 | 181 | -define(SERVER_LOG_PREFIX, "Server[~0p, term ~0p, ~0p] "). |
181 | 182 | -define(SERVER_LOG_FORMAT(Format), ?SERVER_LOG_PREFIX Format). |
182 | 183 |
|
183 | | --define(SERVER_LOG_ARGS(State, Data, Args), [(Data)#raft_state.name, (Data)#raft_state.current_term, State | Args]). |
| 184 | +-define(SERVER_LOG_ARGS(State, Data, Args), [(Data)#raft_state.name, (Data)#raft_state.current_term, require_valid_state(State) | Args]). |
184 | 185 |
|
185 | 186 | -define(SERVER_LOG_ERROR(Data, Format, Args), ?SERVER_LOG_ERROR(?FUNCTION_NAME, Data, Format, Args)). |
186 | 187 | -define(SERVER_LOG_ERROR(State, Data, Format, Args), ?RAFT_LOG_ERROR(?SERVER_LOG_FORMAT(Format), ?SERVER_LOG_ARGS(State, Data, Args))). |
@@ -594,6 +595,14 @@ bootstrap(Server, Position, Config, Data) -> |
594 | 595 | notify_complete(Server) -> |
595 | 596 | gen_statem:cast(Server, ?NOTIFY_COMPLETE_COMMAND()). |
596 | 597 |
|
| 598 | +%%------------------------------------------------------------------------------ |
| 599 | +%% RAFT Server - State Machine Implementation - Logging |
| 600 | +%%------------------------------------------------------------------------------ |
| 601 | + |
| 602 | +-spec require_valid_state(state()) -> state(). |
| 603 | +require_valid_state(State) -> |
| 604 | + State. |
| 605 | + |
597 | 606 | %%------------------------------------------------------------------------------ |
598 | 607 | %% RAFT Server - State Machine Implementation - General Callbacks |
599 | 608 | %%------------------------------------------------------------------------------ |
@@ -3036,8 +3045,9 @@ handle_heartbeat( |
3036 | 3045 | EntryCount = length(Entries), |
3037 | 3046 |
|
3038 | 3047 | ?RAFT_GATHER({raft, State, 'heartbeat.size'}, EntryCount), |
3039 | | - ?SERVER_LOG_DEBUG(State, Data0, "considering appending ~0p log entries in range ~0p to ~0p to log ending at ~0p.", |
3040 | | - [EntryCount, PrevLogIndex + 1, PrevLogIndex + EntryCount, wa_raft_log:last_index(View)]), |
| 3048 | + EntryCount =/= 0 andalso |
| 3049 | + ?SERVER_LOG_DEBUG(State, Data0, "considering appending ~0p log entries in range ~0p to ~0p to log ending at ~0p.", |
| 3050 | + [EntryCount, PrevLogIndex + 1, PrevLogIndex + EntryCount, wa_raft_log:last_index(View)]), |
3041 | 3051 |
|
3042 | 3052 | case append_entries(State, PrevLogIndex, PrevLogTerm, Entries, EntryCount, Data0) of |
3043 | 3053 | {ok, Accepted, NewMatchIndex, Data1} -> |
|
0 commit comments