[ZODB-Dev] Adding attributes to a btree

Tim Peters tim at zope.com
Mon Oct 11 11:51:12 EDT 2004


[Thomas Güttler]
> If a conflict errors occurs in a btree, you get the oid if it.

That's true of conflict errors in general, not specific to BTrees or Buckets
(or TreeSets or Sets).

> AFAIK there is no way to get the container which holds the btree.

Correct.  For that matter, any number of other objects may point to a
specific BTree (Bucket, etc) -- the "the" in "the container" doesn't make
much sense.

> Is there a way to get all objects which reference a given oid?

That depends on the storage.  For FileStorage, ZODB trunk (under SVN) has a
new fsoids.py command-line tool for tracing all references to specified oids
in a .fs file.  That's for ZODB 3.4, and won't be backported, although it
works fine with FileStorages created by ZODBs in the 3.3, 3.2, and 3.1
lines.  Note that fsoids is expensive:  it has to read the entire content of
the FileStorage, including every object pickle in every revision of every
object.

> Is there a way add attributes to a btree?

Not short of subclassing, no.  If it's an OO tree, you could add reserved
(by you, for your purposes) names.  You could also, e.g., add a new OOBTree,
mapping the oid of a BTree to "its container" (whatever that means to you).

> If this would be possible, I could add a reference to the container,
> which holds this btree. I need this for debugging conflict errors.
>
> mybtree.myatt="foo" does not work, since BTrees are not written in
> python.

More precisely, BTrees don't support instance dicts.  Classes written in
Python need not support instance dicts either:

>>> class C(object):
...     __slots__ = ['a', 'b']
>>> c = C()
>>> c.a = 1
>>> c.b = 2
>>> c.c = 3
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'C' object has no attribute 'c'
>>>

Instance dicts are memory-intensive, so are avoided by building-block
classes.



More information about the ZODB-Dev mailing list