Author: rfm
Date: Wed May 27 16:53:36 2015
New Revision: 38578

URL: http://svn.gna.org/viewcvs/gnustep?rev=38578&view=rev
Log:
connection pool enhancements

Modified:
    libs/sqlclient/trunk/ChangeLog
    libs/sqlclient/trunk/SQLClient.h
    libs/sqlclient/trunk/SQLClientPool.m

Modified: libs/sqlclient/trunk/ChangeLog
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/ChangeLog?rev=38578&r1=38577&r2=38578&view=diff
==============================================================================
--- libs/sqlclient/trunk/ChangeLog      (original)
+++ libs/sqlclient/trunk/ChangeLog      Wed May 27 16:53:36 2015
@@ -1,3 +1,11 @@
+2015-05-27 Richard Frith-Macdonald  <[email protected]>
+
+       * Postgres.m: bugfixes
+       * SQLClient.m: bugfix for finding oldest idle connection
+       * SQLClientPool.m: implement method to disconnect idle connections
+       in pool.  also check for clients being returned to pool while a
+       transaction is still in progress.
+
 2015-04-30 Richard Frith-Macdonald  <[email protected]>
 
        * Postgres.m:

Modified: libs/sqlclient/trunk/SQLClient.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.h?rev=38578&r1=38577&r2=38578&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.h    (original)
+++ libs/sqlclient/trunk/SQLClient.h    Wed May 27 16:53:36 2015
@@ -987,7 +987,7 @@
                     recordType: (id)rtype
                       listType: (id)ltype;
 
-/** Releases a lock previously obtained using -lockbeforeDate:
+/** Releases a lock previously obtained using -lockBeforeDate:
  */
 - (void) unlock;
 

Modified: libs/sqlclient/trunk/SQLClientPool.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClientPool.m?rev=38578&r1=38577&r2=38578&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClientPool.m        (original)
+++ libs/sqlclient/trunk/SQLClientPool.m        Wed May 27 16:53:36 2015
@@ -37,9 +37,15 @@
 #import        <Performance/GSCache.h>
 #import        "SQLClient.h"
 
-/** Connections idle for morew than this time are candidates for purging.
+/** Connections idle for more than this time are candidates for purging
+ * as long as there are at leas min connections open.
  */
-static NSTimeInterval   purgeTime = 10.0;
+static NSTimeInterval   purgeMinTime = 10.0;
+
+/** Connections idle for more than this time are candidates for purging
+ * even if the number of open connections is less than or equal to min.
+ */
+static NSTimeInterval   purgeAllTime = 300.0;
 
 @interface      SQLClient(Pool)
 - (void) _clearPool: (SQLClientPool*)p;
@@ -333,19 +339,26 @@
                 }
             }
         }
-      if (connected > min && nil != found
-        && [[found lastOperation] timeIntervalSinceNow] < -purgeTime)
-        {
-          NS_DURING
-            {
-              [found disconnect];
-              more = YES;
-            }
-          NS_HANDLER
-            {
-              NSLog(@"Error disconnecting client in pool: %@", localException);
-            }
-          NS_ENDHANDLER
+      if (nil != found)
+        {
+          NSTimeInterval        age;
+
+          age = -[[found lastOperation] timeIntervalSinceNow];
+          if (age > purgeAllTime
+            || (connected > min && age > purgeMinTime))
+            {
+              NS_DURING
+                {
+                  [found disconnect];
+                  more = YES;
+                }
+              NS_HANDLER
+                {
+                  NSLog(@"Error disconnecting client in pool: %@",
+                    localException);
+                }
+              NS_ENDHANDLER
+            }
         }
     }
   [self _unlock];
@@ -495,6 +508,8 @@
 
 - (BOOL) swallowClient: (SQLClient*)client
 {
+  BOOL  disconnected = NO;
+  BOOL  replaced = NO;
   BOOL  found = NO;
   int   index;
 
@@ -507,7 +522,24 @@
           found = YES;
         }
     }
+  if (YES == found && YES == [client isInTransaction])
+    {
+      if (YES == [client lockBeforeDate: nil])
+        {
+          disconnected = YES;
+          [client disconnect];
+          [client unlock];
+        }
+      else
+        {
+          replaced = YES;
+          c[index] = [[SQLClient alloc] initWithConfiguration: _config
+                                                         name: _name
+                                                         pool: self];
+        }
+    }
   [self _unlock];
+
   if (_debugging > 2)
     {
       if (YES == found)
@@ -519,6 +551,19 @@
           NSLog(@"%@ rejects %p", self, client);
         }
     }
+
+  if (YES == disconnected)
+    {
+      NSLog(@"ERROR: Disconnected client which was returned to pool"
+        @" while a transaction was in progress: %@", client);
+    }
+  else if (YES == replaced)
+    {
+      NSLog(@"ERROR: Replaced client which was returned to pool"
+        @" while a transaction was in progress: %@", client);
+      [client release];
+    }
+
   return found;
 }
 


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to