[native source] eid_creation_lock actually lock the eid connection creation and usage stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 11 Apr 2011 13:29:41 +0200
branchstable
changeset 7202 5b80f5ee61b5
parent 7201 52f5831400b2
child 7203 e0e802afa8e1
[native source] eid_creation_lock actually lock the eid connection creation and usage
cwvreg.py
server/sources/native.py
--- a/cwvreg.py	Mon Apr 11 13:28:59 2011 +0200
+++ b/cwvreg.py	Mon Apr 11 13:29:41 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
--- a/server/sources/native.py	Mon Apr 11 13:28:59 2011 +0200
+++ b/server/sources/native.py	Mon Apr 11 13:29:41 2011 +0200
@@ -282,7 +282,7 @@
         self._temp_table_data = {}
         # we need a lock to protect eid attribution function (XXX, really?
         # explain)
-        self._eid_creation_lock = Lock()
+        self._eid_cnx_lock = Lock()
         self._eid_creation_cnx = None
         # (etype, attr) / storage mapping
         self._storages = {}
@@ -835,27 +835,22 @@
         self.doexec(session, sql)
 
     def _create_eid_sqlite(self, session):
-        self._eid_creation_lock.acquire()
-        try:
+        with self._eid_cnx_lock:
             for sql in self.dbhelper.sqls_increment_sequence('entities_id_seq'):
                 cursor = self.doexec(session, sql)
             return cursor.fetchone()[0]
-        finally:
-            self._eid_creation_lock.release()
 
 
     def create_eid(self, session):
-        # lock needed to prevent 'Connection is busy with results for another command (0)' errors with SQLServer
-        self._eid_creation_lock.acquire()
-        try:
+        # lock needed to prevent 'Connection is busy with results for another
+        # command (0)' errors with SQLServer
+        with self._eid_cnx_lock:
             return self._create_eid()
-        finally:
-            self._eid_creation_lock.release()
 
     def _create_eid(self):
         # internal function doing the eid creation without locking.
         # needed for the recursive handling of disconnections (otherwise we
-        # deadlock on self._eid_creation_lock
+        # deadlock on self._eid_cnx_lock
         if self._eid_creation_cnx is None:
             self._eid_creation_cnx = self.get_connection()
         cnx = self._eid_creation_cnx