summaryrefslogtreecommitdiff
path: root/src/mongo/db/ops/write_ops_parsers.h
diff options
context:
space:
mode:
authorDan Larkin-York <dan.larkin-york@mongodb.com>2021-04-28 21:04:54 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-28 22:07:09 +0000
commit09e418805e9019cb56e54d240c7c7d9bcb95e339 (patch)
tree9c0f988d9b9bdfa0b808b84849d1c8b87497bcc6 /src/mongo/db/ops/write_ops_parsers.h
parent6e88994a34e7882e1c9692fea653ed625e6e1c1b (diff)
downloadmongo-09e418805e9019cb56e54d240c7c7d9bcb95e339.tar.gz
SERVER-55501 Avoid element-wise iteration and copy when appending to an object in doc_diff::applyDiff
Diffstat (limited to 'src/mongo/db/ops/write_ops_parsers.h')
-rw-r--r--src/mongo/db/ops/write_ops_parsers.h34
1 files changed, 24 insertions, 10 deletions
diff --git a/src/mongo/db/ops/write_ops_parsers.h b/src/mongo/db/ops/write_ops_parsers.h
index 900740b271b..22608793005 100644
--- a/src/mongo/db/ops/write_ops_parsers.h
+++ b/src/mongo/db/ops/write_ops_parsers.h
@@ -84,23 +84,27 @@ public:
/**
* Used to indicate that a certain type of update is being passed to the constructor.
*/
- struct DiffTag {};
+ struct DiffOptions {
+ bool mustCheckExistenceForInsertOperations = true;
+ };
struct ClassicTag {};
// Given the 'o' field of an update oplog entry, will return an UpdateModification that can be
- // applied.
- static UpdateModification parseFromOplogEntry(const BSONObj& oField);
+ // applied. The `options` parameter will be applied only in the case a Delta update is parsed.
+ static UpdateModification parseFromOplogEntry(const BSONObj& oField,
+ const DiffOptions& options);
static UpdateModification parseFromClassicUpdate(const BSONObj& modifiers) {
return UpdateModification(modifiers, ClassicTag{});
}
- static UpdateModification parseFromV2Delta(const doc_diff::Diff& diff) {
- return UpdateModification(diff, DiffTag{});
+ static UpdateModification parseFromV2Delta(const doc_diff::Diff& diff,
+ DiffOptions const& options) {
+ return UpdateModification(diff, options);
}
UpdateModification() = default;
UpdateModification(BSONElement update);
UpdateModification(std::vector<BSONObj> pipeline);
- UpdateModification(doc_diff::Diff, DiffTag);
+ UpdateModification(doc_diff::Diff, DiffOptions);
// This constructor exists only to provide a fast-path for constructing classic-style updates.
UpdateModification(const BSONObj& update, ClassicTag);
@@ -143,7 +147,12 @@ public:
doc_diff::Diff getDiff() const {
invariant(type() == Type::kDelta);
- return stdx::get<doc_diff::Diff>(_update);
+ return stdx::get<DeltaUpdate>(_update).diff;
+ }
+
+ bool mustCheckExistenceForInsertOperations() const {
+ invariant(type() == Type::kDelta);
+ return stdx::get<DeltaUpdate>(_update).options.mustCheckExistenceForInsertOperations;
}
std::string toString() const {
@@ -157,8 +166,9 @@ public:
sb << "{type: Pipeline, update: "
<< Value(pipeline).toString() << "}";
},
- [&sb](const doc_diff::Diff& diff) {
- sb << "{type: Delta, update: " << diff << "}";
+ [&sb](const DeltaUpdate& delta) {
+ sb << "{type: Delta, update: " << delta.diff
+ << "}";
}},
_update);
@@ -171,7 +181,11 @@ private:
BSONObj bson;
};
using PipelineUpdate = std::vector<BSONObj>;
- stdx::variant<ClassicUpdate, PipelineUpdate, doc_diff::Diff> _update;
+ struct DeltaUpdate {
+ doc_diff::Diff diff;
+ DiffOptions options;
+ };
+ stdx::variant<ClassicUpdate, PipelineUpdate, DeltaUpdate> _update;
};
} // namespace write_ops