From a9b3e74fc67e172be889fac1bcb3bfeba7572b07 Mon Sep 17 00:00:00 2001 From: Allison Easton Date: Tue, 11 Jun 2024 13:05:39 +0200 Subject: [PATCH] SERVER-91203 AutoGetters should establish capped snapshots for secondary namespaces (#23157) GitOrigin-RevId: 8426ffda43d081c4ee4b92a9fe3f43fa13fe77c7 --- jstests/noPassthrough/lookup_profile.js | 22 ++++++++++++++++++++++ src/mongo/db/db_raii.cpp | 5 +++++ 2 files changed, 27 insertions(+) create mode 100644 jstests/noPassthrough/lookup_profile.js diff --git a/jstests/noPassthrough/lookup_profile.js b/jstests/noPassthrough/lookup_profile.js new file mode 100644 index 00000000000..7327cdcbfdb --- /dev/null +++ b/jstests/noPassthrough/lookup_profile.js @@ -0,0 +1,22 @@ +// Tests that lookups on local capped collections acquire a snapshot on the capped collection +// correctly. Tests the scenario fixed by SERVER-91203 no longer causes a crash. + +let rst = new ReplSetTest({nodes: {n0: {profile: "0"}}}); +rst.startSet(); +rst.initiate(); + +const dbName = "test"; +const collName = "foo"; + +let testDB = rst.getPrimary().getDB(dbName); +let testColl = testDB.getCollection(collName); + +testColl.insert({a: 1}); + +testDB.setProfilingLevel(2); + +const pipeline = + [{$lookup: {from: 'system.profile', localField: 'key', foreignField: 'key', as: 'results'}}]; +testColl.aggregate(pipeline).toArray(); + +rst.stopSet(); diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp index 1c268feadef..d614b6cb8af 100644 --- a/src/mongo/db/db_raii.cpp +++ b/src/mongo/db/db_raii.cpp @@ -601,6 +601,11 @@ ConsistentCatalogAndSnapshot getConsistentCatalogAndSnapshot( // openCollection is eventually called to construct a Collection object from the durable // catalog. establishCappedSnapshotIfNeeded(opCtx, catalogBeforeSnapshot, nsOrUUID); + if (resolvedSecondaryNamespaces) { + for (const auto& secondaryNss : *resolvedSecondaryNamespaces) { + establishCappedSnapshotIfNeeded(opCtx, catalogBeforeSnapshot, {secondaryNss}); + } + } shard_role_details::getRecoveryUnit(opCtx)->preallocateSnapshot();