Open nuno-faria opened 5 months ago
@nsaadouni - don't know if you've picked up on this PR, but is this something your team could look at?
Note that this is also I believe broken when using the erlang
bitcask io_mode
. It adds the o_sync
flag, when the mode supported in Erlang is to use sync
instead.
I think this is an issue dating back to when a bespoke version of the erlang VM was used within Riak that was patched to add support for o_sync
, but when the PR was accepted upstream the name was changed to sync
.
For a new user of bitcask, I think use of the nif
IO mode is questionable. Given the fact that native erlang file IO now uses dirty IO scheduling, it would seem to be obviously safer than using a bespoke nif without dirty-nif support.
Would be interesting to know what the current big users of bitcask actually use in production.
@martinsumner In our case, the main reason we chose the nif
mode was due to the warning provided in the most recent Riak documentation about Bitcask as the backend, stating that:
"Synchronous file I/O via o_sync is supported in Bitcask if io_mode is set to nif and is not supported in the erlang mode."
So we just relied on the nif
interface, later discovering the bug.
According to Riak's docs, using the POSIX C API to write files, together with the
o_sync
strategy, should result in synchronous data writes. However, when looking at the open file descriptors for the Bitcask data, we can see that only the.write.lock
files are opened with theO_SYNC
flag, e.g.:This means writes are still asynchronous, which could lead to data loss even after sending the reply to the client.
The reason for this is that while the
get_file_open_flags
C function adds theO_SYNC
to the bitmask, it replaces it when it receives anATOM_CREATE
option. The easiest fix is to simply add theo_sync
option to the end of the list atbitcask_fileops.erl:87
, to ensure that it always appears after thecreate
. Now the files are correctly opened with theO_SYNC
flag: