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();