Skip to content

Commit b8ff512

Browse files
patelarjavmeta-codesync[bot]
authored andcommitted
Add commit queue for low priority requests
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 separates the pending commit queue into two separate queues: one for each high priority requests, and one for low priority requests. In the current paradigm, we treat all requests as high priority, and this diff continues doing that. Reviewed By: jaher Differential Revision: D82855032 fbshipit-source-id: da9b19129d6c703d7a0a1d6d5b37d179eb176c68
1 parent 9158c77 commit b8ff512

File tree

3 files changed

+40
-31
lines changed

3 files changed

+40
-31
lines changed

include/wa_raft.hrl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,12 @@
142142
%% Maximum bytes of pending applies for any single RAFT partition
143143
-define(RAFT_MAX_PENDING_APPLY_BYTES, raft_max_pending_apply_bytes).
144144
-define(RAFT_MAX_PENDING_APPLY_BYTES(App), ?RAFT_APP_CONFIG(App, ?RAFT_MAX_PENDING_APPLY_BYTES, 32_000_000)).
145-
%% Maximum number of pending commits for any single RAFT partition
146-
-define(RAFT_MAX_PENDING_COMMITS, raft_max_pending_commits).
147-
-define(RAFT_MAX_PENDING_COMMITS(App), ?RAFT_APP_CONFIG(App, ?RAFT_MAX_PENDING_COMMITS, 1500)).
145+
%% Maximum number of pending high priority commits for any single RAFT partition
146+
-define(RAFT_MAX_PENDING_HIGH_PRIORITY_COMMITS, raft_max_pending_high_priority_commits).
147+
-define(RAFT_MAX_PENDING_HIGH_PRIORITY_COMMITS(App), ?RAFT_APP_CONFIG(App, ?RAFT_MAX_PENDING_HIGH_PRIORITY_COMMITS, 1500)).
148+
%% Maximum number of pending low priority commits for any single RAFT partition
149+
-define(RAFT_MAX_PENDING_LOW_PRIORITY_COMMITS, raft_max_pending_low_priority_commits).
150+
-define(RAFT_MAX_PENDING_LOW_PRIORITY_COMMITS(App), ?RAFT_APP_CONFIG(App, ?RAFT_MAX_PENDING_LOW_PRIORITY_COMMITS, 150)).
148151
%% Maximum number of pending reads for any single RAFT partition
149152
-define(RAFT_MAX_PENDING_READS, raft_max_pending_reads).
150153
-define(RAFT_MAX_PENDING_READS(App), ?RAFT_APP_CONFIG(App, ?RAFT_MAX_PENDING_READS, 5000)).

src/wa_raft_acceptor.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,11 @@ terminate(Reason, #state{name = Name}) ->
251251

252252
%% Enqueue a commit.
253253
-spec commit_impl(From :: gen_server:from(), Request :: op(), Priority :: priority(), State :: #state{}) -> continue | commit_error().
254-
commit_impl(From, {Key, _} = Op, _Priority, #state{name = Name, server = Server, queues = Queues}) ->
254+
commit_impl(From, {Key, _} = Op, Priority, #state{name = Name, server = Server, queues = Queues}) ->
255255
StartT = os:timestamp(),
256256
try
257257
?RAFT_LOG_DEBUG("Acceptor[~0p] starts to handle commit of ~0P from ~0p.", [Name, Op, 30, From]),
258-
case wa_raft_queue:commit_started(Queues) of
258+
case wa_raft_queue:commit_started(Queues, Priority) of
259259
commit_queue_full ->
260260
?RAFT_LOG_WARNING(
261261
"Acceptor[~0p] is rejecting commit request from ~0p because the commit queue is full.",

src/wa_raft_queue.erl

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
-export([
1414
queues/1,
1515
queues/2,
16-
commit_queue_size/1,
1716
commit_queue_size/2,
18-
commit_queue_full/1,
17+
commit_queue_size/3,
1918
commit_queue_full/2,
19+
commit_queue_full/3,
2020
apply_queue_size/1,
2121
apply_queue_size/2,
2222
apply_queue_byte_size/1,
@@ -35,7 +35,7 @@
3535

3636
%% PENDING COMMIT QUEUE API
3737
-export([
38-
commit_started/1,
38+
commit_started/2,
3939
commit_cancelled/3,
4040
commit_completed/3
4141
]).
@@ -85,15 +85,17 @@
8585
-define(RAFT_QUEUE_TABLE_OPTIONS, [named_table, public, {read_concurrency, true}, {write_concurrency, true}]).
8686

8787
%% Total number of counters for RAFT partition specfic counters
88-
-define(RAFT_NUMBER_OF_QUEUE_SIZE_COUNTERS, 4).
88+
-define(RAFT_NUMBER_OF_QUEUE_SIZE_COUNTERS, 5).
8989
%% Index into counter reference for counter tracking apply queue size
9090
-define(RAFT_APPLY_QUEUE_SIZE_COUNTER, 1).
9191
%% Index into counter reference for counter tracking apply total byte size
9292
-define(RAFT_APPLY_QUEUE_BYTE_SIZE_COUNTER, 2).
93-
%% Index into counter reference for counter tracking commit queue size
94-
-define(RAFT_COMMIT_QUEUE_SIZE_COUNTER, 3).
93+
%% Index into counter reference for counter tracking high priority commit queue size
94+
-define(RAFT_HIGH_PRIORITY_COMMIT_QUEUE_SIZE_COUNTER, 3).
95+
%% Index into counter reference for counter tracking low priority commit queue size
96+
-define(RAFT_LOW_PRIORITY_COMMIT_QUEUE_SIZE_COUNTER, 4).
9597
%% Index into counter reference for counter tracking read queue size
96-
-define(RAFT_READ_QUEUE_SIZE_COUNTER, 4).
98+
-define(RAFT_READ_QUEUE_SIZE_COUNTER, 5).
9799

98100
%%-------------------------------------------------------------------
99101
%% INTERNAL TYPES
@@ -129,33 +131,37 @@ queues(Table, Partition) ->
129131
Options -> queues(Options)
130132
end.
131133

132-
-spec commit_queue_size(Queues :: queues()) -> non_neg_integer().
133-
commit_queue_size(#queues{counters = Counters}) ->
134-
atomics:get(Counters, ?RAFT_COMMIT_QUEUE_SIZE_COUNTER).
134+
-spec commit_queue_size(Queues :: queues(), Priority :: wa_raft_acceptor:priority()) -> non_neg_integer().
135+
commit_queue_size(#queues{counters = Counters}, high) ->
136+
atomics:get(Counters, ?RAFT_HIGH_PRIORITY_COMMIT_QUEUE_SIZE_COUNTER);
137+
commit_queue_size(#queues{counters = Counters}, low) ->
138+
atomics:get(Counters, ?RAFT_LOW_PRIORITY_COMMIT_QUEUE_SIZE_COUNTER).
135139

136-
-spec commit_queue_size(wa_raft:table(), wa_raft:partition()) -> non_neg_integer().
137-
commit_queue_size(Table, Partition) ->
140+
-spec commit_queue_size(Table :: wa_raft:table(), Partition :: wa_raft:partition(), Priority :: wa_raft_acceptor:priority()) -> non_neg_integer().
141+
commit_queue_size(Table, Partition, Priority) ->
138142
case queues(Table, Partition) of
139143
undefined -> 0;
140-
Queue -> commit_queue_size(Queue)
144+
Queue -> commit_queue_size(Queue, Priority)
141145
end.
142146

143-
-spec commit_queue_full(Queues :: queues()) -> boolean().
144-
commit_queue_full(#queues{application = App, counters = Counters}) ->
145-
atomics:get(Counters, ?RAFT_COMMIT_QUEUE_SIZE_COUNTER) >= ?RAFT_MAX_PENDING_COMMITS(App).
147+
-spec commit_queue_full(Queues :: queues(), Priority :: wa_raft_acceptor:priority()) -> boolean().
148+
commit_queue_full(#queues{application = App, counters = Counters}, high) ->
149+
atomics:get(Counters, ?RAFT_HIGH_PRIORITY_COMMIT_QUEUE_SIZE_COUNTER) >= ?RAFT_MAX_PENDING_HIGH_PRIORITY_COMMITS(App);
150+
commit_queue_full(#queues{application = App, counters = Counters}, low) ->
151+
atomics:get(Counters, ?RAFT_LOW_PRIORITY_COMMIT_QUEUE_SIZE_COUNTER) >= ?RAFT_MAX_PENDING_LOW_PRIORITY_COMMITS(App).
146152

147-
-spec commit_queue_full(wa_raft:table(), wa_raft:partition()) -> boolean().
148-
commit_queue_full(Table, Partition) ->
153+
-spec commit_queue_full(Table :: wa_raft:table(), Partition :: wa_raft:partition(), Priority :: wa_raft_acceptor:priority()) -> boolean().
154+
commit_queue_full(Table, Partition, Priority) ->
149155
case queues(Table, Partition) of
150156
undefined -> false;
151-
Queues -> commit_queue_full(Queues)
157+
Queues -> commit_queue_full(Queues, Priority)
152158
end.
153159

154160
-spec apply_queue_size(Queues :: queues()) -> non_neg_integer().
155161
apply_queue_size(#queues{counters = Counters}) ->
156162
atomics:get(Counters, ?RAFT_APPLY_QUEUE_SIZE_COUNTER).
157163

158-
-spec apply_queue_size(wa_raft:table(), wa_raft:partition()) -> non_neg_integer().
164+
-spec apply_queue_size(Table :: wa_raft:table(), Partition :: wa_raft:partition()) -> non_neg_integer().
159165
apply_queue_size(Table, Partition) ->
160166
case queues(Table, Partition) of
161167
undefined -> 0;
@@ -219,17 +225,17 @@ registered_name(Table, Partition) ->
219225
%% PENDING COMMIT QUEUE API
220226
%%-------------------------------------------------------------------
221227

222-
-spec commit_started(Queues :: queues()) -> ok | apply_queue_full | commit_queue_full.
223-
commit_started(#queues{counters = Counters} = Queues) ->
224-
case commit_queue_full(Queues) of
228+
-spec commit_started(Queues :: queues(), Priority :: wa_raft_acceptor:priority()) -> ok | apply_queue_full | commit_queue_full.
229+
commit_started(#queues{counters = Counters} = Queues, Priority) ->
230+
case commit_queue_full(Queues, Priority) of
225231
true ->
226232
commit_queue_full;
227233
false ->
228234
case apply_queue_full(Queues) of
229235
true ->
230236
apply_queue_full;
231237
false ->
232-
PendingCommits = atomics:add_get(Counters, ?RAFT_COMMIT_QUEUE_SIZE_COUNTER, 1),
238+
PendingCommits = atomics:add_get(Counters, ?RAFT_HIGH_PRIORITY_COMMIT_QUEUE_SIZE_COUNTER, 1),
233239
?RAFT_GATHER('raft.acceptor.commit.request.pending', PendingCommits),
234240
ok
235241
end
@@ -238,13 +244,13 @@ commit_started(#queues{counters = Counters} = Queues) ->
238244

239245
-spec commit_cancelled(Queues :: queues(), From :: gen_server:from(), Reason :: wa_raft_acceptor:commit_error() | undefined) -> ok.
240246
commit_cancelled(#queues{counters = Counters}, From, Reason) ->
241-
atomics:sub(Counters, ?RAFT_COMMIT_QUEUE_SIZE_COUNTER, 1),
247+
atomics:sub(Counters, ?RAFT_HIGH_PRIORITY_COMMIT_QUEUE_SIZE_COUNTER, 1),
242248
Reason =/= undefined andalso gen_server:reply(From, Reason),
243249
ok.
244250

245251
-spec commit_completed(Queues :: queues(), From :: gen_server:from(), Reply :: term()) -> ok.
246252
commit_completed(#queues{counters = Counters}, From, Reply) ->
247-
atomics:sub(Counters, ?RAFT_COMMIT_QUEUE_SIZE_COUNTER, 1),
253+
atomics:sub(Counters, ?RAFT_HIGH_PRIORITY_COMMIT_QUEUE_SIZE_COUNTER, 1),
248254
gen_server:reply(From, Reply),
249255
ok.
250256

0 commit comments

Comments
 (0)