[Zodb-checkins] CVS: ZODB4/src/zodb - serialize.py:1.21 db.py:1.17 connection.py:1.33

Jeremy Hylton jeremy at zope.com
Tue May 20 16:07:25 EDT 2003


Update of /cvs-repository/ZODB4/src/zodb
In directory cvs.zope.org:/tmp/cvs-serv19336/zodb

Modified Files:
	serialize.py db.py connection.py 
Log Message:
Refactor persistence api to use _p_changed only to mark an object as changed.

Use _p_deactivate() to turn an object into a ghost, and use the
keyword argument force=1 if you want to turn a modified object into a
ghost.  Several occurrences of the old interface have been updated.

This refactoring uncovered a number of subtle bugs in the persistence
C API.  The two chief problems were that the load function in the C
API struct did not set the state and that the functions return 0 for
error and 1 for success.  Regardless of whether these APIs are doing
the right thing, fix the code to use them correctly.

One downside of the new API is the C objects (BTrees) that override
_p_deactivate() have to deal with all the cruft for keyword
arguments.  Since BTrees only add a single line of extra code to
_p_deactivate(), it seems useful to provide a hook in the persistence
framework for this purpose.

Also:

If an object is in the changed state, don't call register() on its
data manager a second time.

Ignore state changes that result from setstate() being called.

Don't load an object's state to call __setstate__().

In BTrees check module, if an object has an oid, print that along with
its id().



=== ZODB4/src/zodb/serialize.py 1.20 => 1.21 ===
--- ZODB4/src/zodb/serialize.py:1.20	Wed Apr 16 18:06:20 2003
+++ ZODB4/src/zodb/serialize.py	Tue May 20 15:07:24 2003
@@ -273,7 +273,10 @@
             # XXX should be done by connection
             obj._p_oid = oid
             obj._p_jar = self._conn
-            obj._p_changed = None
+            # When an object is created, it is put in the UPTODATE
+            # state.  We must explicitly deactivate it to turn it into
+            # a ghost.
+            obj._p_deactivate()
 
             self._cache.set(oid, obj)
             return obj


=== ZODB4/src/zodb/db.py 1.16 => 1.17 ===
--- ZODB4/src/zodb/db.py:1.16	Thu May  1 15:34:58 2003
+++ ZODB4/src/zodb/db.py	Tue May 20 15:07:24 2003
@@ -169,6 +169,8 @@
             assert version == connection._version
             version = connection._version
 
+        self.log.debug("invalidate %s" % oids)
+
         # Notify connections
         for cc in self._allocated:
             if cc is not connection:


=== ZODB4/src/zodb/connection.py 1.32 => 1.33 ===
--- ZODB4/src/zodb/connection.py:1.32	Thu May  1 15:34:58 2003
+++ ZODB4/src/zodb/connection.py	Tue May 20 15:07:24 2003
@@ -46,6 +46,7 @@
 from zodb.conflict import ResolvedSerial
 from zodb.export import ExportImport
 from zodb.interfaces import *
+from zodb.interfaces import _fmt_oid
 from zodb.serialize import ConnectionObjectReader, ObjectWriter
 from zodb.storage.base import splitrefs
 from zodb.utils import u64, Set
@@ -148,9 +149,11 @@
 
         obj._p_oid = oid
         obj._p_jar = self
-        obj._p_changed = None # make sure it is a ghost
+        # When an object is created, it is put in the UPTODATE state.
+        # We must explicitly deactivate it to turn it into a ghost.
+        obj._p_deactivate()
         obj._p_serial = serial
-
+        
         self._cache.set(oid, obj)
         if oid == ZERO:
             # Keep a reference to the root so that the pickle cache
@@ -235,6 +238,7 @@
 
     def register(self, obj):
         assert obj._p_jar is self and obj._p_oid is not None
+        self._log.debug("register oid=%s" % _fmt_oid(obj._p_oid))
         if not self._registered:
             self._get_transaction().join(self)
         self._registered.add(obj)
@@ -417,7 +421,7 @@
             if obj is None:
                 return
             if serial == ResolvedSerial:
-                obj._p_changed = None
+                obj._p_deactivate()
             else:
                 if change:
                     obj._p_changed = 0
@@ -430,7 +434,7 @@
                 if obj is None:
                     continue
                 if serial == ResolvedSerial:
-                    obj._p_changed = None
+                    obj._p_deactivate()
                 else:
                     if change:
                         obj._p_changed = 0
@@ -438,13 +442,14 @@
 
     def _objcommit(self, obj, transaction):
         oid = obj._p_oid
-        self._log.debug("commit object %s", u64(oid))
+        self._log.debug("commit object %s", _fmt_oid(oid))
 
         if obj._p_changed:
             self._modified.add(oid)
         else:
             # The object reverted to the up-to-date state after
             # registering.
+            self._log.info("object not modified %s", _fmt_oid(oid))
             return
 
         writer = ObjectWriter(self)
@@ -462,7 +467,7 @@
         else:
             # Make a quick check against the invalidated set, because
             # pickling is expensive.  Catching a conflict here will
-            # be much faster than catching in the store call.
+            # be much faster than catching it in the store call.
             self._inv_lock.acquire()
             try:
                 if (oid in self._invalidated and




More information about the Zodb-checkins mailing list