Remix.run Logo
nh2 3 days ago

> fsync doesn’t just sync the file’s data, it syncs every piece of metadata the file depends on: ... directory entry

Famously not, as the man page says.

It is also said later in the article:

> POSIX strictly requires a parent-directory fsync to make a newly created file’s existence durable.

So I'm not sure why the dirent sync is claimed earlier.

zbentley 2 days ago | parent | next [-]

I’m curious: what happens when a file and its metadata are fsync’d, but the dirent is not and the system loses power? If the file is brand new, does it show up as an orphan upon reboot, or is it just gone? Can you somehow access it by inode even if it’s not findable? Is this filesystem specific?

Is there something else weird that can happen if the file is not new, not unlinked, but changes are made that would alter the directory entry in it in some way?

thomas_fa 3 days ago | parent | prev [-]

Thanks for pointing it out the mistakes. We should make it clearer, when fsync an opened file descriptor, it would only sync its own metadata. To make it truly persistent, we need to issue another fsync for the directory fd, which would make it more expensive.

dezgeg 3 days ago | parent [-]

You don't need to do that for every write though. Only when the database file is created.

thomas_fa 3 days ago | parent [-]

Yes, especially for our object storage each putObject would need to create new entry for in the (data)name space which would need fsync for dir fd.