[ZODB-Dev] ZEO + zodb: syncing required to keep multiple connections consistent?

Jason Bernardo jay at brontes3d.com
Thu Mar 2 11:50:31 EST 2006


Hello,

I'm trying to understand just how ZEO/zodb should work when there are
two connections open to the *same* database at the *same time* and one
connection updates an object in the database. If an object in the
database is modified from one of the connections, that modification is
*not* propogated to the second connection, unless a .sync() is performed
on the connection itself (or the connection is closed/reopened).

Is a sync actually required in a scenario such as this? Does normal
usage of multiple connections to the same database require that a sync
is performed in order to propogate changes between the two (or more)
connections and maintain consistency?

I'm unable to find sufficient documentation regarding this issue, or the
sync method itself (other than sync aborts any open transactions). What
I would like to know is if syncing is the normal procedure for keeping
multiple connections consistent, or I'm simply going about things in the
wrong way.

Below is a summary of python interactive shell commands that will
produce the issue which I'm trying to gather more information on:

This is generally how I connect to the DB
-----------------------------------------
>>> import ZEO, transaction, ZODB
>>> import ZODB.config
>>> import transaction
>>> from persistent.mapping import PersistentMapping
>>> db =
ZODB.config.databaseFromURL('/home/jay/sandbox/zope/zeo_client.conf')
>>> dbConnection = db.open()
>>> root = dbConnection.root()

Version!
--------
>>> ZEO.version
'2.3.1'

Zeo is started like so
----------------------
/usr/bin/python /usr/bin/runzeo.py -C ~/sandbox/zope/zeo_server.conf


The zeo_client.conf looks like this
-----------------------------------
<zodb>
    <zeoclient>
    server localhost:8090
    max-disconnect-poll 5
    </zeoclient>
</zodb>


zeo_server.conf looks like this
-------------------------------
<zeo>
    address 127.0.0.1:8090
</zeo>
<filestorage 1>
    path /home/jay/sandbox/zope/test.db2
</filestorage>
<eventlog>
    <logfile>
        path /home/jay/sandbox/zope/zeo.log
        format %(asctime)s %(message)s
    </logfile>
</eventlog>



The DB was initialized like so (it was initially nonexistant)
-------------------------------------------------------------
>>> t = transaction.begin()
>>> root['Test'] = PersistentMapping()
>>> t.commit()


Now, I connect to the database in two separate python shells.
There are two connections open to the same DB at this point.
I used the above connection method and do this in both shells.
The result is exactly the same...
-------------------------------------------------------------
>>> temp = root['Test']
>>> temp
{}

Now, In the first shell, I do this
----------------------------------
>>> t = transaction.begin()
>>> temp.update({1:'testing'})
>>> t.commit()
>>> temp
{1: 'testing'}

In the second, I do this
------------------------
>>> temp
{}

Note that nothing has been updated into my second connection
to the DB. Now, if I do a sync on the dbConnection....
------------------------------------------------------
>>> dbConnection.sync()
>>> temp
{1: 'testing'}

Magic. I now have the updated contents from the Test table
of the database. Is the sync required in order to update 
the second connection, or am I doing something incorrectly?

Thanks for your time, and let me know if you require any additional
information.

-Jay



More information about the ZODB-Dev mailing list