Commits

Aristarkh Zagorodnikov  committed 7708485

Added C++ driver GridFS read preference patch
Removed C++ driver GridFS slaveOk patch

  • Participants
  • Parent commits 1c7cdf2
  • Branches v0.3

Comments (0)

Files changed (2)

File patches/gridfs-readpref

+--- mongo-cxx-driver/src/mongo/client/gridfs.h	2012-08-13 21:38:00.000000000 +0400
++++ mongo-cxx-driver/src/mongo/client/gridfs.h	2012-12-18 14:13:46.000000000 +0400
+@@ -103,22 +103,22 @@
+         /**
+          * returns a file object matching the query
+          */
+-        GridFile findFile( BSONObj query ) const;
++        GridFile findFile( BSONObj query , const string& readPrefMode = "" ) const;
+ 
+         /**
+          * equiv to findFile( { filename : filename } )
+          */
+-        GridFile findFile( const string& fileName ) const;
++        GridFile findFile( const string& fileName , const string& readPrefMode = "" ) const;
+ 
+         /**
+          * convenience method to get all the files
+          */
+-        auto_ptr<DBClientCursor> list() const;
++        auto_ptr<DBClientCursor> list( const string& readPrefMode = "" ) const;
+ 
+         /**
+          * convenience method to get all the files with a filter
+          */
+-        auto_ptr<DBClientCursor> list( BSONObj query ) const;
++        auto_ptr<DBClientCursor> list( BSONObj query , const string& readPrefMode = "" ) const;
+ 
+     private:
+         DBClientBase& _client;
+@@ -194,12 +194,13 @@
+         gridfs_offset write( const string& where ) const;
+ 
+     private:
+-        GridFile(const GridFS * grid , BSONObj obj );
++        GridFile(const GridFS * grid , BSONObj obj , const string& readPrefMode );
+ 
+         void _exists() const;
+ 
+         const GridFS * _grid;
+         BSONObj        _obj;
++        string         _readPrefMode;
+ 
+         friend class GridFS;
+     };
+--- mongo-cxx-driver/src/mongo/client/gridfs.cpp	2012-08-13 21:38:00.000000000 +0400
++++ mongo-cxx-driver/src/mongo/client/gridfs.cpp	2012-12-18 17:35:05.000000000 +0400
+@@ -184,25 +184,35 @@
+         }
+     }
+ 
+-    GridFile::GridFile(const GridFS * grid , BSONObj obj ) {
++    GridFile::GridFile(const GridFS * grid , BSONObj obj , const string& readPrefMode ) {
+         _grid = grid;
+         _obj = obj;
++        _readPrefMode = readPrefMode;
+     }
+ 
+-    GridFile GridFS::findFile( const string& fileName ) const {
+-        return findFile( BSON( "filename" << fileName ) );
++    GridFile GridFS::findFile( const string& fileName, const string& readPrefMode ) const {
++        return findFile( BSON( "filename" << fileName ) , readPrefMode );
+     };
+ 
+-    GridFile GridFS::findFile( BSONObj query ) const {
+-        query = BSON("query" << query << "orderby" << BSON("uploadDate" << -1));
+-        return GridFile( this , _client.findOne( _filesNS.c_str() , query ) );
++    GridFile GridFS::findFile( BSONObj query, const string& readPrefMode ) const {
++        BSONObjBuilder b;
++        b.append("query", query);
++        b.append("orderby", BSON("uploadDate" << -1));
++        if (!readPrefMode.empty()) {
++            b.append("$readPreference", BSON("mode" << readPrefMode));
++        }
++        query = b.obj();
++        return GridFile( this , _client.findOne( _filesNS.c_str() , query ) , readPrefMode );
+     }
+ 
+-    auto_ptr<DBClientCursor> GridFS::list() const {
+-        return _client.query( _filesNS.c_str() , BSONObj() );
++    auto_ptr<DBClientCursor> GridFS::list( const string& readPrefMode ) const {
++        return list( BSONObj() , readPrefMode );
+     }
+ 
+-    auto_ptr<DBClientCursor> GridFS::list( BSONObj o ) const {
++    auto_ptr<DBClientCursor> GridFS::list( BSONObj o, const string& readPrefMode ) const {
++        if (!readPrefMode.empty()) {
++        	o = BSON("query" << o << "$readPreference" << BSON("mode" << readPrefMode));
++        }
+         return _client.query( _filesNS.c_str() , o );
+     }
+ 
+@@ -220,8 +230,12 @@
+         BSONObjBuilder b;
+         b.appendAs( _obj["_id"] , "files_id" );
+         b.append( "n" , n );
++        BSONObj q = b.obj();
++        if (!_readPrefMode.empty()) {
++        	q = BSON("query" << q << "$readPreference" << BSON("mode" << _readPrefMode));
++        }
+ 
+-        BSONObj o = _grid->_client.findOne( _grid->_chunksNS.c_str() , b.obj() );
++        BSONObj o = _grid->_client.findOne( _grid->_chunksNS.c_str() , q );
+         uassert( 10014 ,  "chunk is empty!" , ! o.isEmpty() );
+         return GridFSChunk(o);
+     }

File patches/gridfs-slaveok

---- mongo-cxx-driver/src/mongo/client/gridfs.h	2012-11-18 21:01:59.935920891 +0400
-+++ mongo-cxx-driver/src/mongo/client/gridfs.h	2012-11-20 11:34:51.000000000 +0400
-@@ -103,22 +103,22 @@
-         /**
-          * returns a file object matching the query
-          */
--        GridFile findFile( BSONObj query ) const;
-+        GridFile findFile( BSONObj query , bool slaveOk = false ) const;
- 
-         /**
-          * equiv to findFile( { filename : filename } )
-          */
--        GridFile findFile( const string& fileName ) const;
-+        GridFile findFile( const string& fileName , bool slaveOk = false ) const;
- 
-         /**
-          * convenience method to get all the files
-          */
--        auto_ptr<DBClientCursor> list() const;
-+        auto_ptr<DBClientCursor> list( bool slaveOk = false ) const;
- 
-         /**
-          * convenience method to get all the files with a filter
-          */
--        auto_ptr<DBClientCursor> list( BSONObj query ) const;
-+        auto_ptr<DBClientCursor> list( BSONObj query , bool slaveOk = false ) const;
- 
-     private:
-         DBClientBase& _client;
-@@ -194,12 +194,13 @@
-         gridfs_offset write( const string& where ) const;
- 
-     private:
--        GridFile(const GridFS * grid , BSONObj obj );
-+        GridFile(const GridFS * grid , BSONObj obj , bool slaveOk = false );
- 
-         void _exists() const;
- 
-         const GridFS * _grid;
-         BSONObj        _obj;
-+        bool           _slaveOk;
- 
-         friend class GridFS;
-     };
---- mongo-cxx-driver/src/mongo/client/gridfs.cpp	2012-11-18 21:02:23.879888343 +0400
-+++ mongo-cxx-driver/src/mongo/client/gridfs.cpp	2012-11-20 11:55:57.000000000 +0400
-@@ -184,26 +184,27 @@
-         }
-     }
- 
--    GridFile::GridFile(const GridFS * grid , BSONObj obj ) {
-+    GridFile::GridFile(const GridFS * grid , BSONObj obj , bool slaveOk ) {
-         _grid = grid;
-         _obj = obj;
-+		_slaveOk = slaveOk;
-     }
- 
--    GridFile GridFS::findFile( const string& fileName ) const {
--        return findFile( BSON( "filename" << fileName ) );
-+    GridFile GridFS::findFile( const string& fileName , bool slaveOk ) const {
-+        return findFile( BSON( "filename" << fileName ) , slaveOk );
-     };
- 
--    GridFile GridFS::findFile( BSONObj query ) const {
-+    GridFile GridFS::findFile( BSONObj query , bool slaveOk ) const {
-         query = BSON("query" << query << "orderby" << BSON("uploadDate" << -1));
--        return GridFile( this , _client.findOne( _filesNS.c_str() , query ) );
-+        return GridFile( this , _client.findOne( _filesNS.c_str() , query, 0 , slaveOk ? QueryOption_SlaveOk : 0 ) , slaveOk );
-     }
- 
--    auto_ptr<DBClientCursor> GridFS::list() const {
--        return _client.query( _filesNS.c_str() , BSONObj() );
-+    auto_ptr<DBClientCursor> GridFS::list( bool slaveOk ) const {
-+        return _client.query( _filesNS.c_str() , BSONObj() , 0 , slaveOk ? QueryOption_SlaveOk : 0 );
-     }
- 
--    auto_ptr<DBClientCursor> GridFS::list( BSONObj o ) const {
--        return _client.query( _filesNS.c_str() , o );
-+    auto_ptr<DBClientCursor> GridFS::list( BSONObj o , bool slaveOk ) const {
-+        return _client.query( _filesNS.c_str() , o , slaveOk ? QueryOption_SlaveOk : 0 );
-     }
- 
-     BSONObj GridFile::getMetadata() const {
-@@ -221,7 +222,7 @@
-         b.appendAs( _obj["_id"] , "files_id" );
-         b.append( "n" , n );
- 
--        BSONObj o = _grid->_client.findOne( _grid->_chunksNS.c_str() , b.obj() );
-+        BSONObj o = _grid->_client.findOne( _grid->_chunksNS.c_str() , b.obj() , 0 , _slaveOk ? QueryOption_SlaveOk : 0 );
-         uassert( 10014 ,  "chunk is empty!" , ! o.isEmpty() );
-         return GridFSChunk(o);
-     }