[Zodb-checkins] CVS: ZODB3/ZODB - Transaction.py:1.39.16.1

Jeremy Hylton jeremy@zope.com
Thu, 31 Oct 2002 16:33:10 -0500


Update of /cvs-repository/ZODB3/ZODB
In directory cvs.zope.org:/tmp/cvs-serv31189

Modified Files:
      Tag: ZODB3-deadlock-debug-branch
	Transaction.py 
Log Message:
Guarantee that jars are called in order.

The order of jars should match the order in which objects were
modified.  The first jar that is called is the jar of the first object
that was modified.

This is implemented by storing a 2-tuple in the jars variable and
using a helper function to create jarsv() instead of justing calling
values().


=== ZODB3/ZODB/Transaction.py 1.39 => 1.39.16.1 ===
--- ZODB3/ZODB/Transaction.py:1.39	Fri Sep 27 14:37:24 2002
+++ ZODB3/ZODB/Transaction.py	Thu Oct 31 16:33:09 2002
@@ -25,6 +25,18 @@
 # Flag indicating whether certain errors have occurred.
 hosed=0
 
+def get_jars_in_order(jars):
+    # make sure jarsv contains the jars in the order they
+    # were added
+    L = []
+    for jar, order in jars.values():
+        L.append((order, jar))
+    L.sort()
+    jarsv = []
+    for order, jar in L:
+        jarsv.append(jar)
+    return jarsv
+
 class Transaction:
     'Simple transaction objects for single-threaded applications.'
     user=''
@@ -191,12 +203,14 @@
         try:
             ncommitted = 0
             try:
+                # the values in jars will be 2-tuples containing a jar
+                # and an int, where the int indicates the order in
+                # which the jars were added.
                 ncommitted += self._commit_objects(objects, jars,
                                                    subtransaction, subj)
 
                 self._commit_subtrans(jars, subjars)
-
-                jarsv = jars.values()
+                jarsv = get_jars_in_order(jars)
                 for jar in jarsv:
                     if not subtransaction:
                         try:
@@ -218,7 +232,7 @@
                 # have to clean up.
                 exc_info = sys.exc_info()
                 if jarsv is None:
-                    jarsv = jars.values()
+                    jarsv = get_jars_in_order(jars)
                 self._commit_error(exc_info, objects, ncommitted,
                                    jarsv, subjars)
         finally:
@@ -234,7 +248,7 @@
             if j is not None:
                 i = id(j)
                 if not jars.has_key(i):
-                    jars[i] = j
+                    jars[i] = j, len(jars)
 
                     if subtransaction:
                         # If a jar does not support subtransactions,
@@ -264,7 +278,7 @@
             j = subjars.pop()
             i = id(j)
             if not jars.has_key(i):
-                jars[i] = j
+                jars[i] = j, len(jars)
             j.commit_sub(self)
 
     def _finish_one(self, jar):