mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 01:21:03 +01:00
SERVER-41756 source namespace is not reported correctly if $out is used
This commit is contained in:
parent
a0b282227f
commit
40f401824c
54
jstests/noPassthrough/aggregation_log_namespace.js
Normal file
54
jstests/noPassthrough/aggregation_log_namespace.js
Normal file
@ -0,0 +1,54 @@
|
||||
// Tests that a source collection namespace is correctly logged in the global log for an aggregate
|
||||
// command when a pipeline contains a stage that can write into an output collection.
|
||||
// @tags: [requires_profiling]
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
load("jstests/aggregation/extras/merge_helpers.js"); // For withEachKindOfWriteStage.
|
||||
load("jstests/libs/check_log.js"); // For checkLogs.containsWithCount.
|
||||
|
||||
// Runs the given 'pipeline' and verifies that the namespace is correctly logged in the global
|
||||
// log for the aggregate command. The 'comment' parameter is used to match a log entry against
|
||||
// the aggregate command.
|
||||
function verifyLoggedNamespace({pipeline, comment}) {
|
||||
assert.commandWorked(db.runCommand(
|
||||
{aggregate: source.getName(), comment: comment, pipeline: pipeline, cursor: {}}));
|
||||
checkLog.containsWithCount(
|
||||
conn,
|
||||
`command ${source.getFullName()} appName: "MongoDB Shell" ` +
|
||||
`command: aggregate { aggregate: "${source.getName()}", comment: "${comment}"`,
|
||||
1);
|
||||
}
|
||||
|
||||
const mongodOptions = {};
|
||||
const conn = MongoRunner.runMongod(mongodOptions);
|
||||
assert.neq(null, conn, `mongod failed to start with options ${tojson(mongodOptions)}`);
|
||||
|
||||
const db = conn.getDB(`${jsTest.name()}_db`);
|
||||
const source = db.getCollection(`${jsTest.name()}_source`);
|
||||
source.drop();
|
||||
const target = db.getCollection(`${jsTest.name()}_target`);
|
||||
target.drop();
|
||||
|
||||
// Make sure each command gets logged.
|
||||
assert.commandWorked(db.setProfilingLevel(1, {slowms: 0}));
|
||||
|
||||
// Test stages that can write into an output collection.
|
||||
withEachKindOfWriteStage(
|
||||
target,
|
||||
(stage) => verifyLoggedNamespace({pipeline: [stage], comment: Object.keys(stage)[0]}));
|
||||
|
||||
// Test each $merge mode.
|
||||
withEachMergeMode(({whenMatchedMode, whenNotMatchedMode}) => verifyLoggedNamespace({
|
||||
pipeline: [{
|
||||
$merge: {
|
||||
into: target.getName(),
|
||||
whenMatched: whenMatchedMode,
|
||||
whenNotMatched: whenNotMatchedMode
|
||||
}
|
||||
}],
|
||||
comment: `merge_${whenMatchedMode}_${whenNotMatchedMode}`
|
||||
}));
|
||||
|
||||
MongoRunner.stopMongod(conn);
|
||||
})();
|
@ -784,6 +784,15 @@ Status runAggregate(OperationContext* opCtx,
|
||||
}
|
||||
}
|
||||
|
||||
// The aggregation pipeline may change the namespace of the curop and we need to set it back to
|
||||
// the original namespace to correctly report command stats. One example when the namespace can
|
||||
// be changed is when the pipeline contains an $out stage, which executes an internal command to
|
||||
// create a temp collection, changing the curop namespace to the name of this temp collection.
|
||||
{
|
||||
stdx::lock_guard<Client> lk(*opCtx->getClient());
|
||||
curOp->setNS_inlock(origNss.ns());
|
||||
}
|
||||
|
||||
// Any code that needs the cursor pinned must be inside the try block, above.
|
||||
return Status::OK();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user