[ZODB-Dev] IOBtree Deletion... PLEASE HELP BEFORE I LOSE ALL MY HAIR

Tim Peters tim at zope.com
Fri May 7 15:51:54 EDT 2004


[M K]
> I have been having a difficult time with this for a
> long time now.  Basically, I have an IOBtree structure
> with an object that I cannot delete (or do anything
> else with for that matter!).
>
> This:  del self.data[123456] returns a key error on 123456.
>
> However, if I do this:
> def delete(self):
>   objs = []
>   for id in self.data.keys():
>     objs.append(id)

Just noting that those three lines are more easily written

    objs = list(self.data.keys())

>   return str(objs)
>
> It will return 123456 in the result.  Am I doing
> something stupid?  I have tried re-phrasing this in
> many ways, and just can't seem to get the object
> deleted.  THANKS FOR HELPING!!!!

This BTree is almost certainly internally damaged.  Diagnostic tools are
explained here:

    http://zope.org/Wikis/ZODB/FrontPage/guide/node6.html

in section 5.3.2, BTree Diagnostic Tools.

In short, do

    self.data._check()

and

    from BTrees.check import check
    check(self.data)

and I bet one of them will raise AssertionError, pointing to internal
inconsistency in the tree.

Over the years, there have been several distinct bugs in ZODB and in ZEO
that could cause internal BTree corruption.  I don't know of any such bugs
in the currently released versions, and haven't heard about one of these in
a long time.

The best way to repair the tree is usually to make a copy:

     self.data = IOBTree(self.data)

Under the covers, that traverses the BTree's "bucket links", which are least
likely to be damaged (the code you wrote above also traverses the bucket
links, and proves that 123456 *is* in some bucket; if the parent->child
links have gotten out of synch, though, then searching for keys may not find
them -- searching uses an entirely different set of links).




More information about the ZODB-Dev mailing list