[ZODB-Dev] Quick ZODB connection synch question

Shane Hathaway shane at zope.com
Mon Sep 29 10:01:14 EDT 2003


Nicholas Henke wrote:
> On Fri, 2003-09-26 at 15:17, Jeremy Hylton wrote:
> 
>>On Fri, 2003-09-26 at 15:05, John Belmonte wrote:
>>
>>>Dieter Maurer wrote:
>>>
>>>>The ZODB processes invalidation requests for a connection only
>>>>
>>>>  *  when the connection is opened
>>>>  
>>>>  *  when you commit or abort a transaction *AND* this transaction
>>>>     has at least one object modified from this connection (such
>>>>     that the connection is registered with the transaction)
>>>>
>>>>  *  you call "connection.sync".
>>>
>>>But the docs mention something about an asyncore main loop.  How does 
>>>that fit in?
>>
>>It has to do with invalidations sent by the ZEO server.   If you have an
>>asyncore mainloop running, invalidations will be handled automatically
>>as they are received.  If you app doesn't have a mainloop, then it won't
>>read those invalidations unless you explicitly call sync to read data
>>from the network; the invalidations will just pile up in the socket
>>buffer waiting for the app to read them.
> 
> 
> You know, I have heard this several times, but I still have yet to see a
> simple example for a non zope application. Is there a possibility one of
> y'all could 'show us the light' for a seemingly important ( and frankly
> much hidden ) issue ? I have done it, but am never sure it is done
> right.

Let's say you have connection A and connection B.  (It doesn't matter 
whether A and B are in the same process or on different continents.) 
Imagine you do the following with connection A:

 >>> A.root()["Test"] = 1
 >>> get_transaction().commit()

Connection B will not see this change until it commits a transaction or 
calls sync().  Here is what you should expect:

 >>> B.root()["Test"]
KeyError: 'Test'
 >>> B.sync()
 >>> B.root()["Test"]
1

Furthermore, you should not expect B to be updated implicitly at 
transaction boundaries unless some object in B actually got changed.

Now, Zope uses a little trick that avoids the need to calling sync(): it 
opens a database connection for every HTTP request.  The only pitfall of 
this trick is that if you don't also run an asyncore loop with ZEO, the 
database will not receive ZEO invalidations.  You'll only fall into this 
if you're using ZEO, you're not using sync(), and you're not using an 
asyncore loop.

HTH!

Shane




More information about the ZODB-Dev mailing list