]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Added a mutex for the initial pool creation when
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 27 Dec 2008 18:45:41 +0000 (18:45 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 27 Dec 2008 18:45:41 +0000 (18:45 +0000)
using pool.manage(dbapi).  This prevents a minor
case of "dogpile" behavior which would otherwise
occur upon a heavy load startup.  [ticket:799]

CHANGES
lib/sqlalchemy/pool.py

diff --git a/CHANGES b/CHANGES
index d0c8ff1586413763c968135808c0199ae59e4e72..c919e9eddd7244b783e3e03deb3035802c564207 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -145,9 +145,6 @@ CHANGES
           mapper since it's not needed.
       
 - sql
-    - NullPool supports reconnect on failure behavior.
-      [ticket:1094]
-      
     - Columns can again contain percent signs within their
       names. [ticket:1256]
       
@@ -156,9 +153,6 @@ CHANGES
       __eq__().  If the object does not implement 
       __eq__() and mutable=True, a deprecation warning
       is raised.
-    
-    - Connection.invalidate() checks for closed status 
-      to avoid attribute errors. [ticket:1246]
       
     - Fixed the import weirdness in sqlalchemy.sql
       to not export __names__ [ticket:1215].
@@ -198,6 +192,20 @@ CHANGES
       LIMIT/OFFSET), you should also call self_group() 
       on it to apply parenthesis.
     
+      
+- engine/pool
+    
+    - Connection.invalidate() checks for closed status 
+      to avoid attribute errors. [ticket:1246]
+
+    - NullPool supports reconnect on failure behavior.
+      [ticket:1094]
+
+    - Added a mutex for the initial pool creation when
+      using pool.manage(dbapi).  This prevents a minor 
+      case of "dogpile" behavior which would otherwise
+      occur upon a heavy load startup.  [ticket:799]
+      
     - _execute_clauseelement() goes back to being 
       a private method.  Subclassing Connection
       is not needed now that ConnectionProxy 
index ee4fa01908195ce83947963c720a357bc27d8dab..1467a4f6b95932b2452c944c408a1f6a9bf04b8b 100644 (file)
@@ -865,7 +865,8 @@ class _DBProxy(object):
         self.params = params
         self.poolclass = poolclass
         self.pools = {}
-
+        self._create_pool_mutex = threading.Lock()
+        
     def close(self):
         for key in self.pools.keys():
             del self.pools[key]
@@ -881,10 +882,17 @@ class _DBProxy(object):
         try:
             return self.pools[key]
         except KeyError:
-            pool = self.poolclass(lambda: self.module.connect(*args, **params), **self.params)
-            self.pools[key] = pool
-            return pool
-
+            self._create_pool_mutex.acquire()
+            try:
+                if key not in self.pools:
+                    pool = self.poolclass(lambda: self.module.connect(*args, **params), **self.params)
+                    self.pools[key] = pool
+                    return pool
+                else:
+                    return self.pools[key]
+            finally:
+                self._create_pool_mutex.release()
+                
     def connect(self, *args, **params):
         """Activate a connection to the database.