[ZODB-Dev] Use of fsync in FileStorage

Tim Peters tim at zope.com
Mon Jul 26 14:45:09 EDT 2004


[Jeremy Hylton]
> FileStorage calls flush() on the file after the tpc_vote(), which at
> least gets the data out of the application buffers into the os.  Then it
> calls sync() in tpc_finish() and truncate() in tpc_abort().  I've got no
> clear understanding of what these actually do in the face of power
> failures.

Well, for one thing, the index file is written after the fsync() call, so a
power outage between could leave the .index file not matching the .fs file.
I think the code tries to check for that when opening a FileStorage, though,
and rebuilds the index file from scratch if the last transaction isn't
reflected in the index file it reads up.

The index file write doesn't do fsync() at all, which may be a real (but
never reported) problem on bouncing Windows systems (only _commit()
convinces Windows to write anything to disk:

f = open('temp.dat', 'wb')
import os
size = 0
data = 'x' * 100000
while 1:
    f.write(data)
    f.flush()
    size += len(data)
    print size, os.path.getsize('temp.dat')

On WinXP Pro just now, that printed

100000 0
200000 0
...
37100000 0
37200000 37100000
37300000 37100000
...
51800000 37100000
51900000 51800000
52000000 51800000
...

Stick in an os.fsync() call too, and the sizes always match.).

> I don't believe this is a critical issue.

It is if it happens <wink>. 



More information about the ZODB-Dev mailing list