Date: Friday, February 9, 2007 @ 17:52:52
  Author: gilles
    Path: /cvsroot/carob/carob

Modified: include/Connection.hpp (1.85 -> 1.86) src/Connection.cpp (1.112
          -> 1.113)

Implemented synchronization + optimization of closeSocket() suggested by Marc: 
socket deletion is now done outside of concurrent calls path
Make use of this function in connectToNextController()


------------------------+
 include/Connection.hpp |    4 +++-
 src/Connection.cpp     |   43 ++++++++++++++++++++++++-------------------
 2 files changed, 27 insertions(+), 20 deletions(-)


Index: carob/include/Connection.hpp
diff -u carob/include/Connection.hpp:1.85 carob/include/Connection.hpp:1.86
--- carob/include/Connection.hpp:1.85   Tue Feb  6 19:53:06 2007
+++ carob/include/Connection.hpp        Fri Feb  9 17:52:52 2007
@@ -514,8 +514,10 @@
   bool                writeExecutedInTransaction;
   /** Transaction identifier */
   int64_t             transactionId;
-  /** Function-specific mutexes */
+  /** To get lock on connection, used by most functions */
   CriticalSection     connectionCS;
+  /** To get lock on socket-only, used for deleting the socket */
+  CriticalSection     socketCS;
   /**
    * Flag to check if a new transaction must be started before executing any
    * statement
Index: carob/src/Connection.cpp
diff -u carob/src/Connection.cpp:1.112 carob/src/Connection.cpp:1.113
--- carob/src/Connection.cpp:1.112      Fri Feb  9 17:19:34 2007
+++ carob/src/Connection.cpp    Fri Feb  9 17:52:52 2007
@@ -232,7 +232,7 @@
       logError(fctName, msg);
     //suspect failing controller
     controller_pool.forceControllerDown(connected_controller);
-    delete driverSocketPtr; driverSocketPtr = NULL;
+    closeSocket();
     // Recurse until no more controller
     connectToNextController();
   }
@@ -243,7 +243,7 @@
       logError(fctName, msg);
     //suspect failing controller
     controller_pool.forceControllerDown(connected_controller);
-    delete driverSocketPtr; driverSocketPtr = NULL;
+    closeSocket();
     // Recurse until no more controller
     connectToNextController();
   }
@@ -251,7 +251,7 @@
   {
     if (isInfoEnabled())
       logInfo(fctName, L"Virtual database down on controller " + 
static_cast<wstring>(connected_controller));
-    delete driverSocketPtr; driverSocketPtr = NULL;
+    closeSocket();
     controller_pool.setVdbDownOnController(connected_controller);
     throw;
   }
@@ -397,25 +397,30 @@
 {
   const wchar_t fctName[] = L"Connection::closeSocket";
 
-  if (isDebugEnabled())
-    logDebug(fctName, L"Closing system socket to controller " + 
static_cast<wstring>(connected_controller));
-
-  if (driverSocketPtr == NULL)
+  // this will allow delayed deletion: we will just set driverSocketPtr to NULL
+  // in a synchronized block, so concurrent calls will see this NULL and return
+  // asap. Effective deletion will be done outside the synchronized block
+  DriverSocket* toDelete = driverSocketPtr;
   {
-    if (isInfoEnabled())
-      logInfo(fctName, L"... was NULL (already closed)");
-    return;
+    LockScope ls(&socketCS);
+  
+    if (isDebugEnabled())
+      logDebug(fctName, L"Closing system socket to controller " + 
static_cast<wstring>(connected_controller));
+  
+    if (driverSocketPtr == NULL)
+    {
+      if (isInfoEnabled())
+        logInfo(fctName, L"... was NULL (already closed)");
+      return;
+    }
+    // will have to delete it but will do that outside synchronized block
+    toDelete = driverSocketPtr;
+    // it's dying, so hide it from anyone else
+    driverSocketPtr = NULL;
   }
-
-  const DriverSocket *toDelete = driverSocketPtr;
-
-  // it's dying, so hide it from anyone else
-  driverSocketPtr = NULL;
-
-  // FIXME: should we unregister it?
-  // system socket closing is done in this destructor
+  // Now we can call the destructor without slowing down concurrent calls
+  // The system socket closing is done in this destructor
   delete toDelete;
-
 }
 
 void Connection::setAutoCommit(bool autoCommitPrm)

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to