[Zope3-checkins] CVS: Zope3/src/transaction - _transaction.py:1.1.2.17

Jeremy Hylton jeremy at zope.com
Mon Mar 22 12:19:40 EST 2004


Update of /cvs-repository/Zope3/src/transaction
In directory cvs.zope.org:/tmp/cvs-serv26421

Modified Files:
      Tag: jeremy-txn-branch
	_transaction.py 
Log Message:
Cleanup and several fixes for ZODB test failures.

Rename ObjectAdapter to MultiObjectResourceAdapter.

Add a do-nothing begin() method.  It probably needs to be fixed as the
comment describes.

If the object passed to register() doesn't have an _p_jar, just pass
it to join().

Don't look for a voted attribute on resource managers.  Instead, keep
a dict of the rms that have voted.

Change unexpected errors in _cleanup() to raise an exception for now.
XXX Not sure what should be done.


=== Zope3/src/transaction/_transaction.py 1.1.2.16 => 1.1.2.17 ===
--- Zope3/src/transaction/_transaction.py:1.1.2.16	Mon Mar 22 10:37:40 2004
+++ Zope3/src/transaction/_transaction.py	Mon Mar 22 12:19:39 2004
@@ -96,11 +96,16 @@
 class Transaction(object):
 
     def __init__(self, synchronizers, manager):
-        # List of resource managers, e.g. ObjectAdapters.
+        # List of resource managers, e.g. MultiObjectResourceAdapters.
         self._resources = []
         self._synchronizers = synchronizers or []
         self._manager = manager
-        self._adapters = {} # Connection/_p_jar -> ObjectAdapter[Sub]
+        # _adapters: Connection/_p_jar -> MultiObjectResourceAdapter[Sub]
+        self._adapters = {}
+        self._voted = {} # id(Connection) -> boolean, True if voted
+        # _voted and other dictionaries use the id() of the resource
+        # manager as a key, because we can't guess whether the actual
+        # resource managers will be safe to use as dict keys.
 
         # The user, description, and _extension attributes are accessed
         # directly by storages, leading underscore notwithstanding.
@@ -123,12 +128,18 @@
         self._resources.append(resource)
 
     def register(self, obj):
+        if not myhasattr(obj, "_p_jar"):
+            # A resource manager like TransactionalUndo that doesn't
+            # manage individual objects.  It doesn't need to be
+            # adapted.
+            self.join(obj)
+            return
         adapter = self._adapters.get(obj._p_jar)
         if adapter is None:
             if myhasattr(obj._p_jar, "commit_sub"):
-                adapter = ObjectAdapterSub(obj)
+                adapter = MultiObjectResourceAdapterSub(obj)
             else:
-                adapter = ObjectAdapter(obj)
+                adapter = MultiObjectResourceAdapter(obj)
             self._adapters[obj._p_jar] = adapter
             self.join(adapter)
         else:
@@ -136,6 +147,11 @@
             assert obj not in adapter.objects
             adapter.objects.append(obj)
 
+    def begin(self):
+        # If nothing has happened yet, it's fine.  Otherwise, abort
+        # this transaction and let the txn manager create a new one.
+        pass
+
     def commit(self, subtransaction=False):
         if not subtransaction and self._sub and self._resources:
             # This commit is for a top-level transaction that has
@@ -180,6 +196,7 @@
                 # call tpc_vote() for subtransaction commits.
                 for rm in L:
                     rm.tpc_vote(self)
+                    self._voted[id(rm)] = True
             for rm in L:
                 rm.tpc_finish(self)
         except:
@@ -189,7 +206,7 @@
     def _cleanup(self, L):
         # Called when an exception occurs during tpc_vote or tpc_finish.
         for rm in L:
-            if not rm.voted:
+            if id(rm) in self._voted:
                 rm.cleanup(self)
         for rm in L:
             if id(rm) in self._sub:
@@ -197,11 +214,13 @@
                     rm.abort_sub(self)
                 except Exception, err:
                     print err
+                    raise
             else:
                 try:
                     rm.tpc_abort(self)
                 except Exception, err:
                     print err
+                    raise
 
     def _getResourceManagers(self, subtransaction):
         L = []
@@ -292,7 +311,7 @@
 
 # XXX We need a better name for the adapters.
 
-class ObjectAdapter(object):
+class MultiObjectResourceAdapter(object):
     """Adapt the old-style register() call to the new-style join().
 
     With join(), a resource mananger like a Connection registers with
@@ -350,7 +369,7 @@
         if tb is not None:
             raise t, v, tb
 
-class ObjectAdapterSub(ObjectAdapter):
+class MultiObjectResourceAdapterSub(MultiObjectResourceAdapter):
     """Adapt resource managers that participate in subtransactions."""
 
     def commit_sub(self, txn):




More information about the Zope3-Checkins mailing list