[Zope] ZODB Conflict, Thunked_TM - PATCH

Brad Clements bkc@murkworks.com
Mon, 15 Jul 2002 13:15:37 -0400


On 15 Jul 2002 at 18:29, Dieter Maurer wrote:

> Brad Clements writes:

>  > I also use SQLDict, maintaining a pool of SQLDict instances (they're expensive to 
>  > create) in a Queue (stored in an external method)
>  > 


> I do not know SQLDict, but when it is a persistent object (or
> contains persistent objects), your approach can give strange
> errors because persistent objects read in one request are
> accessed in a different request and maybe in a different connection.

I believe the problem is how THUNKED_TM handles it's lock and changing it's instance 
variables. Plus, TM.TM is now using _finalize and THUNKED_TM knows nothing about 
it.

Here's my suggested patch for THUNKED_TM, which *appears* to have resolved the 
issue. Ideally, however, I want only one DB instance shared between ALL threads, 
rather than only "one active instance" which is what THUNKED_TM gets me. (I actually 
get one DB for each thread, which means one database connection per thread, which 
isn't really safe with Interbase)

*** /usr/local/Zope/Zope-2.5.1-linux2-x86/lib/python/Shared/DC/ZRDB/THUNK.py	
Wed Nov 28 10:51:13 2001
--- THUNK.py	Mon Jul 15 13:16:58 2002
***************
*** 22,46 ****
      def _register(self):
          if not self._registered:
              thunk_lock.acquire()
!             try:
!                 get_transaction().register(Surrogate(self))
!                 self._begin()
!             except:
!                 thunk_lock.release()
!                 raise
!             else:
!                 self._registered=1
      
      def tpc_finish(self, *ignored):
!         if self._registered:
              try: self._finish()
              finally:
-                 thunk_lock.release()
                  self._registered=0
  
      def abort(self, *ignored):
-         if self._registered:
              try: self._abort()
              finally:
-                 thunk_lock.release()
                  self._registered=0
--- 22,40 ----
      def _register(self):
          if not self._registered:
              thunk_lock.acquire()
!             TM.TM._register(self)
      
      def tpc_finish(self, *ignored):
!         if self._finalize:
              try: self._finish()
              finally:
                  self._registered=0
+                 thunk_lock.release()
  
      def abort(self, *ignored):
          try: self._abort()
          finally:
              self._registered=0
+             thunk_lock.release()
+ 
+     tpc_abort = abort   # match what's in TM.TM




Brad Clements,                bkc@murkworks.com   (315)268-1000
http://www.murkworks.com                          (315)268-9812 Fax
AOL-IM: BKClements