2020-04-09 23:32:46 +02:00
|
|
|
/**
|
|
|
|
* Tests that when the profiler (introspect.cpp) wants to log an operation but the
|
|
|
|
* 'system.profiler' collection does not yet exist and the operation context is an interrupted
|
|
|
|
* state, the collection can still be successfully created on the fly.
|
|
|
|
*
|
|
|
|
* This test restarts the server and requires that data persists across restarts.
|
|
|
|
* @tags: [requires_persistence, requires_profiling]
|
|
|
|
*/
|
2019-01-07 19:20:32 +01:00
|
|
|
(function() {
|
2019-07-27 00:20:35 +02:00
|
|
|
"use strict";
|
2019-01-07 19:20:32 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
//
|
|
|
|
// Start mongo with profiling disabled, create an empty database, and populate it with a
|
|
|
|
// collection that has one document.
|
|
|
|
//
|
|
|
|
let standalone = MongoRunner.runMongod({profile: "0"});
|
2019-01-07 19:20:32 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
let db = standalone.getDB("profile_interrupted_op");
|
|
|
|
assert.commandWorked(db.dropDatabase());
|
2019-01-07 19:20:32 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
let coll = db.getCollection("test");
|
|
|
|
assert.commandWorked(coll.insert({a: 1}));
|
2019-01-07 19:20:32 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
//
|
|
|
|
// Stop the mongod and then restart it, this time with profiling enabled. Note that enabling
|
|
|
|
// profiling on a running database would create the 'system.profile' collection, which we don't
|
|
|
|
// yet want created for this test.
|
|
|
|
//
|
|
|
|
MongoRunner.stopMongod(standalone);
|
|
|
|
standalone = MongoRunner.runMongod(
|
|
|
|
{restart: true, cleanData: false, dbpath: standalone.dbpath, profile: "2"});
|
2019-01-07 19:20:32 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
//
|
|
|
|
// Execute a query that will get interrupted for exceeding its 'maxTimeMS' value. The profiler
|
|
|
|
// will attempt to create the 'system.profile' collection while the operation context is already
|
|
|
|
// marked as interrupted.
|
|
|
|
//
|
|
|
|
db = standalone.getDB("profile_interrupted_op");
|
|
|
|
coll = db.getCollection("test");
|
|
|
|
const err = assert.throws(function() {
|
|
|
|
coll.find({
|
|
|
|
$where: function() {
|
|
|
|
sleep(3600);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.maxTimeMS(1000)
|
|
|
|
.count();
|
|
|
|
});
|
|
|
|
assert.contains(
|
|
|
|
err.code, [ErrorCodes.MaxTimeMSExpired, ErrorCodes.Interrupted, ErrorCodes.InternalError], err);
|
2019-01-07 19:20:32 +01:00
|
|
|
|
2020-04-09 23:32:46 +02:00
|
|
|
// The mongod should have created the 'system.profile' collection automatically.
|
2019-07-27 00:20:35 +02:00
|
|
|
const res = db.runCommand({listCollections: 1, filter: {name: "system.profile"}});
|
|
|
|
assert.commandWorked(res);
|
2020-04-09 23:32:46 +02:00
|
|
|
assert.eq(res.cursor.firstBatch.length, 1, res);
|
2019-01-07 19:20:32 +01:00
|
|
|
|
2019-07-27 00:20:35 +02:00
|
|
|
MongoRunner.stopMongod(standalone);
|
2019-01-07 19:20:32 +01:00
|
|
|
})();
|