Skip to content

Commit cc54084

Browse files
authored
Merge pull request #499 from rabbitmq/log-tweaks
Improve some multi line log messages.
2 parents d333e83 + 0a5307f commit cc54084

File tree

6 files changed

+24
-23
lines changed

6 files changed

+24
-23
lines changed

src/ra.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ start_cluster(System, [#{cluster_name := ClusterName} | _] = ServerConfigs,
444444
end, ServerConfigs),
445445
case Started of
446446
[] ->
447-
?ERR("ra: failed to form a new cluster ~w.~n "
447+
?ERR("ra: failed to form a new cluster ~w. "
448448
"No servers were successfully started.",
449449
[ClusterName]),
450450
{error, cluster_not_formed};
@@ -460,15 +460,15 @@ start_cluster(System, [#{cluster_name := ClusterName} | _] = ServerConfigs,
460460
case members(TriggeredId,
461461
length(ServerConfigs) * Timeout) of
462462
{ok, _, Leader} ->
463-
?INFO("ra: started cluster ~ts with ~b servers~n"
464-
"~b servers failed to start: ~w~nLeader: ~w",
463+
?INFO("ra: started cluster ~ts with ~b servers. "
464+
"~b servers failed to start: ~w. Leader: ~w",
465465
[ClusterName, length(ServerConfigs),
466466
length(NotStarted), NotStartedIds,
467467
Leader]),
468468
% we have a functioning cluster
469469
{ok, StartedIds, NotStartedIds};
470470
Err ->
471-
?WARN("ra: failed to form new cluster ~w.~n "
471+
?WARN("ra: failed to form new cluster ~w. "
472472
"Error: ~w", [ClusterName, Err]),
473473
_ = [force_delete_server(System, N) || N <- StartedIds],
474474
% we do not have a functioning cluster

src/ra_log.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ delete_everything(#?MODULE{cfg = #cfg{uid = UId,
11091109
catch
11101110
_:_ = Err ->
11111111
?WARN("ra_log:delete_everything/1 failed to delete "
1112-
"directory ~ts~n Error: ~p", [Dir, Err])
1112+
"directory ~ts. Error: ~p", [Dir, Err])
11131113
end,
11141114
ok.
11151115

src/ra_server.erl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
%% @hidden
77
-module(ra_server).
88

9+
-include_lib("stdlib/include/assert.hrl").
910
-include("ra.hrl").
1011
-include("ra_server.hrl").
1112

@@ -1160,6 +1161,7 @@ handle_follower(#append_entries_rpc{term = Term,
11601161
State00 = #{cfg := #cfg{log_id = LogId,
11611162
id = Id} = Cfg,
11621163
log := Log00,
1164+
commit_index := CommitIndex,
11631165
current_term := CurTerm})
11641166
when Term >= CurTerm ->
11651167
ok = incr_counter(Cfg, ?C_RA_SRV_AER_RECEIVED_FOLLOWER, 1),
@@ -1175,13 +1177,14 @@ handle_follower(#append_entries_rpc{term = Term,
11751177
case Entries of
11761178
[] ->
11771179
ok = incr_counter(Cfg, ?C_RA_SRV_AER_RECEIVED_FOLLOWER_EMPTY, 1),
1178-
LastIdx = ra_log:last_index_term(Log1),
1180+
{LastIdx, _} = ra_log:last_index_term(Log1),
11791181
Log2 = case Entries0 of
1180-
[] when element(1, LastIdx) > PLIdx ->
1182+
[] when LastIdx > PLIdx ->
11811183
%% if no entries were sent we need to reset
11821184
%% last index to match the leader
1183-
?DEBUG("~ts: resetting last index to ~b",
1184-
[LogId, PLIdx]),
1185+
?DEBUG("~ts: resetting last index to ~b from ~b in term ~b",
1186+
[LogId, PLIdx, LastIdx, Term]),
1187+
?assertNot(PLIdx =< CommitIndex),
11851188
{ok, L} = ra_log:set_last_index(PLIdx, Log1),
11861189
L;
11871190
_ ->
@@ -1218,7 +1221,6 @@ handle_follower(#append_entries_rpc{term = Term,
12181221
%% alternative where the WAL writes the last index, term
12191222
%% it wrote for each UID into an ETS table and query
12201223
%% this.
1221-
% Log = ra_log:reset_to_last_known_written(Log1),
12221224
Log = Log1,
12231225
{await_condition,
12241226
State1#{log => Log,
@@ -1249,7 +1251,7 @@ handle_follower(#append_entries_rpc{term = Term,
12491251
%% NB: this is the commit index before update
12501252
LastApplied = maps:get(last_applied, State00),
12511253
?INFO("~ts: term mismatch - follower had entry at ~b with term ~b "
1252-
"but not with term ~b~n"
1254+
"but not with term ~b. "
12531255
"Asking leader ~w to resend from ~b",
12541256
[LogId, PLIdx, OtherTerm, PLTerm, LeaderId, LastApplied + 1]),
12551257
% This situation arises when a minority leader replicates entries
@@ -1346,16 +1348,16 @@ handle_follower(#request_vote_rpc{term = Term, candidate_id = Cand,
13461348
LastIdxTerm = last_idx_term(State1),
13471349
case is_candidate_log_up_to_date(LLIdx, LLTerm, LastIdxTerm) of
13481350
true ->
1349-
?INFO("~ts: granting vote for ~w with last indexterm ~w"
1351+
?INFO("~ts: granting vote for ~w with last {index, term} ~w"
13501352
" for term ~b previous term was ~b",
13511353
[LogId, Cand, {LLIdx, LLTerm}, Term, CurTerm]),
13521354
Reply = #request_vote_result{term = Term, vote_granted = true},
13531355
State = update_term_and_voted_for(Term, Cand, State1),
13541356
{follower, State, [{reply, Reply}]};
13551357
false ->
13561358
?INFO("~ts: declining vote for ~w for term ~b,"
1357-
" candidate last log index term was: ~w~n"
1358-
" last log entry idxterm seen was: ~w",
1359+
" candidate last log {index, term} was: ~w "
1360+
" last log entry {index, term} is: ~w",
13591361
[LogId, Cand, Term, {LLIdx, LLTerm}, {LastIdxTerm}]),
13601362
Reply = #request_vote_result{term = Term, vote_granted = false},
13611363
{follower, update_term(Term, State1), [{reply, Reply}]}
@@ -2399,7 +2401,7 @@ process_pre_vote(FsmState, #pre_vote_rpc{term = Term, candidate_id = Cand,
23992401
TheirMacVer =< OurMacVer) ->
24002402
?DEBUG("~ts: granting pre-vote for ~w"
24012403
" machine version (their:ours:effective) ~b:~b:~b"
2402-
" with last indexterm ~w"
2404+
" with last {index, term} ~w"
24032405
" for term ~b previous term ~b",
24042406
[log_id(State0), Cand, TheirMacVer, OurMacVer, EffMacVer,
24052407
{LLIdx, LLTerm}, Term, CurTerm]),
@@ -2413,8 +2415,8 @@ process_pre_vote(FsmState, #pre_vote_rpc{term = Term, candidate_id = Cand,
24132415
start_election_timeout]};
24142416
false ->
24152417
?DEBUG("~ts: declining pre-vote for ~w for term ~b,"
2416-
" candidate last log index term was: ~w~n"
2417-
"Last log entry idxterm seen was: ~w",
2418+
" candidate last log {index, term} was: ~w "
2419+
"last log entry {index, term} seen is: ~w",
24182420
[log_id(State0), Cand, Term, {LLIdx, LLTerm}, LastIdxTerm]),
24192421
case FsmState of
24202422
follower ->

src/ra_server_sup_sup.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ delete_server_rpc(System, RaName) ->
171171
#{data_dir := _SysDir,
172172
names := #{log_meta := Meta,
173173
server_sup := SrvSup} = Names} ->
174-
?INFO("Deleting server ~w and its data directory.~n",
174+
?INFO("Deleting server ~w and its data directory.",
175175
[RaName]),
176176
%% TODO: better handle and report errors
177177
%% UId could be `undefined' here
@@ -201,7 +201,7 @@ delete_data_directory(Directory) ->
201201
ok
202202
catch
203203
_:_ = Err ->
204-
?WARN("ra: delete_server/1 failed to delete directory ~ts~n"
204+
?WARN("ra: delete_server/1 failed to delete directory ~ts. "
205205
"Error: ~p", [Directory, Err]),
206206
error
207207
end
@@ -218,7 +218,7 @@ delete_data_directory(Directory) ->
218218
remove_all(System) when is_atom(System) ->
219219
#{names := #{server_sup := Sup}} = ra_system:fetch(System),
220220
_ = [begin
221-
?DEBUG("ra: terminating child ~w in system ~ts~n", [Pid, System]),
221+
?DEBUG("ra: terminating child ~w in system ~ts", [Pid, System]),
222222
supervisor:terminate_child(Sup, Pid)
223223
end
224224
|| {_, Pid, _, _} <- supervisor:which_children(Sup)],

src/ra_system_recover.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ init([System]) ->
5959
ok ->
6060
ok
6161
catch C:E:S ->
62-
?ERROR("~s: ~s encountered during server recovery ~p~n "
62+
?ERROR("~s: ~s encountered during server recovery ~p. "
6363
"stack ~p",
6464
[?MODULE, C, E, S]),
6565
ok

test/ra_server_SUITE.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ follower_aer_5(_Config) ->
533533
%% next index
534534
Init = empty_state(3, n2),
535535
AER1 = #append_entries_rpc{term = 1, leader_id = N1, prev_log_index = 0,
536-
prev_log_term = 0, leader_commit = 10,
536+
prev_log_term = 0, leader_commit = 2,
537537
entries = [
538538
entry(1, 1, one),
539539
entry(2, 1, two),
@@ -555,7 +555,6 @@ follower_aer_5(_Config) ->
555555
?assertMatch(#append_entries_reply{next_index = 4,
556556
last_term = 1,
557557
last_index = 3}, M),
558-
% ct:pal("Effects ~p~n State: ~p", [Effects, State1]),
559558
ok.
560559

561560

0 commit comments

Comments
 (0)