summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/run_aggregate.cpp
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2022-12-16 08:51:00 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-12-16 09:22:51 +0000
commit11b5cafdb964e68eb892e413ee893bdb20a7574e (patch)
tree2f691d59dbba3b2a8249eb032a4189a1b28fa307 /src/mongo/db/commands/run_aggregate.cpp
parentcbad1f3c68f18b2d836fc191c00ae7b45968ac8b (diff)
downloadmongo-11b5cafdb964e68eb892e413ee893bdb20a7574e.tar.gz
SERVER-66145 Prevent operations from writing with read tickets
Since we do not support ticket upgrades, this effectively bans global lock upgrades
Diffstat (limited to 'src/mongo/db/commands/run_aggregate.cpp')
-rw-r--r--src/mongo/db/commands/run_aggregate.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp
index f2f06d1c9c7..225896a6b5f 100644
--- a/src/mongo/db/commands/run_aggregate.cpp
+++ b/src/mongo/db/commands/run_aggregate.cpp
@@ -689,6 +689,14 @@ Status runAggregate(OperationContext* opCtx,
// The UUID of the collection for the execution namespace of this aggregation.
boost::optional<UUID> uuid;
+ // All cursors share the ownership to 'extDataSrcGuard'. Once all cursors are destroyed,
+ // 'extDataSrcGuard' will also be destroyed and any virtual collections will be dropped by
+ // the destructor of ExternalDataSourceScopeGuard. We obtain a reference before taking locks so
+ // that the virtual collections will be dropped after releasing our read locks, avoiding a lock
+ // upgrade.
+ std::shared_ptr<ExternalDataSourceScopeGuard> extDataSrcGuard =
+ std::make_shared<ExternalDataSourceScopeGuard>(std::move(externalDataSourceGuard));
+
// If emplaced, AutoGetCollectionForReadCommand will throw if the sharding version for this
// connection is out of date. If the namespace is a view, the lock will be released before
// re-running the expanded aggregation.
@@ -1038,8 +1046,6 @@ Status runAggregate(OperationContext* opCtx,
p.deleteUnderlying();
}
});
- auto extDataSrcGuard =
- std::make_shared<ExternalDataSourceScopeGuard>(std::move(externalDataSourceGuard));
for (auto&& exec : execs) {
ClientCursorParams cursorParams(
std::move(exec),
@@ -1057,9 +1063,6 @@ Status runAggregate(OperationContext* opCtx,
pin->incNBatches();
cursors.emplace_back(pin.getCursor());
- // All cursors share the ownership to 'extDataSrcGuard' and if the last cursor is destroyed,
- // 'extDataSrcGuard' is also destroyed and created virtual collections are dropped by the
- // destructor of ExternalDataSourceScopeGuard.
ExternalDataSourceScopeGuard::get(pin.getCursor()) = extDataSrcGuard;
pins.emplace_back(std::move(pin));
}