Files
mongo/jstests/multiVersion/genericBinVersion/query_stats_key_hash_version_consistency.js
Nick Zolnierz 3e0ff89ff1 SERVER-94971 Add query ownership for files under jstests/libs (#27375)
GitOrigin-RevId: 36330925597c2fca287c2d73bcb6743026f316b4
2024-10-02 11:50:41 +00:00

58 lines
2.0 KiB
JavaScript

/**
* Tests that query stats key hashes are consistent across versions.
* TODO SERVER-93204 Add queryShapeHash to this test.
*/
import "jstests/multiVersion/libs/multi_rs.js";
import {
getQueryStatsFindCmd,
getQueryStatsKeyHashes
} from "jstests/libs/query/query_stats_utils.js";
import {ReplSetTest} from "jstests/libs/replsettest.js";
const rst = new ReplSetTest({
nodes:
{n1: {binVersion: "last-lts"}, n2: {binVersion: "last-lts"}, n3: {binVersion: "last-lts"}}
});
// Turn on the collecting of query stats metrics.
rst.startSet({setParameter: {internalQueryStatsRateLimit: -1}});
rst.initiate();
let conn = rst.getPrimary();
const collName = jsTestName();
let coll = conn.getDB("test")[collName];
coll.drop();
coll.insert({x: 5});
// Run a few unique queries so that they generate different query stats entries.
function runQueries() {
coll.find({x: 5}).toArray();
coll.find({y: 5}).toArray();
coll.find({y: 5}).sort({x: -1}).toArray();
coll.find({y: 5}).maxTimeMS(123).toArray();
}
// First, collect and save query stats entries on the older version.
runQueries();
const preUpgradeEntries = getQueryStatsFindCmd(conn, {collName, transformIdentifiers: false});
assert.eq(preUpgradeEntries.length, 4, tojson(preUpgradeEntries));
const preUpgradeKeyHashes = getQueryStatsKeyHashes(preUpgradeEntries);
// Upgrade to the latest.
rst.upgradeSet({binVersion: 'latest'});
conn = rst.getPrimary();
coll = conn.getDB("test")[collName];
// Run the same queries again and check that we got the same query stats key hash values as we did
// on the old version.
runQueries();
const postUpgradeEntries = getQueryStatsFindCmd(conn, {collName, transformIdentifiers: false});
assert.eq(postUpgradeEntries.length, 4, tojson(postUpgradeEntries));
const postUpgradeKeyHashes = getQueryStatsKeyHashes(postUpgradeEntries);
assert.sameMembers(postUpgradeKeyHashes,
preUpgradeKeyHashes,
`preUpgradeEntries = ${tojson(preUpgradeEntries)}, postUpgradeEntries = ${
tojson(postUpgradeEntries)}`);
rst.stopSet();