summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2010-11-03 14:10:13 -0400
committerMathias Stearn <mathias@10gen.com>2010-11-03 14:14:00 -0400
commitc74c0f9e28c0b813ada9035afa3c2ad1602727c3 (patch)
tree387cf9960aaecb5d206e7989e33307043da53e98 /tools
parent77a0cb7662edca4a66a2efd022380e8ee810d19c (diff)
downloadmongo-c74c0f9e28c0b813ada9035afa3c2ad1602727c3.tar.gz
Use QueryOption_Exaust in mongodump. SERVER-2059
Diffstat (limited to 'tools')
-rw-r--r--tools/dump.cpp39
1 files changed, 30 insertions, 9 deletions
diff --git a/tools/dump.cpp b/tools/dump.cpp
index f2eeb84b14d..e5910a26560 100644
--- a/tools/dump.cpp
+++ b/tools/dump.cpp
@@ -35,6 +35,23 @@ public:
;
}
+ // This is a functor that writes a BSONObj to a file
+ struct Writer{
+ Writer(ostream& out, ProgressMeter* m) :_out(out), _m(m) {}
+
+ void operator () (const BSONObj& obj) {
+ _out.write( obj.objdata() , obj.objsize() );
+
+ // if there's a progress bar, hit it
+ if (_m) {
+ _m->hit();
+ }
+ }
+
+ ostream& _out;
+ ProgressMeter* _m;
+ };
+
void doCollection( const string coll , ostream &out , ProgressMeter *m ) {
Query q;
if ( _query.isEmpty() && !hasParam("dbpath"))
@@ -42,15 +59,19 @@ public:
else
q = _query;
- auto_ptr<DBClientCursor> cursor = conn( true ).query( coll.c_str() , q , 0 , 0 , 0 , QueryOption_SlaveOk | QueryOption_NoCursorTimeout );
-
- while ( cursor->more() ) {
- BSONObj obj = cursor->next();
- out.write( obj.objdata() , obj.objsize() );
-
- // if there's a progress bar, hit it
- if (m) {
- m->hit();
+ DBClientBase& connBase = conn(true);
+ Writer writer(out, m);
+
+ // use low-latency "exhaust" mode if going over the network
+ if (typeid(connBase) == typeid(DBClientConnection&)){
+ DBClientConnection& conn = static_cast<DBClientConnection&>(connBase);
+ boost::function<void(const BSONObj&)> castedWriter(writer); // needed for overload resolution
+ conn.query( castedWriter, coll.c_str() , q , NULL, QueryOption_SlaveOk | QueryOption_NoCursorTimeout | QueryOption_Exhaust);
+ } else {
+ //This branch should only be taken with DBDirectClient which doesn't support exhaust mode
+ scoped_ptr<DBClientCursor> cursor(connBase.query( coll.c_str() , q , 0 , 0 , 0 , QueryOption_SlaveOk | QueryOption_NoCursorTimeout ));
+ while ( cursor->more() ) {
+ writer(cursor->next());
}
}
}