1. Aristarkh Zagorodnikov
  2. mod_gridfs


Aristarkh Zagorodnikov  committed c51008d

SlaveOk support

  • Participants
  • Parent commits 2e270e2
  • Branches cxx-driver

Comments (0)

Files changed (2)


View file
  • Ignore whitespace
 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
 Configuration example:
 GridFSConnection rsTest/db1,db2
 Also, it supports HEAD requests, conditional queries (If-Modified-Since and/or If-None-Match with proper 304 Not Modified response).
 It doesn't support range queries (not going to be implemented soon).
-SlaveOK queries
 Known problems:
 If you're using gcc version less than 4.5, apache parent process would crash when reloading modules (on restart after a module list update).
 This is a known problem with gcc and libstdc++. Unfortunately, the only workaround is to upgrade your compiler and standard library.

File gridfs/mod_gridfs.cpp

View file
  • Ignore whitespace
 #include "http_protocol.h"
 #include "http_request.h"
+//	Support for slaveOk (requires patched driver until https://jira.mongodb.org/browse/SERVER-5568 is resolved)
 //	Declare module
 extern "C"
 	bool cache_max_age_set;
 	int connect_timeout;
 	bool connect_timeout_set;
+	bool slave_ok;
+	bool slave_ok_set;
 //	Creates module configuration
 	config->cache_max_age_set = add->cache_max_age_set || base->cache_max_age_set;
 	config->connect_timeout = add->connect_timeout_set ? add->connect_timeout : base->connect_timeout;
 	config->connect_timeout_set = add->connect_timeout_set || base->connect_timeout_set;
+	config->slave_ok = add->slave_ok_set ? add->slave_ok : base->slave_ok;
+	config->slave_ok_set = add->slave_ok_set || base->slave_ok_set;
 	return config;
 	return 0;
+//	Handles "GridFSSlaveOk <On|Off>" command
+static const char *gridfs_slave_ok_command(cmd_parms *const command, void *const module_config, int flag)
+	if (flag)
+		return "slaveOk not supported by the driver";
+	gridfs_config *const config = static_cast<gridfs_config *>(module_config);
+	config->slave_ok = flag != 0;
+	config->slave_ok_set = true;
+	return 0;
 //	Handles request
 static int gridfs_handler(request_rec *const request)
 		const mongo::GridFS gridfs(connection.conn(), *config->database);
+		const mongo::GridFile& gridfile = gridfs.findFile(filename, config->slave_ok);
 		const mongo::GridFile& gridfile = gridfs.findFile(filename);
 		if (!gridfile.exists())
 	AP_INIT_TAKE1("GridFSDatabase", reinterpret_cast<cmd_func>(gridfs_database_command), 0, OR_FILEINFO, "GridFS database name."),
 	AP_INIT_TAKE1("GridFSCacheMaxAge", reinterpret_cast<cmd_func>(gridfs_cache_max_age_command), 0, OR_FILEINFO, "GridFS cache max age (seconds, 0 to disable expiration)."),
 	AP_INIT_TAKE1("GridFSConnectTimeout", reinterpret_cast<cmd_func>(gridfs_connect_timeout_command), 0, OR_FILEINFO, "GridFS connection timeout (seconds, 0 for infinite)."),
+	AP_INIT_FLAG("GridFSSlaveOk", reinterpret_cast<cmd_func>(gridfs_slave_ok_command), 0, OR_FILEINFO, "GridFS slaveOk flag."),