basho / bitcask

because you need another a key/value storage engine
1.28k stars 171 forks source link

File Open behaves differently between NIF and Erlang modes [JIRA: RIAK-2895] #251

Closed pyrrho closed 7 years ago

pyrrho commented 7 years ago

https://github.com/basho/bitcask/blob/develop/src/bitcask_file.erl#L133-L134 https://github.com/basho/bitcask/blob/develop/c_src/bitcask_nifs.c#L2314

In Erlang mode, calling file_open with [] as the FileOpts will result in [read, write, raw, binary] being passed to Erlang's file:open/2. As per the Erlang docs,

write The file is opened for writing. It is created if it does not exist.

In NIF mode, calling file_open with [] as the FileOps will result in O_RDWR | O_APPEND being passed into the open call. Without O_CREATE, O_RDWR will return enoent when attempting to open a file that does not exist.

The end result of this is that calling file_open/2 in Erlang mode will create a file if it doesn't exist, but calling it it in NIF mode it will not. This relates closely to #242.

bsparrow435 commented 7 years ago

Fixed by a1568aea4d8c2caabff7b987fb59fe57d02ecd39