Permalink
Browse files

Add timeout on waiting for pooled connection

  • Loading branch information...
1 parent a71af6f commit 01e7df3c167683dede137242dae3878bafaf15ac @readams readams committed Jun 22, 2009
Showing with 12 additions and 3 deletions.
  1. +9 −1 clients/cpp/src/ConnectionPool.cpp
  2. +3 −2 clients/cpp/src/RoutedStore.cpp
@@ -17,6 +17,7 @@
* the License.
*/
+#include <voldemort/UnreachableStoreException.h>
#include "ConnectionPool.h"
#include <sstream>
@@ -59,13 +60,20 @@ shared_ptr<Connection>& ConnectionPool::checkout(const string& host, int port,
hep = host_entry_ptr(new host_entry());
host_ready_count = 0;
}
+
+ system_time const timeout =
+ get_system_time() +
+ posix_time::milliseconds(clientConfig->getConnectionTimeoutMs());
while ((host_ready_count == 0) &&
(((clientConfig->getMaxConnectionsPerNode() > 0) &&
(hep->size() >= (size_t)clientConfig->getMaxConnectionsPerNode())) ||
((clientConfig->getMaxTotalConnections() > 0) &&
(totalConnections >= clientConfig->getMaxTotalConnections())))) {
- checkinCond.wait(lock);
+ if (!checkinCond.timed_wait(lock, timeout)) {
+ throw VoldemortException("Timed out waiting "
+ "for pooled connection");
+ }
}
// Search for a ready connection to try
@@ -101,8 +101,9 @@ static bool doPutFromStore(const std::string& key,
node->setAvailable(true);
return true;
} catch (UnreachableStoreException& e) {
- cerr << "Setting node unavailable " << node->getId()
- << "because " << e.what() << endl;
+ /* XXX - TODO add logging */
+ cerr << "Setting node " << node->getId()
+ << " unavailable because: " << e.what() << endl;
node->setAvailable(false);
}
return false;

0 comments on commit 01e7df3

Please sign in to comment.