diff options
author | Spencer T Brody <spencer@mongodb.com> | 2017-11-14 17:52:12 -0500 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2017-11-17 12:13:04 -0500 |
commit | 60ab064909d30d982efcc3898cb374508dd54001 (patch) | |
tree | 2ab96a95594a4336e4994e64dacab183246a5eae /src | |
parent | 66a83776a84a56688dc45d8a091b1d9fc2ca02e6 (diff) | |
download | mongo-60ab064909d30d982efcc3898cb374508dd54001.tar.gz |
SERVER-31953 Target secondary application of updates and deletes by just _id
(cherry picked from commit b6235c8418faf541af93e9caacc22b7ed9aed817)
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/repl/oplog.cpp | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 909cf659fa8..c849a450f26 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -1297,12 +1297,15 @@ Status applyOperation_inlock(OperationContext* opCtx, } else if (*opType == 'u') { opCounters->gotUpdate(); - BSONObj updateCriteria = o2; - const bool upsert = valueB || alwaysUpsert; - + auto idField = o2["_id"]; uassert(ErrorCodes::NoSuchKey, str::stream() << "Failed to apply update due to missing _id: " << op.toString(), - updateCriteria.hasField("_id")); + !idField.eoo()); + + // The o2 field may contain additional fields besides the _id (like the shard key fields), + // but we want to do the update by just _id so we can take advantage of the IDHACK. + BSONObj updateCriteria = idField.wrap(); + const bool upsert = valueB || alwaysUpsert; UpdateRequest request(requestNss); request.setQuery(updateCriteria); @@ -1379,9 +1382,14 @@ Status applyOperation_inlock(OperationContext* opCtx, } else if (*opType == 'd') { opCounters->gotDelete(); + auto idField = o["_id"]; uassert(ErrorCodes::NoSuchKey, str::stream() << "Failed to apply delete due to missing _id: " << op.toString(), - o.hasField("_id")); + !idField.eoo()); + + // The o field may contain additional fields besides the _id (like the shard key fields), + // but we want to do the delete by just _id so we can take advantage of the IDHACK. + BSONObj deleteCriteria = idField.wrap(); SnapshotName timestamp; if (assignOperationTimestamp) { @@ -1396,7 +1404,7 @@ Status applyOperation_inlock(OperationContext* opCtx, } if (opType[1] == 0) { - deleteObjects(opCtx, collection, requestNss, o, /*justOne*/ valueB); + deleteObjects(opCtx, collection, requestNss, deleteCriteria, /*justOne*/ valueB); } else verify(opType[1] == 'b'); // "db" advertisement wuow.commit(); |