Skip to content

Commit a2d6074

Browse files
patelarjavmeta-codesync[bot]
authored andcommitted
Push priority down into log provider append
Summary: The follow stack of diffs will implement priority requests (as per [this](https://docs.google.com/document/d/181je6C5Iwmi5Ckl87UPLOug2V0eLVp8jIM2DoDlWbpo/edit?tab=t.0#heading=h.9l8mmncnncc8) doc). --- This diff exposes `Priority` to a log provider's append method. It's a no-op for now. Reviewed By: jaher Differential Revision: D83006862 fbshipit-source-id: 46ce9e62fb0eafd3ca6ac434c0a88bddfa58cc9a
1 parent 83d92c8 commit a2d6074

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/wa_raft_log.erl

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
-export([
2121
append/2,
2222
try_append/2,
23+
try_append/3,
2324
check_heartbeat/3
2425
]).
2526

@@ -241,7 +242,7 @@
241242
%% make it difficult to append to the log without blocking, then
242243
%% the append should be skipped and 'skipped' returned. Otherwise,
243244
%% the same conditions as the 'strict' mode apply.
244-
-callback append(View :: view(), Entries :: [log_entry() | binary()], Mode :: strict | relaxed) ->
245+
-callback append(View :: view(), Entries :: [log_entry() | binary()], Mode :: strict | relaxed, Priority :: wa_raft_acceptor:priority()) ->
245246
ok | skipped | {error, Reason :: term()}.
246247

247248
%%-------------------------------------------------------------------
@@ -326,22 +327,27 @@ start_link(#raft_options{log_name = Name} = Options) ->
326327
{ok, NewView :: view()} | {error, Reason :: term()}.
327328
append(View, Entries) ->
328329
% eqwalizer:ignore - strict append cannot return skipped
329-
append(View, Entries, strict).
330+
append(View, Entries, strict, high).
330331

331332
%% Attempt to append new log entries to the end of the log if an append can be
332333
%% serviced immediately.
333334
-spec try_append(View :: view(), Entries :: [log_entry() | binary()]) ->
334335
{ok, NewView :: view()} | skipped | {error, Reason :: term()}.
335336
try_append(View, Entries) ->
336-
append(View, Entries, relaxed).
337+
try_append(View, Entries, high).
338+
339+
-spec try_append(View :: view(), Entries :: [log_entry() | binary()], Priority :: wa_raft_acceptor:priority()) ->
340+
{ok, NewView :: view()} | skipped | {error, Reason :: term()}.
341+
try_append(View, Entries, Priority) ->
342+
append(View, Entries, relaxed, Priority).
337343

338344
%% Append new log entries to the end of the log.
339-
-spec append(View :: view(), Entries :: [log_entry() | binary()], Mode :: strict | relaxed) ->
345+
-spec append(View :: view(), Entries :: [log_entry() | binary()], Mode :: strict | relaxed, Priority :: wa_raft_acceptor:priority()) ->
340346
{ok, NewView :: view()} | skipped | {error, Reason :: term()}.
341-
append(#log_view{last = Last} = View, Entries, Mode) ->
347+
append(#log_view{last = Last} = View, Entries, Mode, Priority) ->
342348
?RAFT_COUNT('raft.log.append'),
343349
Provider = provider(View),
344-
case Provider:append(View, Entries, Mode) of
350+
case Provider:append(View, Entries, Mode, Priority) of
345351
ok ->
346352
?RAFT_COUNT('raft.log.append.ok'),
347353
{ok, refresh_config(View#log_view{last = Last + length(Entries)})};

src/wa_raft_log_ets.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
%% RAFT log provider interface for writing new log data
2828
-export([
29-
append/3
29+
append/4
3030
]).
3131

3232
%% RAFT log provider interface for managing underlying RAFT log
@@ -141,8 +141,8 @@ config(#raft_log{name = Name}) ->
141141
%% RAFT log provider interface for writing new log data
142142
%%-------------------------------------------------------------------
143143

144-
-spec append(View :: wa_raft_log:view(), Entries :: [wa_raft_log:log_entry() | binary()], Mode :: strict | relaxed) -> ok.
145-
append(View, Entries, _Mode) ->
144+
-spec append(View :: wa_raft_log:view(), Entries :: [wa_raft_log:log_entry() | binary()], Mode :: strict | relaxed, Priority :: wa_raft_acceptor:priority()) -> ok.
145+
append(View, Entries, _Mode, _Priority) ->
146146
Name = wa_raft_log:log_name(View),
147147
Last = wa_raft_log:last_index(View),
148148
true = ets:insert(Name, append_decode(Last + 1, Entries)),

src/wa_raft_server.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2724,7 +2724,7 @@ commit_pending(#raft_state{log_view = View, pending_high = PendingHigh, pending_
27242724
[_ | _] ->
27252725
% If we have processed at least one new log entry
27262726
% with the given priority, we try to append to the log.
2727-
case wa_raft_log:try_append(View, Entries) of
2727+
case wa_raft_log:try_append(View, Entries, Priority) of
27282728
{ok, NewView} ->
27292729
% Add the newly appended log entries to the pending queue (which
27302730
% is kept in reverse order).

0 commit comments

Comments
 (0)