Re: MiddleKit Threading Error?

Roger Haase <crosseyedpenguin-/[email protected]> Wed, 22 Oct 2008 09:45:21 -0700 (PDT)
Newsgroups gmane.comp.python.webware
Message-ID <[email protected]>


--- On Sun, 10/19/08, Roger Haase <crosseyedpenguin-/[email protected]> wrote:

> From: Roger Haase <crosseyedpenguin-/[email protected]>
> Subject: MiddleKit Threading Error?
> To: webware-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> Date: Sunday, October 19, 2008, 3:46 PM
> I last reported this problem back on May 22, 2004.  I am not
> sure what I have been doing different lately, but I have
> encountered the problem on both my test system and my
> production system this past month.  I have never been able
> to reproduce this problem at will.  The problem last went
> away with some 0.8x or 0.9x release but has now occurred on
> 1.0RC1.
> 
> I think the problem is caused by:
>   1. a freshly started AppServer
>   2. a flurry of incoming transactions all trying to access
> a MySQL
> table that has not been accessed before.
> 
> I think I am hitting the problem because my application
> generates web pages with multiple embedded images that are
> served by the Webware application.  So accessing a web page
> may create a flurry of transactions, the first has to wait
> for a disk read, and the second transactions overruns it
> resulting in duplicate entries in the cache.
> 
> The abend occurs in MiddleKit/Run/MiddleObject in
> readStoreData at line 92:
>     assert len(cache) + 1 == len(row)
> 
> Per the fancy traceback, cache is equal to:
> [<unbound method Folder.setFileName>, 
> <unbound method Folder.setSurveyDate>, 
> <unbound method Folder.setLockUserId>, 
> <unbound method Folder.setPhotographer>, 
> <unbound method Folder.setComments>, 
> <unbound method Folder.setRootId>, 
> <unbound method Folder.setSiteId>, 
> <unbound method Folder.setNumberFiles>, 
> <unbound method Folder.setUpdatedBy>, 
> <unbound method Folder.setUpdateTime>, 
>    -- the problem is here, the fields repeat
> <unbound method Folder.setFileName>, 
> <unbound method Folder.setSurveyDate>, 
> <unbound method Folder.setLockUserId>, 
> <unbound method Folder.setPhotographer>, 
> <unbound method Folder.setComments>, 
> <unbound method Folder.setRootId>, 
> <unbound method Folder.setSiteId>, 
> <unbound method Folder.setNumberFiles>, 
> <unbound method Folder.setUpdatedBy>, 
> <unbound method Folder.setUpdateTime>]
> 
> And row is equal to:
> (96L, 
> 'MonumentNashRuin_AR-03-09-02-08', 
> datetime.date(2007, 2, 6),
>  2L, 
> 'RH, GH', 
> '', 
> 8L, 
> 94L, 
> 42L, 
> 2L, 
> datetime.datetime(2007, 9, 18, 12, 44, 3))
> 
> I think the solution is to insert a lock around the code
> that deals
> with loading the cache the first time a table is accessed.
> This is my diff from MiddleKit/Run/MiddleObject.py (probably
> hard to read because of the line wraps).
> 

Well, the previous solution worked for the failing transaction, but then I hit another problem on a flurry of 5 transactions that were generating PNG images.  The new problem occurred in the same area - MiddleKit/Run/MiddleObject.py method readStoreData on the line:
   assert 0, "attempted to refresh changed object ....

My revised solution is to put the lock at the beginning and end of the method.

--- C:\...\MiddleObject.py-revBASE.svn005.tmp.py	Tue Oct 21 08:41:35 2008
+++ C:...\MiddleObject.py	Tue Oct 21 08:36:16 2008
@@ -5,6 +5,9 @@
 from MiddleKit.Core.ObjRefAttr import ObjRefAttr
 from MiddleKit.Core.ListAttr import ListAttr
 
+import thread # 2002-08-21 rdh
+_cacheLock = thread.allocate_lock() # 2002-08-21 rdh
+
 try: # for Python < 2.2
 	object
 except NameError:
@@ -67,6 +70,7 @@
 		for the same object in order to "refresh the attributes"
 		from the persistent store.
 		"""
+		_cacheLock.acquire() # 2008-10-20 rdh
 		if self._mk_store:
 			assert self._mk_store is store, 'Cannot refresh data from a different store.'
 			if self._mk_changed and not self._mk_initing:
@@ -114,6 +118,7 @@
 		self._mk_initing = 0
 		self._mk_inStore = 1
 		self._mk_changed = 0  # setting the values above will have caused this to be set; clear it now.
+		_cacheLock.release() # 2008-10-20 rdh
 		return self

Roger Haase


      

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/