[Zope3-dev] Missing _truncate in FileStorage

Tim Peters tim@zope.com
Wed, 23 Jul 2003 16:35:48 -0400


[Marius Gedminas]
> I just got a strange error when trying to start Zope 3:
>
> 2003-07-23T18:17:11 WARNING zodb.storage.file Data.fs truncated,
> possibly due to damaged records at 560016 Traceback (most recent call
>   last): File "z3.py", line 67, in ?
>     run()

That's a problem.  The easiest way to proceed is to delete your Data.fs and
start over.  The relevant code comments say:

                # Hm, the data were truncated or the checkpoint flag
                # wasn't cleared.  They may also be corrupted, in
                # which case, we don't want to totally lose the data.

Because the code's attempt to recover from this problem didn't work, you're
probably going to continue getting the same complaint every time you try to
start Zope 3 (until you start over with a new Data.fs).

>   File "z3.py", line 63, in run
>     main(argv[1:])
>   File "/home/users/mg/Zope3/src/zope/app/process/main.py", line 56,
>     in main setup(args)
>   File "/home/users/mg/Zope3/src/zope/app/process/main.py", line 88,
>     in setup db = options.database.open()
>   File "/home/users/mg/Zope3/src/zodb/config.py", line 97, in open
>     return zodb.db.DB(section.storage.open(),
>   File "/home/users/mg/Zope3/src/zodb/config.py", line 126, in open
>     quota=self.config.quota)
>   File "/home/users/mg/Zope3/src/zodb/storage/file/main.py", line
>     138, in __init__ read_only=read_only)
>   File "/home/users/mg/Zope3/src/zodb/storage/file/format.py", line
>     224, in _read_index _truncate(self._file, self._file.name, pos)
> NameError: global name '_truncate' is not defined
>
>
> _truncate is called twice in zodb.storage.file.format, but never
> defined or imported.

That's a problem too, and one I know Jeremy has fixed at least once in some
other ZODB branch.  Jeremy's out of touch for a while, else I'm sure he
could fix it instantly (I'm not sure anyone else can -- I know I can't).  If
it's important to try to recover data in this Data.fs, you could try this:

A. Make a copy of Data.fs, in case the rest of this doesn't work.

B. Change line 224 of src/zodb/storage/file/format.py, from

                    _truncate(self._file, self._file.name, pos)
to
                    self._file.seek(pos)
                    self._file.truncate()