summaryrefslogtreecommitdiff
path: root/src/mongo/scripting/bench.cpp
diff options
context:
space:
mode:
authorApollon Oikonomopoulos <apoikos@debian.org>2016-01-14 00:10:06 +0200
committerApollon Oikonomopoulos <apollon@skroutz.gr>2016-01-14 00:10:06 +0200
commit374e1947abcd3e127a2a613aff73ecffdb9199ea (patch)
treed83973c3c9802450acd5b5e86fe0d4e8e60a3a1b /src/mongo/scripting/bench.cpp
parent65585c90b12d6523bea75a2aebaae2a2fdf9e641 (diff)
Imported Upstream version 2.6.11upstream/2.6.11
Diffstat (limited to 'src/mongo/scripting/bench.cpp')
-rw-r--r--src/mongo/scripting/bench.cpp100
1 files changed, 88 insertions, 12 deletions
diff --git a/src/mongo/scripting/bench.cpp b/src/mongo/scripting/bench.cpp
index 74d2be2174d..b85d0b3c5a7 100644
--- a/src/mongo/scripting/bench.cpp
+++ b/src/mongo/scripting/bench.cpp
@@ -14,16 +14,29 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects
+ * for all of the code used other than as permitted herein. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you do not
+ * wish to do so, delete this exception statement from your version. If you
+ * delete this exception statement from all source files in the program,
+ * then also delete it in the license file.
*/
-#include "pch.h"
+#include "mongo/pch.h"
#include "mongo/scripting/bench.h"
#include <boost/thread/thread.hpp>
+#include "mongo/db/namespace_string.h"
#include "mongo/client/dbclientcursor.h"
#include "mongo/scripting/bson_template_evaluator.h"
#include "mongo/scripting/engine.h"
@@ -331,6 +344,10 @@ namespace mongo {
int delay = e["delay"].eoo() ? 0 : e["delay"].Int();
+ // Let's default to writeCmd == false.
+ bool useWriteCmd = e["writeCmd"].eoo() ? false :
+ e["writeCmd"].Bool();
+
BSONObj context = e["context"].eoo() ? BSONObj() : e["context"].Obj();
auto_ptr<Scope> scope;
@@ -469,10 +486,30 @@ namespace mongo {
{
BenchRunEventTrace _bret(&_stats.updateCounter);
- conn->update( ns, fixQuery( query, bsonTemplateEvaluator ), update,
- upsert , multi );
- if (safe)
- result = conn->getLastErrorDetailed();
+
+ if (useWriteCmd) {
+ // TODO: Replace after SERVER-11774.
+ BSONObjBuilder builder;
+ builder.append("update",
+ nsToCollectionSubstring(ns));
+ BSONArrayBuilder docBuilder(
+ builder.subarrayStart("updates"));
+ docBuilder.append(BSON("q" << fixQuery(query, bsonTemplateEvaluator) <<
+ "u" << update <<
+ "multi" << multi <<
+ "upsert" << upsert));
+ docBuilder.done();
+ conn->runCommand(
+ nsToDatabaseSubstring(ns).toString(),
+ builder.done(), result);
+ }
+ else {
+ conn->update(ns, fixQuery(query,
+ bsonTemplateEvaluator), update,
+ upsert , multi);
+ if (safe)
+ result = conn->getLastErrorDetailed();
+ }
}
if( safe ){
@@ -497,11 +534,30 @@ namespace mongo {
else if( op == "insert" ) {
bool safe = e["safe"].trueValue();
BSONObj result;
+
{
BenchRunEventTrace _bret(&_stats.insertCounter);
- conn->insert( ns, fixQuery( e["doc"].Obj(), bsonTemplateEvaluator ) );
- if (safe)
- result = conn->getLastErrorDetailed();
+
+ if (useWriteCmd) {
+ // TODO: Replace after SERVER-11774.
+ BSONObjBuilder builder;
+ builder.append("insert",
+ nsToCollectionSubstring(ns));
+ BSONArrayBuilder docBuilder(
+ builder.subarrayStart("documents"));
+ docBuilder.append(fixQuery(e["doc"].Obj(),
+ bsonTemplateEvaluator));
+ docBuilder.done();
+ conn->runCommand(
+ nsToDatabaseSubstring(ns).toString(),
+ builder.obj(), result);
+ }
+ else {
+ conn->insert(ns, fixQuery(e["doc"].Obj(),
+ bsonTemplateEvaluator));
+ if (safe)
+ result = conn->getLastErrorDetailed();
+ }
}
if( safe ){
@@ -532,9 +588,29 @@ namespace mongo {
{
BenchRunEventTrace _bret(&_stats.deleteCounter);
- conn->remove( ns, fixQuery( query, bsonTemplateEvaluator ), ! multi );
- if (safe)
- result = conn->getLastErrorDetailed();
+
+ if (useWriteCmd) {
+ // TODO: Replace after SERVER-11774.
+ BSONObjBuilder builder;
+ builder.append("delete",
+ nsToCollectionSubstring(ns));
+ BSONArrayBuilder docBuilder(
+ builder.subarrayStart("deletes"));
+ int limit = (multi == true) ? 0 : 1;
+ docBuilder.append(
+ BSON("q" << fixQuery(query, bsonTemplateEvaluator) <<
+ "limit" << limit));
+ docBuilder.done();
+ conn->runCommand(
+ nsToDatabaseSubstring(ns).toString(),
+ builder.obj(), result);
+ }
+ else {
+ conn->remove(ns, fixQuery(query,
+ bsonTemplateEvaluator), !multi);
+ if (safe)
+ result = conn->getLastErrorDetailed();
+ }
}
if( safe ){
@@ -602,7 +678,7 @@ namespace mongo {
_stats.errCount++;
}
- if ( ++count % 100 == 0 ) {
+ if (++count % 100 == 0 && !useWriteCmd) {
conn->getLastError();
}