[ZODB-Dev] Persistent sub-objects: noob question

Casey Duncan casey at zope.com
Sat Jan 17 23:18:59 EST 2004


On Sat, 17 Jan 2004 17:31:30 -0500
Paul Winkler <pw_lists at slinkp.com> wrote:

> Here's a noob ZODB question...
> in most of my apps to date I haven't had to worry
> about issues like this and zope makes them easy
> to ignore 
> 
> Given this class:
> 
> class Foo(Persistent):
>     def __init__(self):
>         self.bar = OOBTree()
> 
>     def store(self, key, value):
>         self.bar[value] = key
>         self._p_changed = 1  # redundant
> 
> The line I'm wondering about is the last one.
> I know it's not *useful* since I've only changed an OOBTree...
> But is it *harmless* to leave that line in? What exactly
> happens? I've been looking at Connection.py but I can't
> really see what happens:

As Jeremy pointed out this does cause self to be stored. One harm it
does cause is that it will always cause a write conflict if store() is
called on the same object in two concurrent transactions. Because Foo
has no conflict resolution, the conflict would not be resolved and would
abort one of the transactions. This essentially defeats the conflict
resolution OOBTrees provide, which would insulate you from write
conflicts in the majority of cases where store was called concurrently
with different keys.

So be aware the setting _p_changed unecessarily will cause needless
writes to the database and will reduce write concurrency unless you
provide custom conflict resolution. That is an exercise best avoided
unless absolutely necessary IMO.

-Casey



More information about the ZODB-Dev mailing list