9494-record (state , {
9595 % Acceptor service name
9696 name :: atom (),
97- % Table name
98- table :: wa_raft :table (),
99- % Partition number
100- partition :: wa_raft :partition (),
10197 % Server service name
102- server :: atom ()
98+ server :: atom (),
99+ % Queues handle
100+ queues :: wa_raft_queue :queues ()
103101}).
104102
105103% %-------------------------------------------------------------------
@@ -190,17 +188,16 @@ registered_name(Table, Partition) ->
190188% %-------------------------------------------------------------------
191189
192190-spec init (Options :: # raft_options {}) -> {ok , # state {}}.
193- init (# raft_options {table = Table , partition = Partition , acceptor_name = Name , server_name = Server }) ->
191+ init (# raft_options {table = Table , partition = Partition , acceptor_name = Name , server_name = Server } = Options ) ->
194192 process_flag (trap_exit , true ),
195193
196194 ? LOG_NOTICE (" Acceptor[~0p ] starting for partition ~0p /~0p " ,
197195 [Name , Table , Partition ], #{domain => [whatsapp , wa_raft ]}),
198196
199197 {ok , # state {
200198 name = Name ,
201- table = Table ,
202- partition = Partition ,
203- server = Server
199+ server = Server ,
200+ queues = wa_raft_queue :queues (Options )
204201 }}.
205202
206203-spec handle_call (read_request (), gen_server :from (), # state {}) -> {reply , read_result (), # state {}} | {noreply , # state {}};
@@ -242,12 +239,12 @@ terminate(Reason, #state{name = Name}) ->
242239
243240% % Enqueue a commit.
244241-spec commit_impl (From :: gen_server :from (), Request :: op (), State :: # state {}) -> continue | commit_error ().
245- commit_impl (From , {Key , _ } = Op , # state {table = Table , partition = Partition , server = Server , name = Name }) ->
242+ commit_impl (From , {Key , _ } = Op , # state {name = Name , server = Server , queues = Queues }) ->
246243 StartT = os :timestamp (),
247244 try
248245 ? LOG_DEBUG (" Acceptor[~0p ] starts to handle commit of ~0P from ~0p ." ,
249246 [Name , Op , 30 , From ], #{domain => [whatsapp , wa_raft ]}),
250- case wa_raft_queue :commit (Table , Partition , Key , From ) of
247+ case wa_raft_queue :commit (Queues , Key , From ) of
251248 duplicate ->
252249 ? LOG_WARNING (" Acceptor[~0p ] is rejecting commit request from ~0p because it has duplicate key ~0p ." ,
253250 [Name , From , Key ], #{domain => [whatsapp , wa_raft ]}),
@@ -273,12 +270,12 @@ commit_impl(From, {Key, _} = Op, #state{table = Table, partition = Partition, se
273270
274271% % Enqueue a strongly-consistent read.
275272-spec read_impl (gen_server :from (), command (), # state {}) -> continue | read_error ().
276- read_impl (From , Command , # state {name = Name , table = Table , partition = Partition , server = Server }) ->
273+ read_impl (From , Command , # state {name = Name , server = Server , queues = Queues }) ->
277274 StartT = os :timestamp (),
278275 ? LOG_DEBUG (" Acceptor[~p ] starts to handle read of ~0P from ~0p ." ,
279276 [Name , Command , 100 , From ], #{domain => [whatsapp , wa_raft ]}),
280277 try
281- case wa_raft_queue :reserve_read (Table , Partition ) of
278+ case wa_raft_queue :reserve_read (Queues ) of
282279 read_queue_full ->
283280 ? RAFT_COUNT ('raft.acceptor.strong_read.error.read_queue_full' ),
284281 ? LOG_WARNING (" Acceptor[~0p ] is rejecting read request from ~0p because the read queue is full." ,
0 commit comments