2023-08-23 16:07:27 +00:00
|
|
|
// Check that a warning message about doing a capped collection scan for a query with an _id
|
|
|
|
|
// constraint is printed at appropriate times. SERVER-5353
|
|
|
|
|
//
|
2020-08-13 19:13:40 -04:00
|
|
|
// @tags: [
|
2023-08-23 16:07:27 +00:00
|
|
|
// # The test runs commands that are not allowed with security token: getLog.
|
2023-12-11 22:44:46 +00:00
|
|
|
// not_allowed_with_signed_security_token,
|
2020-08-13 19:13:40 -04:00
|
|
|
// does_not_support_stepdowns,
|
|
|
|
|
// requires_capped,
|
2024-12-27 16:01:08 +04:00
|
|
|
// requires_getmore,
|
2020-08-13 19:13:40 -04:00
|
|
|
// ]
|
2017-11-28 10:10:44 -05:00
|
|
|
|
2012-04-22 12:01:52 -07:00
|
|
|
function numWarnings() {
|
2016-03-09 12:17:50 -05:00
|
|
|
let logs = db.adminCommand({getLog: "global"}).log;
|
2012-04-22 12:01:52 -07:00
|
|
|
let ret = 0;
|
2016-03-09 12:17:50 -05:00
|
|
|
logs.forEach(function(x) {
|
|
|
|
|
if (x.match(warningMatchRegexp)) {
|
|
|
|
|
++ret;
|
|
|
|
|
}
|
|
|
|
|
});
|
2012-04-22 12:01:52 -07:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let collectionNameIndex = 0;
|
|
|
|
|
|
|
|
|
|
// Generate a collection name not already present in the log.
|
|
|
|
|
do {
|
2012-05-01 16:48:47 -04:00
|
|
|
var testCollectionName = 'jstests_queryoptimizera__' + collectionNameIndex++;
|
2016-03-09 12:17:50 -05:00
|
|
|
var warningMatchString =
|
|
|
|
|
'unindexed _id query on capped collection.*collection: test.' + testCollectionName;
|
|
|
|
|
var warningMatchRegexp = new RegExp(warningMatchString);
|
2012-04-22 12:01:52 -07:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
} while (numWarnings() > 0);
|
|
|
|
|
|
|
|
|
|
let t = db[testCollectionName];
|
2012-04-22 12:01:52 -07:00
|
|
|
t.drop();
|
|
|
|
|
|
|
|
|
|
let notCappedCollectionName = testCollectionName + '_notCapped';
|
|
|
|
|
|
2018-04-13 09:02:26 -04:00
|
|
|
let notCapped = db.getSiblingDB("local").getCollection(notCappedCollectionName);
|
2012-04-22 12:01:52 -07:00
|
|
|
notCapped.drop();
|
|
|
|
|
|
2018-04-13 09:02:26 -04:00
|
|
|
assert.commandWorked(db.createCollection(testCollectionName, {capped: true, size: 1000}));
|
2025-03-26 10:17:46 +01:00
|
|
|
assert.commandWorked(notCapped.getDB().createCollection(notCappedCollectionName));
|
2012-04-22 12:01:52 -07:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
t.insert({});
|
|
|
|
|
notCapped.insert({});
|
2012-04-22 12:01:52 -07:00
|
|
|
|
|
|
|
|
let oldNumWarnings = 0;
|
|
|
|
|
|
|
|
|
|
function assertNoNewWarnings() {
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.eq(oldNumWarnings, numWarnings());
|
2012-04-22 12:01:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function assertNewWarning() {
|
2012-07-24 15:43:50 -07:00
|
|
|
let newNumWarnings = numWarnings();
|
|
|
|
|
// Ensure that newNumWarnings > oldNumWarnings. It's not safe to test that oldNumWarnings + 1
|
|
|
|
|
// == newNumWarnings, because a (simulated) page fault exception may cause multiple messages to
|
|
|
|
|
// be logged instead of only one.
|
2016-03-09 12:17:50 -05:00
|
|
|
assert.lt(oldNumWarnings, newNumWarnings);
|
2012-07-24 15:43:50 -07:00
|
|
|
oldNumWarnings = newNumWarnings;
|
2012-04-22 12:01:52 -07:00
|
|
|
}
|
|
|
|
|
|
2012-08-02 08:14:22 -04:00
|
|
|
// Simple _id query
|
2016-03-09 12:17:50 -05:00
|
|
|
t.find({_id: 0}).itcount();
|
2012-08-02 08:14:22 -04:00
|
|
|
assertNoNewWarnings();
|
2012-04-22 12:01:52 -07:00
|
|
|
|
|
|
|
|
// Simple _id query without an _id index, on a non capped collection.
|
2016-03-09 12:17:50 -05:00
|
|
|
notCapped.find({_id: 0}).itcount();
|
2012-04-22 12:01:52 -07:00
|
|
|
assertNoNewWarnings();
|
|
|
|
|
|
|
|
|
|
// A multi field query, including _id.
|
2016-03-09 12:17:50 -05:00
|
|
|
t.find({_id: 0, a: 0}).itcount();
|
2012-08-02 08:14:22 -04:00
|
|
|
assertNoNewWarnings();
|
2012-04-22 12:01:52 -07:00
|
|
|
|
|
|
|
|
// An unsatisfiable query.
|
2016-03-09 12:17:50 -05:00
|
|
|
t.find({_id: 0, a: {$in: []}}).itcount();
|
2012-04-22 12:01:52 -07:00
|
|
|
assertNoNewWarnings();
|
|
|
|
|
|
|
|
|
|
// An hinted query.
|
2016-03-09 12:17:50 -05:00
|
|
|
t.find({_id: 0}).hint({$natural: 1}).itcount();
|
2012-04-22 12:01:52 -07:00
|
|
|
assertNoNewWarnings();
|
|
|
|
|
|
|
|
|
|
// Retry a multi field query.
|
2016-03-09 12:17:50 -05:00
|
|
|
t.find({_id: 0, a: 0}).itcount();
|
2012-08-02 08:14:22 -04:00
|
|
|
assertNoNewWarnings();
|
2012-04-22 12:01:52 -07:00
|
|
|
|
|
|
|
|
// Warnings should not be printed when an index is added on _id.
|
2020-11-17 13:45:05 +00:00
|
|
|
t.createIndex({_id: 1});
|
2012-04-22 12:01:52 -07:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
t.find({_id: 0}).itcount();
|
2012-04-22 12:01:52 -07:00
|
|
|
assertNoNewWarnings();
|
|
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
t.find({_id: 0, a: 0}).itcount();
|
2012-04-22 12:01:52 -07:00
|
|
|
assertNoNewWarnings();
|
|
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
t.find({_id: 0, a: 0}).itcount();
|
2012-04-22 12:01:52 -07:00
|
|
|
assertNoNewWarnings();
|
2012-05-01 16:48:47 -04:00
|
|
|
|
2016-03-09 12:17:50 -05:00
|
|
|
t.drop(); // cleanup
|
2018-04-13 09:02:26 -04:00
|
|
|
notCapped.drop();
|