[ZODB-Dev] ReadConflictError while re-indexing big fat index

Dieter Maurer dieter at handshake.de
Tue Aug 3 14:55:47 EDT 2004


sean.upton at uniontrib.com wrote at 2004-8-2 12:34 -0700:
> ...
>So is there any way to re-read the object based on it's new state after you
>catch the RCE and want to retry (outside the publisher machinery)?  I'm
>thinking something less complicated than "re-loading" an entire index.
>Let's say, just a simple content object gets invalidated.  What's the "right
>way" to reload in a scenario like this:
>
>app = Zope.app()
>retries = 0
>while 1:
>    try:
>        foo = app['foo'].__of__(app)
>        #another thread/client changes app.foo here
>        print foo.bar #raises RCE
>        break
>    except ReadConflictError:
>        retries += 1
>        #do something here to make the air safe to breath again?
>        if retries > 4: break

The "do something" must include a "transaction.abort()".

I remember however, that I had to add "_flush_invalidation" calls
in "abort" to force an abort to really reset the invalidation flags.
Hopefully, the current ZODB version does this, too.

Formerly, invalidations were usually flushed only when the connection
was opened or synced.

Alternatively, you can declare the object as "independent"
("def _p_independent(self): return True").
This will deactivate the invalidation check for those objects.

>Is there any way to get the new, consistent state for app.foo in the except
>block above, so that I'm not retrying in vain?  Will get_connection().sync()
>do the trick or is there something more?

It does work -- note that "sync" also aborts the current transaction.

-- 
Dieter


More information about the ZODB-Dev mailing list