Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename atomicity is not enough #64

Open
socketpair opened this issue Jul 9, 2020 · 5 comments
Open

Rename atomicity is not enough #64

socketpair opened this issue Jul 9, 2020 · 5 comments

Comments

@socketpair
Copy link

http://stackoverflow.com/questions/3764822/how-to-durably-rename-a-file-in-posix

So, you need to open directory where file exists (O_DIRECOTRY), and fsync() it's FD after rename. If not, application may think that rename is durable, but on accidental reboot, old file may appear.

@davidhq
Copy link

davidhq commented Jan 2, 2021

Using this lib on a project to write program state in .json file between process restarts...

Very occasionally the state is empty on restart of the process (mostly when the entire device reboots suddenly .. or (not sure) when there's a program error)..

Anyway my question is: can 100% reliable atomic file writes be achieved (with this library or in general) on Unix-like systems... and on SD cards ..

This is happening when testing the nodejs process on RaspberryPies ... (file system on SD card)

Could your claim be related to the problem I'm experiencing?

It is also possible that the issue is elsewhere but I'm starting to debug at this side... first I want to be really sure that this library / approach does not have any edge cases...

@socketpair
Copy link
Author

socketpair commented Jan 2, 2021

@davidhq No, this is another issue. It's about possible revert of atomic rename on power loss.

F.Y.I. Atomic rename is NOT implemented on FAT32.

@davidhq
Copy link

davidhq commented Jan 2, 2021

Thank you... I use ext4 on all SD cards.

So I can be reasonably certain that the issue is elsewhere and no data loss is occuring because of failed atomic file renames?

@socketpair
Copy link
Author

@davidhq I don't know. Renames in Linux (in normal FS) are always atomic. Possibly this library does not handle errors from write and fsync. Possibly your storage stack ignores flushes, or report completion when flush is still not complete. Or your SD card is a crap (i.e. it reports flushes as complete, when they are not).

@davidhq
Copy link

davidhq commented Jan 13, 2021

Thank you for explaining! In the meantime I have figured out the most likely culprit and it's something else... a very subtle bug before data is written, I actually passed empty data by coincidence at some rare cases and when this was the last write before process exited, then the file was empty... :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants