0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

SERVER-43052 Sanitize writeConflictRetry loops for duplicate fields in result

This commit is contained in:
Evgeni Dobranov 2019-09-13 20:02:10 +00:00 committed by evergreen
parent abfc416116
commit d832971810
2 changed files with 53 additions and 1 deletions

View File

@ -0,0 +1,48 @@
/*
* Test that dropIndexes does not return a message containing multiple "nIndexesWas" fields.
*
* @tags: [requires_wiredtiger]
*/
(function() {
"use strict";
let oldRes, newRes;
let coll = db.dropindexes_duplicate_fields;
try {
// Repeat 100 times for the sake of probabilities
for (let i = 0; i < 100; i++) {
coll.drop();
assert.commandWorked(coll.insert({x: 1}));
assert.commandWorked(coll.createIndex({"x": 1}));
assert.commandWorked(db.adminCommand(
{configureFailPoint: 'WTWriteConflictException', mode: {activationProbability: 0.1}}));
// Will blow up if writeConflictRetry causes duplicate fields to be appended to result
let res = db.runCommand({dropIndexes: coll.getName(), index: {"x": 1}});
if (!oldRes && !newRes) {
oldRes = res;
} else if (oldRes && !newRes) {
newRes = res;
} else {
oldRes = newRes;
newRes = res;
}
assert.commandWorked(newRes ? newRes : oldRes);
// Responses between runs should be the same independent of a WriteConflict
if (oldRes && newRes) {
assert.eq(oldRes, newRes);
}
assert.commandWorked(
db.adminCommand({configureFailPoint: 'WTWriteConflictException', mode: "off"}));
}
} finally {
assert.commandWorked(
db.adminCommand({configureFailPoint: 'WTWriteConflictException', mode: "off"}));
}
})();

View File

@ -226,12 +226,16 @@ Status dropIndexes(OperationContext* opCtx,
WriteUnitOfWork wunit(opCtx);
OldClientContext ctx(opCtx, nss.ns());
Status status = wrappedRun(opCtx, collection, cmdObj, result);
// Use an empty BSONObjBuilder to avoid duplicate appends to result on retry loops.
BSONObjBuilder tempObjBuilder;
Status status = wrappedRun(opCtx, collection, cmdObj, &tempObjBuilder);
if (!status.isOK()) {
return status;
}
wunit.commit();
result->appendElementsUnique(tempObjBuilder.done()); // This append will only happen once.
return Status::OK();
});
}