summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDwight <dmerriman@gmail.com>2008-11-03 20:44:31 -0500
committerDwight <dmerriman@gmail.com>2008-11-03 20:44:31 -0500
commitc8315736840386d64e1e42ceb32b595446355618 (patch)
tree3fde9286e865458497c0fe7d186ac9862cbede3c
parenta4968427e2eeec59f60c6f72a82d15ddd521347c (diff)
parent45d9d8db480c712d562900de3358788a8b12beff (diff)
downloadmongo-c8315736840386d64e1e42ceb32b595446355618.tar.gz
Merge branch 'master' of ssh://git.10gen.com/data/gitroot/p
Conflicts: db/makefile
-rw-r--r--client/connpool.cpp (renamed from dbgrid/connpool.cpp)61
-rw-r--r--client/connpool.h (renamed from dbgrid/connpool.h)11
-rw-r--r--db/makefile2
-rw-r--r--dbgrid/dbgrid.cpp2
-rw-r--r--dbgrid/dbgrid.vcproj36
-rw-r--r--dbgrid/dbgrid_commands.cpp2
-rw-r--r--dbgrid/gridconfig.cpp2
-rw-r--r--dbgrid/griddb.cpp2
-rw-r--r--dbgrid/request.cpp2
9 files changed, 65 insertions, 55 deletions
diff --git a/dbgrid/connpool.cpp b/client/connpool.cpp
index eed74bfe52e..d997aa49e2d 100644
--- a/dbgrid/connpool.cpp
+++ b/client/connpool.cpp
@@ -1,4 +1,5 @@
-// connpool.cpp
+/* connpool.cpp
+*/
/**
* Copyright (C) 2008 10gen Inc.
@@ -14,32 +15,32 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-// _ todo: reconnect?
-
-#include "stdafx.h"
-#include "connpool.h"
-
-DBConnectionPool pool;
-
-DBClientConnection* DBConnectionPool::get(const string& host) {
- boostlock L(poolMutex);
-
- PoolForHost *&p = pools[host];
- if( p == 0 )
- p = new PoolForHost();
- if( p->pool.empty() ) {
- string errmsg;
- DBClientConnection *c = new DBClientConnection();
- if( !c->connect(host.c_str(), errmsg) ) {
- delete c;
- uassert("dbconnectionpool: connect failed", false);
- return 0;
- }
- return c;
- }
- DBClientConnection *c = p->pool.front();
- p->pool.pop();
- return c;
-}
+*/
+
+// _ todo: reconnect?
+
+#include "stdafx.h"
+#include "connpool.h"
+
+DBConnectionPool pool;
+
+DBClientConnection* DBConnectionPool::get(const string& host) {
+ boostlock L(poolMutex);
+
+ PoolForHost *&p = pools[host];
+ if( p == 0 )
+ p = new PoolForHost();
+ if( p->pool.empty() ) {
+ string errmsg;
+ DBClientConnection *c = new DBClientConnection();
+ if( !c->connect(host.c_str(), errmsg) ) {
+ delete c;
+ uassert("dbconnectionpool: connect failed", false);
+ return 0;
+ }
+ return c;
+ }
+ DBClientConnection *c = p->pool.front();
+ p->pool.pop();
+ return c;
+}
diff --git a/dbgrid/connpool.h b/client/connpool.h
index de79781128b..6a4b5d92f00 100644
--- a/dbgrid/connpool.h
+++ b/client/connpool.h
@@ -19,7 +19,7 @@
#pragma once
#include <queue>
-#include "../client/dbclient.h"
+#include "dbclient.h"
struct PoolForHost {
queue<DBClientConnection*> pool;
@@ -29,6 +29,8 @@ class DBConnectionPool {
boost::mutex poolMutex;
map<string,PoolForHost*> pools;
public:
+
+ /* generally, use ScopedDbConnection and do not call these directly */
DBClientConnection *get(const string& host);
void release(const string& host, DBClientConnection *c) {
boostlock L(poolMutex);
@@ -38,7 +40,7 @@ public:
extern DBConnectionPool pool;
-/* create these to get a connection from the pool. then on exceptions things
+/* Use to get a connection from the pool. On exceptions things
clean up nicely.
*/
class ScopedDbConnection {
@@ -51,6 +53,9 @@ public:
ScopedDbConnection(const string& _host) :
host(_host), _conn( pool.get(_host) ) { }
+ /* Call this when you are done with the ocnnection.
+ Why? See note in the destructor below.
+ */
void done() {
if( _conn->isFailed() )
delete _conn;
@@ -64,7 +69,7 @@ public:
/* you are supposed to call done(). if you did that, correctly, we
only get here if an exception was thrown. in such a scenario, we can't
be sure we fully read all expected data of a reply on the socket. so
- we don't try to reuse the connection.
+ we don't try to reuse the connection. The cout is just informational.
*/
cout << "~ScopedDBConnection: _conn != null\n";
delete _conn;
diff --git a/db/makefile b/db/makefile
index c5d1045ad1c..113d45a7270 100644
--- a/db/makefile
+++ b/db/makefile
@@ -13,7 +13,7 @@ JVM_LIBS = -L/opt/java/lib/
OBJS=../stdafx.o ../util/sock.o ../grid/message.o ../util/mmap.o pdfile.o query.o jsobj.o introspect.o btree.o clientcursor.o ../util/util.o javajs.o tests.o json.o repl.o ../client/dbclient.o btreecursor.o cloner.o namespace.o commands.o matcher.o dbcommands.o dbeval.o ../util/background.o
-DBGRID_OBJS=../stdafx.o json.o ../util/sock.o ../grid/message.o ../util/util.o jsobj.o ../client/dbclient.o ../dbgrid/dbgrid.o ../dbgrid/request.o ../dbgrid/connpool.o ../dbgrid/gridconfig.o commands.o ../dbgrid/dbgrid_commands.o ../dbgrid/griddb.o ../client/model.o ../util/background.o
+DBGRID_OBJS=../stdafx.o json.o ../util/sock.o ../grid/message.o ../util/util.o jsobj.o ../client/dbclient.o ../dbgrid/dbgrid.o ../dbgrid/request.o ../client/connpool.o ../dbgrid/gridconfig.o commands.o ../dbgrid/dbgrid_commands.o ../dbgrid/griddb.o ../client/model.o ../util/background.o
GPP = g++
diff --git a/dbgrid/dbgrid.cpp b/dbgrid/dbgrid.cpp
index ae5cde2eb04..e5cccc114c0 100644
--- a/dbgrid/dbgrid.cpp
+++ b/dbgrid/dbgrid.cpp
@@ -19,7 +19,7 @@
#include "stdafx.h"
#include "../grid/message.h"
#include "../util/unittest.h"
-#include "connpool.h"
+#include "../client/connpool.h"
#include "gridconfig.h"
const char *curNs = "";
diff --git a/dbgrid/dbgrid.vcproj b/dbgrid/dbgrid.vcproj
index ec177196f2f..a734f114311 100644
--- a/dbgrid/dbgrid.vcproj
+++ b/dbgrid/dbgrid.vcproj
@@ -175,10 +175,6 @@
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
- RelativePath=".\connpool.cpp"
- >
- </File>
- <File
RelativePath=".\dbgrid.cpp"
>
</File>
@@ -205,18 +201,6 @@
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
- RelativePath="..\util\background.h"
- >
- </File>
- <File
- RelativePath="..\db\commands.h"
- >
- </File>
- <File
- RelativePath=".\connpool.h"
- >
- </File>
- <File
RelativePath=".\database.h"
>
</File>
@@ -244,6 +228,18 @@
RelativePath="..\stdafx.h"
>
</File>
+ <Filter
+ Name="Header Shared"
+ >
+ <File
+ RelativePath="..\util\background.h"
+ >
+ </File>
+ <File
+ RelativePath="..\db\commands.h"
+ >
+ </File>
+ </Filter>
</Filter>
<Filter
Name="Resource Files"
@@ -271,6 +267,14 @@
Name="client"
>
<File
+ RelativePath="..\client\connpool.cpp"
+ >
+ </File>
+ <File
+ RelativePath="..\client\connpool.h"
+ >
+ </File>
+ <File
RelativePath="..\client\dbclient.cpp"
>
</File>
diff --git a/dbgrid/dbgrid_commands.cpp b/dbgrid/dbgrid_commands.cpp
index 2a1e9b898c7..74464b0851a 100644
--- a/dbgrid/dbgrid_commands.cpp
+++ b/dbgrid/dbgrid_commands.cpp
@@ -32,7 +32,7 @@
#include "stdafx.h"
#include "../grid/message.h"
#include "../db/dbmessage.h"
-#include "connpool.h"
+#include "../client/connpool.h"
#include "../db/commands.h"
#include "gridconfig.h"
diff --git a/dbgrid/gridconfig.cpp b/dbgrid/gridconfig.cpp
index b1cc0981827..da915161386 100644
--- a/dbgrid/gridconfig.cpp
+++ b/dbgrid/gridconfig.cpp
@@ -20,7 +20,7 @@
#include "../grid/message.h"
#include "../util/unittest.h"
#include "database.h"
-#include "connpool.h"
+#include "../client/connpool.h"
#include "../db/pdfile.h"
#include "gridconfig.h"
#include "../client/model.h"
diff --git a/dbgrid/griddb.cpp b/dbgrid/griddb.cpp
index c02f28ab831..90fe44dcb90 100644
--- a/dbgrid/griddb.cpp
+++ b/dbgrid/griddb.cpp
@@ -20,7 +20,7 @@
#include "../grid/message.h"
#include "../util/unittest.h"
#include "database.h"
-#include "connpool.h"
+#include "../client/connpool.h"
#include "../db/pdfile.h"
#include "gridconfig.h"
#include "../client/model.h"
diff --git a/dbgrid/request.cpp b/dbgrid/request.cpp
index 9a2cda7f95a..79082c40bd3 100644
--- a/dbgrid/request.cpp
+++ b/dbgrid/request.cpp
@@ -32,7 +32,7 @@
#include "stdafx.h"
#include "../grid/message.h"
#include "../db/dbmessage.h"
-#include "connpool.h"
+#include "../client/connpool.h"
const char *tempHost = "localhost:27018";