[ZODB-Dev] Use of fsync in FileStorage

Tim Peters tim at zope.com
Mon Jul 26 21:49:51 EDT 2004


[Toby Dickenson]
...
> fsync alone is not sufficient. The easiest approach that is sufficent is
> to:
> 1. write the backup file content to a temporary file.
> 2. fflush, fsync
> 3. rename the temporary file to its proper filename.

Thanks!  That all makes sense, and I made this change for repozo.py in ZODB
3.3.  It's a little tricky because repozo uses both regular Python file
objects and gzip module file classes, and fsync'ing the latter requires a
dirty trick, so I'm reluctant to dump this into a bugfix release for 3.2
(assuming another one is ever made) in the absence of a reported problem.

> 4. for even nicer semantics, fsync the directory.

I punted on that one, primarily because there's no portable way to do it
(directories can't be opened "as files" on Windows).

> If the power is lost at any point, on recovery you will have either:
> a. A file with the right contents at the right directory location, or
> b. a temporary file that needs deleting.

I don't think leaving the temp file sitting around can do any harm.  If one
is there, repozo will simply overwrite it the next time a backup is done.
Its existence won't bother the "restore" half of repozo either.

> The optional step 4 guarantees that you always have good file if the
> power loss occurs after the backup process terminated.

Understood.



More information about the ZODB-Dev mailing list