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

Offer durable file writing functions #87

Closed
nh2 opened this issue May 3, 2018 · 5 comments
Closed

Offer durable file writing functions #87

nh2 opened this issue May 3, 2018 · 5 comments

Comments

@nh2
Copy link

nh2 commented May 3, 2018

rio should offer file writing functions that are durable.

That involves fsync()ing the file itself after writing and before close(), and fsync()ing the directory that contains the file. It also involves failing hard on errors in fsync(), as retrying fsync has no effect.

Sources for fsyncing the directory:

See also:

Note it may not be possible to provide durable variants for all operating and file systems, but these functions should be as durable as they can be.

We should also discuss whether durability should be the default in writeFileBinary and writeFileUtf8.

In general, rio should expose durable and non-durable variants of file writing operations.

@nh2
Copy link
Author

nh2 commented May 3, 2018

We should also discuss whether durability should be the default in writeFileBinary and writeFileUtf8.

My personal take right now is safe defaults are better, even if they are much slower due to the fsyncs and moves.

And ideally the docs should point out things like "if you do not need durability, use this other function which is much faster".

Also relevant for atomic moves (and performance) is whether the source and target are on the safe file system (overwise the rename() is not atomic at all).

@snoyberg
Copy link
Collaborator

snoyberg commented May 4, 2018

The atomic move issue is probably the biggest question mark about this for me. AFAICT, the only way to reliably implement this is to create a temporary file in the same directory as the target file and then move it. However, in the case of program crashes/SIGKILLs/etc, there's a possibility that the file could be left behind, meaning that this change doesn't just trade performance for durability, but also introduces slight externally-visible semantic changes.

@nh2
Copy link
Author

nh2 commented May 4, 2018

I found another very useful thread that discusses these issues, and particular wheter fsync() after rename() is necessary (the answer there is yes):

@lehins
Copy link
Contributor

lehins commented Feb 24, 2020

Just stumbled on this ticket. It seems like it can be closed, no?

@snoyberg
Copy link
Collaborator

I think so

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

3 participants