Commits

Aristarkh Zagorodnikov  committed 5a97223

When slaveOk is enabled, and a file is not found on slave, the query is retried with slaveOk disabled to combat replication lag issues

  • Participants
  • Parent commits 57dab5d
  • Branches v0.2

Comments (0)

Files changed (1)

File gridfs/mod_gridfs.cpp

 		try
 		{
 			const mongo::GridFS gridfs(connection->conn(), *config->database);
-			const mongo::GridFile& gridfile = gridfs.findFile(filename, config->slave_ok);
+			mongo::GridFile gridfile = gridfs.findFile(filename, config->slave_ok);
 			if (!gridfile.exists())
 			{
-				connection->done();
-				return HTTP_NOT_FOUND;
+				if (config->slave_ok)
+				{
+					gridfile = gridfs.findFile(filename, false);
+					if (!gridfile.exists())
+					{
+						connection->done();
+						return HTTP_NOT_FOUND;
+					}
+				}
+				else
+				{
+					connection->done();
+					return HTTP_NOT_FOUND;
+				}
 			}
 			const mongo::gridfs_offset file_length = gridfile.getContentLength();
 			const mongo::Date_t upload_date = gridfile.getUploadDate();