Comment by polyrand
3 years ago
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...