iilyak commented on code in PR #5558:
URL: https://github.com/apache/couchdb/pull/5558#discussion_r2159296947
##########
src/couch_mrview/src/couch_mrview_index.erl:
##########
@@ -210,7 +215,17 @@ finish_update(State) ->
commit(State) ->
Header = {State#mrst.sig, couch_mrview_util:make_header(State)},
- couch_file:write_header(State#mrst.fd, Header).
+ ok = couch_file:sync(State#mrst.fd),
Review Comment:
Here is the implementation of
`write_header`](https://github.com/apache/couchdb/blob/4adf245b99d5ac2d8ff7f5f49821c4911c6d7688/src/couch/src/couch_file.erl#L435C1-L440C69)
```erlang
write_header(Fd, Data) ->
Bin = ?term_to_bin(Data),
Checksum = generate_checksum(Bin),
% now we assemble the final header binary and write to disk
FinalBin = <<Checksum/binary, Bin/binary>>,
ioq:call(Fd, {write_header, FinalBin}, erlang:get(io_priority)).
```
As you can see the call reaches the `couch_file`'s `gen_server` via `ioq`.
The
[`sync`](https://github.com/apache/couchdb/blob/4adf245b99d5ac2d8ff7f5f49821c4911c6d7688/src/couch/src/couch_file.erl#L301C1-L307C9)
doesn't go via `ioq`
```erlang
sync(Fd) ->
case gen_server:call(Fd, sync, infinity) of
ok ->
ok;
{error, Reason} ->
erlang:error({fsync_error, Reason})
end.
```
Here is what I propose
```erlang
commit_header(Fd, Data) ->
Bin = ?term_to_bin(Data),
Checksum = generate_checksum(Bin),
% now we assemble the final header binary and write to disk
FinalBin = <<Checksum/binary, Bin/binary>>,
ioq:call(Fd, {commit_header, FinalBin}, erlang:get(io_priority)).
...
handle_call({commit_header, _Bin}, From, #file{fd = Fd} = File) ->
sync(Fd),
Result = handle_call({write_header, Bin}, From, File),
sync(Fd),
Result;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]