Commits

Aristarkh Zagorodnikov  committed 482ee83

Moved to a new build system that uses original (and fresh) MongoDB source with applied patches

  • Participants
  • Parent commits 27d39ac
  • Branches default

Comments (0)

Files changed (3)

 Old driver that is written in C and used MongoDB C driver is still available in the "c-driver" branch.
 
 Building (see next section for Ubuntu fast-forward instructions):
-Make sure you have g++ and boost libraries installed
+Make sure you have g++ and boost libraries (filesystem, system, thread) installed
 Install Apache 2.2+ and APXS
 Grab the module from https://bitbucket.org/onyxmaster/mod_gridfs/, remember the absolute path to the directory (referenced as /path/to/mod_gridfs later on)
-Grab MongoDB C++ driver from http://downloads.mongodb.org/cxx-driver/mongodb-linux-x86_64-latest.tgz, unpack it and go to the target directory
-Fix the driver build environment (change broken rights and build static library with PIC to allow module to be built as a shared library):
-	chmod -R a+r .
+Grab MongoDB from https://github.com/mongodb/mongo (post-2.0 branch required) and go to its directory
+Build MongoDB C++ driver source package from MongoDB sources:
+	scons distclient
+Unpack the resulting archive (mongo-cxx-driver.tgz) and go it its directory
+Fix the driver build environment (build static library with PIC to allow module to be built as a shared library):
 	echo 'env.Append(CCFLAGS="-fPIC")' >> SConstruct
-Build and install the results to "gridfs/driver" directory:
-	mkdir /path/to/mod_gridfs/gridfs/driver
-	scons install --prefix=/path/to/mod_gridfs/gridfs/driver
+Apply the GridFS slaveOk patch:
+	patch -d src/mongo/client < /path/to/mod_gridfs/patches/gridfs-slaveok
+Build the driver:
+	scons
 
 Ubuntu build fast-forward instructions:
-sudo apt-get -y install mercurial wget g++ apache2 apache2-threaded-dev libboost-thread-dev libboost-filesystem-dev libboost-system-dev
-cd $HOME
+sudo apt-get -y install mercurial wget g++ apache2 apache2-threaded-dev libboost-filesystem-dev libboost-system-dev libboost-thread-dev
 hg clone https://bitbucket.org/onyxmaster/mod_gridfs/
 cd mod_gridfs
 hg update
-wget http://downloads.mongodb.org/cxx-driver/mongodb-linux-x86_64-latest.tgz
-tar xzf mongodb-linux-x86_64-latest.tgz
-rm mongodb-linux-x86_64-latest.tgz
-cd mongo-cxx-driver-nightly
-chmod -R a+r .
-echo 'env.Append(CCFLAGS="-fPIC")' >> SConstruct
-mkdir $HOME/mod_gridfs/gridfs/driver
-scons install --prefix=$HOME/mod_gridfs/gridfs/driver
-cd $HOME/mod_gridfs
-rm -rf mongo-cxx-driver-nightly
-cd gridfs
-make && sudo make install
+wget https://github.com/mongodb/mongo/tarball/master
+tar xzf master
+rm master
+mv mongodb-mongo-* mongo
+scons -C mongo distclient
+tar xzf mongo/mongo-cxx-driver.tgz
+rm -rf mongo
+echo 'env.Append(CCFLAGS="-fPIC")' >> mongo-cxx-driver/SConstruct
+patch -d mongo-cxx-driver/src/mongo/client < patches/gridfs-slaveok
+scons -C mongo-cxx-driver
+make -C gridfs
 
-Ubuntu installation fast-forward instructions (copy $HOME/mod_gridfs directory to a target machine first):
-sudo apt-get -y install apache2 libstdc++6 libboost-thread libboost-filesystem libboost-system
-cd $HOME/mod_gridfs
-sudo make install
+Ubuntu build cleanup instructions:
+cd mod_gridfs
+make -C gridfs clean
+rm -rf mongo-cxx-driver
+
+Ubuntu installation fast-forward instructions (copy mod_gridfs directory to a target machine first):
+sudo apt-get -y install apache2 libstdc++6 libboost-filesystem libboost-system libboost-thread
+cd mod_gridfs
+sudo make -C gridfs install
 
 Configuration:
 GridFSConnection -- Connection string ("host[:port]" for single hosts, "replicaSetName/host[:port],[host[:port], ...]" for replica sets)
 GridFSDatabase <database> -- Set database name
 GridFSCacheMaxAge <maxAge> -- Optional, set cache max age in seconds (default is 1 week, maximum is 10 years), set to 0 to disable expiration caching (see Notes below)
 GridFSConnectTimeout <timeout> -- Optional, set MongoDB connection timeout in seconds (default is 5 seconds)
-GridFSSlaveOk <On|Off> -- Optional, set MongoDB slaveOk mode (horizontal sharding), currently requires patched driver until https://jira.mongodb.org/browse/SERVER-5568 is resolved
+GridFSSlaveOk <On|Off> -- Optional, set MongoDB slaveOk mode (horizontal sharding)
 
 Configuration example:
 GridFSConnection rsTest/db1,db2
 Known problems:
 If you're using gcc version less than 4.5, Apache parent process would crash when reloading modules (on a restart after module list is updated).
 This is a known problem with gcc and libstdc++. Unfortunately, the only workaround is to upgrade your compiler and standard C++ library.
-

File gridfs/Makefile

 CXX=g++
 
 #	Set MongoDB C++ driver location
-mongo_includedir=driver/include
-mongo_libdir=driver/lib
+mongo_includedir=../mongo-cxx-driver/src
+mongo_libdir=../mongo-cxx-driver
 
 #	Determine paths using apxs
 builddir=.

File patches/gridfs-slaveok

+--- mongo-cxx-driver/src/mongo/client/gridfs.h	2012-04-19 21:45:44.000000000 +0400
++++ mongo-cxx-driver/src/mongo/client/gridfs.h	2012-04-20 00:08:12.000000000 +0400
+@@ -101,22 +101,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;
+@@ -192,12 +192,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-04-19 21:45:44.000000000 +0400
++++ mongo-cxx-driver/src/mongo/client/gridfs.cpp	2012-04-20 00:03:50.000000000 +0400
+@@ -174,26 +174,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 ) , 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 {