[ZODB-Dev] ZEO client cache tempfile oddness
Tim Peters
tim.peters at gmail.com
Thu Apr 5 19:41:28 EDT 2007
[Paul Winkler]
> Can somebody explain to me the intent of this dance?
> (from ZEO/cache.py):
The ZEO client cache is stored in a fixed-size disk file. When a ZEO
client needs to create this file for the first time, it's trying to
ensure there's enough space on disk for it at the start, and reserve
that disk space then, rather than risk dying with a "no space left on
device" error umpteen hours later. Alas, there is no portable way to
do so (the C standard says nothing about physical devices such as
disks).
> # Make sure the OS really saves enough bytes for the file.
> self.f.seek(self.maxsize - 1)
> self.f.write('x')
> self.f.truncate()
>
> The comment seems self-explanatory, except that I'm not sure what
> "saves" means. Does the behavior vary on different filesystems?
Yes.
> On ext3 at least, a colleague just confirmed that this call "succeeds"
> with self.maxsize ten times larger than the size of the filesystem.
> It doesn't actually use many blocks though:
Sounds like it optimizes for sparse files. Not all filesystems do.
If you care, the intent could probably be better served by changing
the code to write a junk byte at every (say) thousandth byte offset
throughout the file (at least one non-NUL byte per disk block). Alas,
there would still be no guarantee that there's actually enough space
on the physical disk to store it.
> $ stat foo.txt
> File: `foo.txt'
> Size: 1000000000002 Blocks: 88 IO Block: 4096 regular file
>
>
> Does this make future calls to self.f.write() faster somehow?
Doubt it, but hat wasn't the intent.
More information about the ZODB-Dev
mailing list