Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions src/osiris_replica_reader.erl
Original file line number Diff line number Diff line change
Expand Up @@ -327,27 +327,44 @@ code_change(_OldVsn, State, _Extra) ->
%%% Internal functions
%%%===================================================================

do_sendfile(#state{socket = Sock,
do_sendfile(#state{name = Name,
socket = Sock,
transport = Transport} = State) ->
ok = setopts(Transport, Sock, [{nopush, true}]),
do_sendfile0(State).
case setopts(Transport, Sock, [{nopush, true}]) of
ok ->
do_sendfile0(State);
{error, Err} ->
?DEBUG_(Name, "setopts nopush true err ~w", [Err]),
State
end.

do_sendfile0(State) ->
do_sendfile0(State, 100).

do_sendfile0(State0, 0) ->
receive
{'EXIT', _Pid, _Reason} = ExitMsg ->

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if this should be a more general "come up to breathe" kind of bit where we exit the send_file loop and resume it if there are no other messages to process.

self() ! ExitMsg,
State0
Comment on lines +345 to +348
after 0 ->
do_sendfile0(State0, 100)
end;
Comment on lines +341 to +351
do_sendfile0(#state{name = Name,
socket = Sock,
transport = Transport,
log = Log0} = State0) ->
log = Log0} = State0, N) ->
State = maybe_send_committed_chunk_id(State0),
case osiris_log:send_file(Sock, Log0) of
{ok, Log} ->
do_sendfile0(State#state{log = Log});
do_sendfile0(State#state{log = Log}, N - 1);
{error, _Err} ->
%% ignore return value here as we've already hit an error
%% and it is likely we'll get another one when setting opts
_ = setopts(Transport, Sock, [{nopush, false}]),
?DEBUG_(Name, "sendfile err ~w", [_Err]),
State;
{end_of_stream, Log} ->
ok = setopts(Transport, Sock, [{nopush, false}]),
_ = setopts(Transport, Sock, [{nopush, false}]),
State#state{log = Log}
end.

Expand Down
Loading