Comment by lanstin
3 years ago
Rename is totally atomic in a way that is simple to reason about. Ten processes try a rename to a per process name, and just one wins, even on an NFS.That one is free to do whatever and then rename back.
3 years ago
Rename is totally atomic in a way that is simple to reason about. Ten processes try a rename to a per process name, and just one wins, even on an NFS.That one is free to do whatever and then rename back.
Yes, rename is atomic, but that doesn't get you very far. For example, if you want to do a partial update to a file, you need to copy the file (you already need more storage), edit the file and then rename it. But then you can't do this between multiple processes because maybe you have copied the file while another process was already changing a different copy (but not yet renamed). And that's not even considering fsync, or supporting different Operating Systems.
Basic atomic filesystem operations support consensus numbers[0] 1 or 2 (via rename and RENAME_EXCHANGE, respectively), but for some concurrent algorithms one needs higher ones. File locks are the only way to get those (if we ignore IPC), and those APIs are a pain.
[0] https://en.wikipedia.org/wiki/Read%E2%80%93modify%E2%80%93wr...