Skip to content

Commit 4cdc6d9

Browse files
committed
minor refactoring
1 parent 83966e1 commit 4cdc6d9

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/ra_log_segment_writer.erl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ handle_cast({truncate_segments, Who, {Name, _Range} = SegRef},
218218
?DEBUG("segment_writer in '~w': ~s for ~s took ~bms",
219219
[System, ?FUNCTION_NAME, Who, Diff]),
220220
case open_successor_segment(Seg, SegConf) of
221-
undefined ->
221+
enoent ->
222222
%% directory must have been deleted after the pivot
223223
%% segment was opened
224224
{noreply, State0};
@@ -450,7 +450,7 @@ append_to_segment(UId, Tid, {Idx, SeqIter} = Cur, Seg0, Closed, State) ->
450450
{error, full} ->
451451
% close and open a new segment
452452
case open_successor_segment(Seg0, State#state.segment_conf) of
453-
undefined ->
453+
enoent ->
454454
%% a successor cannot be opened - this is most likely due
455455
%% to the directory having been deleted.
456456
undefined;
@@ -505,7 +505,7 @@ open_successor_segment(CurSeg, SegConf) ->
505505
{error, enoent} ->
506506
%% the directory has been deleted whilst segments were being
507507
%% written
508-
undefined;
508+
enoent;
509509
{ok, Seg} ->
510510
Seg
511511
end.
@@ -522,7 +522,13 @@ open_file(Dir, SegConf) ->
522522
%% existing which could happen after server deletion
523523
case ra_log_segment:open(File, SegConf#{mode => append}) of
524524
{ok, Segment} ->
525-
Segment;
525+
case ra_log_segment:segref(Segment) of
526+
undefined ->
527+
Segment;
528+
_ ->
529+
%% has entries, open successor
530+
open_successor_segment(Segment, SegConf)
531+
end;
526532
{error, missing_segment_header} ->
527533
%% a file was created by the segment header had not been
528534
%% synced. In this case it is typically safe to just delete

src/ra_server.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,7 +2320,7 @@ promote_checkpoint(Index, #{log := Log0} = State) ->
23202320
-spec persist_last_applied(ra_server_state()) -> ra_server_state().
23212321
persist_last_applied(#{persisted_last_applied := PLA,
23222322
last_applied := LA} = State) when LA =< PLA ->
2323-
% if last applied is less than PL for some reason do nothing
2323+
% if last applied is less than or equal to PL do nothing
23242324
State;
23252325
persist_last_applied(#{last_applied := LastApplied,
23262326
cfg := #cfg{uid = UId} = Cfg} = State) ->
@@ -2881,7 +2881,6 @@ apply_to(ApplyTo, ApplyFun, Notifys0, Effects0,
28812881
erlang:system_time(millisecond) - LastTs
28822882
end,
28832883
%% due to machine versioning all entries may not have been applied
2884-
%%
28852884
FinalEffs = make_notify_effects(Notifys, lists:reverse(Effects)),
28862885
put_counter(Cfg, ?C_RA_SVR_METRIC_LAST_APPLIED, AppliedTo),
28872886
put_counter(Cfg, ?C_RA_SVR_METRIC_COMMIT_LATENCY, CommitLatency),

0 commit comments

Comments
 (0)