summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Bligh <mbligh@mongodb.com>2016-02-02 10:57:23 -0500
committerRamon Fernandez <ramon@mongodb.com>2016-02-02 18:56:13 -0500
commit3d236611718ccd164335c0edc649f34868d0072c (patch)
treead070cc99e2b62a4292d032aad3a83f29fbd6cb8
parent44f0661a7a770bad193582935d001b4754389b34 (diff)
downloadmongo-3d236611718ccd164335c0edc649f34868d0072c.tar.gz
SERVER-22167: Move fixDocuments up earlier in the insert path to ensure it runs
(cherry picked from commit 370634f46633f0fd6d626822d7d75752a34d4f50)
-rw-r--r--jstests/noPassthroughWithMongod/bench_test_crud_commands.js42
-rw-r--r--src/mongo/db/instance.cpp14
2 files changed, 39 insertions, 17 deletions
diff --git a/jstests/noPassthroughWithMongod/bench_test_crud_commands.js b/jstests/noPassthroughWithMongod/bench_test_crud_commands.js
index bdbd03f74b0..843e6db080b 100644
--- a/jstests/noPassthroughWithMongod/bench_test_crud_commands.js
+++ b/jstests/noPassthroughWithMongod/bench_test_crud_commands.js
@@ -6,6 +6,19 @@
coll.drop();
assert.commandWorked(coll.getDB().createCollection(coll.getName()));
+ function makeDocument(docSize) {
+ var doc = { "fieldName":"" };
+ var longString = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
+ while(Object.bsonsize(doc) < docSize) {
+ if (Object.bsonsize(doc) < docSize - longString.length) {
+ doc.fieldName += longString;
+ } else {
+ doc.fieldName += "x";
+ }
+ }
+ return doc;
+ }
+
function executeBenchRun(benchOps) {
var benchArgs = {ops: benchOps, parallel: 2, seconds: 1, host: db.getMongo().host};
if (jsTest.options().auth) {
@@ -16,17 +29,13 @@
return benchRun(benchArgs);
}
- function testInsert(writeCmd, wc) {
+ function testInsert(docs, writeCmd, wc) {
coll.drop();
- var docs = [];
- for (var i = 0; i < 100; i++) {
- docs.push({x: 1});
- }
var res = executeBenchRun([{ns: coll.getFullName(),
op: "insert",
doc: docs,
- writeCmd: writeCmd,
+ writeCmd: writeCmd,
writeConcern : wc}]);
assert.gt(coll.count(), 0);
@@ -61,10 +70,23 @@
assert.gt(res.findOne, 0, tojson(res));
}
- testInsert(false, {});
- testInsert(true, {"writeConcern" : {"w" : "majority"}});
- testInsert(true, {"writeConcern" : {"w" : 1, "j": false}});
- testInsert(true, {"writeConcern" : {"j" : true}});
+ function testWriteConcern(writeCmd) {
+ var bigDoc = makeDocument(260 * 1024);
+ var docs = [];
+ for (var i = 0; i < 100; i++) {
+ docs.push({x: 1});
+ }
+
+ testInsert([bigDoc], writeCmd, {});
+ testInsert(docs, writeCmd, {});
+ testInsert(docs, writeCmd, {"writeConcern" : {"w" : "majority"}});
+ testInsert(docs, writeCmd, {"writeConcern" : {"w" : 1, "j": false}});
+ testInsert(docs, writeCmd, {"writeConcern" : {"j" : true}});
+ }
+
+ testWriteConcern(false);
+ testWriteConcern(true);
+
testFind(false);
testFind(true);
testFindOne(false);
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp
index e1cd9230d24..70ee99959e4 100644
--- a/src/mongo/db/instance.cpp
+++ b/src/mongo/db/instance.cpp
@@ -982,13 +982,6 @@ void insertMultiVector(OperationContext* txn,
CurOp& op,
vector<BSONObj>::iterator begin,
vector<BSONObj>::iterator end) {
- for (vector<BSONObj>::iterator it = begin; it != end; it++) {
- StatusWith<BSONObj> fixed = fixDocumentForInsert(*it);
- uassertStatusOK(fixed.getStatus());
- if (!fixed.getValue().isEmpty())
- *it = fixed.getValue();
- }
-
try {
WriteUnitOfWork wunit(txn);
Collection* collection = ctx.db()->getCollection(ns);
@@ -1025,6 +1018,13 @@ NOINLINE_DECL void insertMulti(OperationContext* txn,
int64_t chunkSize = 0;
for (vector<BSONObj>::iterator it = docs.begin(); it != docs.end(); it++) {
+ StatusWith<BSONObj> fixed = fixDocumentForInsert(*it);
+ uassertStatusOK(fixed.getStatus());
+ if (!fixed.getValue().isEmpty())
+ *it = fixed.getValue();
+ }
+
+ for (vector<BSONObj>::iterator it = docs.begin(); it != docs.end(); it++) {
chunkSize += (*it).objsize();
// Limit chunk size, actual size chosen is a tradeoff: larger sizes are more efficient,
// but smaller chunk sizes allow yielding to other threads and lower chance of WCEs