Re: Zero length files - an alternative approach?

Theodore Tso
2009-03-30T14:07:23Z

On Mon, Mar 30, 2009 at 08:41:26AM -0400, Chris Mason wrote:
> >
> > Consider this scenario:
> >
> > 1. Create/write/close newfile
> > 2. Rename newfile to oldfile
>
> 2a. create oldfile again
> 2b. fsync oldfile
>
> > 3. Open/read oldfile. This must return the new contents.
> > 4. System crash and reboot before delayed allocation/flush complete
> > 5. Open/read oldfile. Old contents now returned.
> >
>
> What happens to the new generation of oldfile? We could insert
> dependency tracking so that we know the fsync of oldfile is supposed to
> also fsync the rename'd new file. But then picture a loop of operations
> doing renames and creating files in the place of the old one...that
> dependency tracking gets ugly in a hurry.

If there are any calls to link(2) to create hard links to oldfile or
newfile intermingled in this sequence, life also gets very
entertaining.

> Databases know how to do all of this, but filesystems don't implement
> most of the database transactional features.

Yep, we'd have to implement a rollback log to get this right, which
would also impact performance. My guess is that just aggressively
forcing out the data write before the rename() is going to cost less
in performance, and is certainly much easier to implement.

- Ted