Skip to content

Commit 3cdbded

Browse files
Martin Neupauerevergreen
authored andcommitted
SERVER-42181 Make WorkingSetMember hold Document instead of BSONObj
SERVER-42157 Unowned mode for Document/Value
1 parent ffd486c commit 3cdbded

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+345
-297
lines changed

src/mongo/db/commands/list_collections.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void _addWorkingSetMember(OperationContext* opCtx,
131131
WorkingSetMember* member = ws->get(id);
132132
member->keyData.clear();
133133
member->recordId = RecordId();
134-
member->obj = Snapshotted<BSONObj>(SnapshotId(), maybe);
134+
member->resetDocument(SnapshotId(), maybe);
135135
member->transitionToOwnedObj();
136136
root->pushBack(id);
137137
}

src/mongo/db/commands/list_indexes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class CmdListIndexes : public BasicCommand {
190190
WorkingSetMember* member = ws->get(id);
191191
member->keyData.clear();
192192
member->recordId = RecordId();
193-
member->obj = Snapshotted<BSONObj>(SnapshotId(), indexSpec.getOwned());
193+
member->resetDocument(SnapshotId(), indexSpec.getOwned());
194194
member->transitionToOwnedObj();
195195
root->pushBack(id);
196196
}

src/mongo/db/exec/and_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class AndCommon {
6464
invariant(src.getState() == WorkingSetMember::RID_AND_OBJ);
6565

6666
// 'src' has the full document but 'dest' doesn't so we need to copy it over.
67-
dest->obj = src.obj;
67+
dest->doc = src.doc;
6868
dest->makeObjOwnedIfNeeded();
6969

7070
// We have an object so we don't need key data.

src/mongo/db/exec/cached_plan.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ Status CachedPlanStage::pickBestPlan(PlanYieldPolicy* yieldPolicy) {
139139
} else if (PlanStage::FAILURE == state) {
140140
// On failure, fall back to replanning the whole query. We neither evict the
141141
// existing cache entry nor cache the result of replanning.
142-
BSONObj statusObj;
143-
WorkingSetCommon::getStatusMemberObject(*_ws, id, &statusObj);
142+
BSONObj statusObj = WorkingSetCommon::getStatusMemberDocument(*_ws, id)->toBson();
144143

145144
LOG(1) << "Execution of cached plan failed, falling back to replan."
146145
<< " query: " << redact(_canonicalQuery->toStringShort())

src/mongo/db/exec/change_stream_proxy.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ ChangeStreamProxyStage::ChangeStreamProxyStage(OperationContext* opCtx,
5050
_latestOplogTimestamp = ResumeToken::parse(_postBatchResumeToken).getData().clusterTime;
5151
}
5252

53-
boost::optional<BSONObj> ChangeStreamProxyStage::getNextBson() {
53+
boost::optional<Document> ChangeStreamProxyStage::getNext() {
5454
if (auto next = _pipeline->getNext()) {
5555
// While we have more results to return, we track both the timestamp and the resume token of
5656
// the latest event observed in the oplog, the latter via its sort key metadata field.
57-
auto nextBSON = _validateAndConvertToBSON(*next);
57+
_validateResumeToken(*next);
5858
_latestOplogTimestamp = PipelineD::getLatestOplogTimestamp(_pipeline.get());
5959
_postBatchResumeToken = next->metadata().getSortKey();
6060
_setSpeculativeReadTimestamp();
61-
return nextBSON;
61+
return next;
6262
}
6363

6464
// We ran out of results to return. Check whether the oplog cursor has moved forward since the
@@ -76,10 +76,10 @@ boost::optional<BSONObj> ChangeStreamProxyStage::getNextBson() {
7676
return boost::none;
7777
}
7878

79-
BSONObj ChangeStreamProxyStage::_validateAndConvertToBSON(const Document& event) const {
79+
void ChangeStreamProxyStage::_validateResumeToken(const Document& event) const {
8080
// If we are producing output to be merged on mongoS, then no stages can have modified the _id.
8181
if (_includeMetaData) {
82-
return event.toBsonWithMetaData();
82+
return;
8383
}
8484
// Confirm that the document _id field matches the original resume token in the sort key field.
8585
auto eventBSON = event.toBson();
@@ -95,7 +95,6 @@ BSONObj ChangeStreamProxyStage::_validateAndConvertToBSON(const Document& event)
9595
<< BSON("_id" << resumeToken) << " but found: "
9696
<< (eventBSON["_id"] ? BSON("_id" << eventBSON["_id"]) : BSONObj()),
9797
idField.binaryEqual(resumeToken));
98-
return eventBSON;
9998
}
10099

101100
void ChangeStreamProxyStage::_setSpeculativeReadTimestamp() {

src/mongo/db/exec/change_stream_proxy.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ class ChangeStreamProxyStage final : public PipelineProxyStage {
7777
}
7878

7979
protected:
80-
boost::optional<BSONObj> getNextBson() final;
80+
boost::optional<Document> getNext() final;
8181

8282
private:
8383
/**
84-
* Verifies that the docs's resume token has not been modified, then converts the doc to BSON.
84+
* Verifies that the docs's resume token has not been modified.
8585
*/
86-
BSONObj _validateAndConvertToBSON(const Document& event) const;
86+
void _validateResumeToken(const Document& event) const;
8787

8888
/**
8989
* Set the speculative majority read timestamp if we have scanned up to a certain oplog

src/mongo/db/exec/collection_scan.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ PlanStage::StageState CollectionScan::doWork(WorkingSetID* out) {
186186
WorkingSetID id = _workingSet->allocate();
187187
WorkingSetMember* member = _workingSet->get(id);
188188
member->recordId = record->id;
189-
member->obj = {getOpCtx()->recoveryUnit()->getSnapshotId(), record->data.releaseToBson()};
189+
member->resetDocument(getOpCtx()->recoveryUnit()->getSnapshotId(),
190+
record->data.releaseToBson());
190191
_workingSet->transitionToRecordIdAndObj(id);
191192

192193
return returnIfMatches(member, id, out);

src/mongo/db/exec/delete.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,11 @@ PlanStage::StageState DeleteStage::doWork(WorkingSetID* out) {
183183
if (_params->returnDeleted) {
184184
// Save a copy of the document that is about to get deleted, but keep it in the RID_AND_OBJ
185185
// state in case we need to retry deleting it.
186-
BSONObj deletedDoc = member->obj.value();
187-
member->obj.setValue(deletedDoc.getOwned());
186+
member->makeObjOwnedIfNeeded();
188187
}
189188

190189
if (_params->removeSaver) {
191-
uassertStatusOK(_params->removeSaver->goingToDelete(member->obj.value()));
190+
uassertStatusOK(_params->removeSaver->goingToDelete(member->doc.value().toBson()));
192191
}
193192

194193
// TODO: Do we want to buffer docs and delete them in a group rather than saving/restoring state

src/mongo/db/exec/filter.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ namespace mongo {
4242
*/
4343
class WorkingSetMatchableDocument : public MatchableDocument {
4444
public:
45-
WorkingSetMatchableDocument(WorkingSetMember* wsm) : _wsm(wsm) {}
45+
WorkingSetMatchableDocument(WorkingSetMember* wsm)
46+
: _wsm(wsm), _obj(_wsm->doc.value().toBson()) {}
4647

4748
// This is only called by a $where query. The query system must be smart enough to realize
4849
// that it should do a fetch beforehand.
4950
BSONObj toBSON() const {
50-
invariant(_wsm->hasObj());
51-
return _wsm->obj.value();
51+
return _obj;
5252
}
5353

5454
ElementIterator* allocateIterator(const ElementPath* path) const final {
5555
// BSONElementIterator does some interesting things with arrays that I don't think
5656
// SimpleArrayElementIterator does.
5757
if (_wsm->hasObj()) {
58-
return new BSONElementIterator(path, _wsm->obj.value());
58+
return new BSONElementIterator(path, _obj);
5959
}
6060

6161
// NOTE: This (kind of) duplicates code in WorkingSetMember::getFieldDotted.
@@ -95,6 +95,7 @@ class WorkingSetMatchableDocument : public MatchableDocument {
9595

9696
private:
9797
WorkingSetMember* _wsm;
98+
BSONObj _obj;
9899
};
99100

100101
class IndexKeyMatchableDocument : public MatchableDocument {

src/mongo/db/exec/geo_near.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static StatusWith<double> computeGeoNearDistance(const GeoNearParams& nearParams
151151

152152
// Extract all the geometries out of this document for the near query
153153
std::vector<std::unique_ptr<StoredGeometry>> geometries;
154-
extractGeometries(member->obj.value(), nearParams.nearQuery->field, &geometries);
154+
extractGeometries(member->doc.value().toBson(), nearParams.nearQuery->field, &geometries);
155155

156156
// Compute the minimum distance of all the geometries in the document
157157
double minDistance = -1;

0 commit comments

Comments
 (0)