List:MySQL++« Previous MessageNext Message »
From:Jonathan Wakely Date:December 22 2007 4:07pm
Subject:problems in ConnectionPool
View as plain text  
There are some problems with ConnectionPool:

1) in grab(), if the first unused connection found is older than
max_idle_time and there are no newer connections, it will be returned
to the user.  This patch fixes that by checking its age and creating a
new connection if too old.  This still isn't quite right though,
because if the first connection found is too old, but there is a newer
connection in the list, the first one will be ignored and left in the
list forever.  I have a work-in-progress which uses a functor and
std::for_each (or std::max_element) to iterate over the list,
remembering the best one to return, and a list of old connections that
should be freed after the loop finishes.

2) When you remove a connection from the pool_ list it seems to be
leaked.  My suggestion is to add a pure-virtual
ConnectionPool::destroy() which the derived class must implement to
free the connection.

3) last_used never seems to be updated.  The patch sets last_used to
time(0) when it is returned to the pool in release(), I'm not sure if
that's better than setting last_used in grab() instead.

I've also added a simple RAII class for locking/unlocking the mutex in
an exception-safe way.

Jon

Attachment: [text/x-patch] mysqlpp-cpool.patch
Thread
problems in ConnectionPoolJonathan Wakely22 Dec
  • Re: problems in ConnectionPoolJonathan Wakely22 Dec
    • Re: problems in ConnectionPoolJonathan Wakely22 Dec
  • Re: problems in ConnectionPoolWarren Young27 Dec
    • Re: problems in ConnectionPoolWarren Young27 Dec
      • Re: problems in ConnectionPoolJonathan Wakely27 Dec
        • Re: problems in ConnectionPoolWarren Young28 Dec
    • Re: problems in ConnectionPoolJonathan Wakely27 Dec
      • Re: problems in ConnectionPoolWarren Young3 Jan