[ZODB-Dev] Getting an up to date instance of a persistent object

Pascal Peregrina Pperegrina at Lastminute.com
Fri Jun 2 05:05:21 EDT 2006


Hi, sorry for late reply.

Below is a partial illustration of what I was saying earlier: in a given connection, just after a conn.sync(), if I access the _p_serial attribute of a persistent object and the object state is outdated, then the up to date state won't be loaded. But if I then access the _p_mtime attribute, the up to date state is loaded.

ZODB is a FileStorage hosted by a ZEO instance.

PYTHON1 and PYTHON2 are two python interpreters in interactive mode.
The below output is given in chronological order.

PYTHON1>>> import sys
PYTHON1>>> zope_home='/opt/pperegri/builds/F2.12/opt/Zope-2.8.6-final'
PYTHON1>>> instance_home='/opt/pperegri/builds/F2.12/instances/zope_rw'
PYTHON1>>> sys.path.append('%s/lib/python'%zope_home)
PYTHON1>>> import Zope2
PYTHON1>>> Zope2.configure('%s/etc/zcmd1.conf'%instance_home)
PYTHON1>>> app=Zope2.app()
... (Zope startup messages, etc)

PYTHON2>>> import sys
PYTHON2>>> zope_home='/opt/pperegri/builds/F2.12/opt/Zope-2.8.6-final'
PYTHON2>>> instance_home='/opt/pperegri/builds/F2.12/instances/zope_rw'
PYTHON2>>> sys.path.append('%s/lib/python'%zope_home)
PYTHON2>>> import Zope2
PYTHON2>>> Zope2.configure('%s/etc/zcmd2.conf'%instance_home)
PYTHON2>>> app=Zope2.app()
... (Zope startup messages, etc)

PYTHON1>>> from ZODB.utils import serial_repr
PYTHON1>>> root1=zcmd1.app

PYTHON2>>> from ZODB.utils import serial_repr
PYTHON2>>> root2=zcmd2.app

PYTHON1>>> serial_repr(root1._p_serial)
'0x0365dc001bf4f866'
PYTHON1>>> root1.test='titi'
PYTHON1>>> import transaction
PYTHON1>>> transaction.get().commit()
PYTHON1>>> serial_repr(root1._p_serial)
'0x0365dc94411ff877'
PYTHON1>>> serial_repr(root1._p_serial)

PYTHON2>>> serial_repr(root2._p_serial)
'0x0365dc001bf4f866'
PYTHON2>>> root2._p_jar.sync()
PYTHON2>>> serial_repr(root2._p_serial)
'0x0365dc001bf4f866'
PYTHON2>>> root2._p_mtime
1149238335.2636449
PYTHON2>>> serial_repr(root2._p_serial)
'0x0365dc94411ff877'

Pascal


-----Message d'origine-----
De : zodb-dev-bounces+pperegrina=lastminute.com at zope.org [mailto:zodb-dev-bounces+pperegrina=lastminute.com at zope.org] De la part de Dieter Maurer
Envoyé : jeudi 25 mai 2006 18:32
À : Pascal Peregrina
Cc : Federico Schwindt; Alejo Sanchez; zodb-dev at zope.org
Objet : Re: [ZODB-Dev] Getting an up to date instance of a persistent object

Pascal Peregrina wrote at 2006-5-24 09:57 +0100:
> ...
>I have a question regarding what triggers the reloading of an object
>state from ZODB (in order to set the most up to date one).

There is only one reason: that it is not in the cache or a ghost.

At transaction boundaries (and only there!) objects modified
in other connections are deactivated (ghosted).

> ...
>Say you have C1, a Connection, and you have already retrieved object O1
>(so O1 is in C1 cache).
>Then, O1 is modified by something (that uses a different Connection).
>
>When you reuse C1 and access O1, I would like to know what makes sure
>the O1 state is up to date.

Nothing, if the modification happened since the last transaction
boundary (or call to the connections "_setDB").

>Apparently, accessing O1._p_serial before anything else returns the old
>serial (so the latest state has not been set). I also tried C1.sync()
>(through O1._p_jar) before accessing O1._p_serial but I got same result.

This is strange -- and should not happen (in ZODB 3.4 or above).

>And apparently, accessing O1._p_mitme before anything else does return
>the latest mtime and then accessing O1._p_serial does return the latest
>serial (so the latest state has been set)

That sounds unbelievable...

>Is that right?

Almost surely not.

>What's the rule?

>From ZODB 3.4 on, objects modified in a foreign connections
are deactivated (ghosted) at transaction boundaries.

Objects not in the cache or ghosted are reloaded on access.

-- 
Dieter
_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev at zope.org
http://mail.zope.org/mailman/listinfo/zodb-dev


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************


More information about the ZODB-Dev mailing list