diff options
author | Jennifer Peshansky <jennifer.peshansky@mongodb.com> | 2021-07-06 19:56:12 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-07-13 22:34:08 +0000 |
commit | 8a2c299813ea322c44e8ffceae6075c42be7b7e3 (patch) | |
tree | 1acbe8fad3bef55b866185ce6ee21df5c51c4482 /jstests | |
parent | 4bdbcf59c1a071b996bfcc95e13ad488ef8d7dea (diff) | |
download | mongo-8a2c299813ea322c44e8ffceae6075c42be7b7e3.tar.gz |
SERVER-51871 Remove remaining code relating to haystack indexes
Diffstat (limited to 'jstests')
3 files changed, 1 insertions, 427 deletions
diff --git a/jstests/core/api_version_unstable_fields.js b/jstests/core/api_version_unstable_fields.js index 113f9ac64cd..e340aa2e42e 100644 --- a/jstests/core/api_version_unstable_fields.js +++ b/jstests/core/api_version_unstable_fields.js @@ -70,7 +70,7 @@ const findCmd = { testCommandWithUnstableFields(aggCmd, unstableFieldsForAggregate); testCommandWithUnstableFields(findCmd, unstableFieldsForFind); -// Test that creating unstable indexes with 'apiStrict: ture' throws. +// Test that creating unstable indexes with 'apiStrict: true' throws. let createIndexesCmd = { createIndexes: collName, indexes: [{key: {a: "text"}, name: "a_1"}], diff --git a/jstests/multiVersion/delete_haystack_indexes_on_upgrade.js b/jstests/multiVersion/delete_haystack_indexes_on_upgrade.js deleted file mode 100644 index 05502bbda88..00000000000 --- a/jstests/multiVersion/delete_haystack_indexes_on_upgrade.js +++ /dev/null @@ -1,218 +0,0 @@ -/** - * Verifies that haystack indexes are removed during the upgrade process from 4.4 to 4.9 for a - * standalone and a replica set. - * - * TODO SERVER-51871: Since this test is specific to the upgrade process from 4.4 to 4.9/5.0, it - * can be deleted once 5.0 becomes last-lts. - */ -(function() { -"use strict"; -load("jstests/multiVersion/libs/multi_rs.js"); // For 'upgradeSet()' -load("jstests/multiVersion/libs/multi_cluster.js"); // For 'upgradeCluster()' -load('jstests/multiVersion/libs/verify_versions.js'); // For 'assert.binVersion()' -load('jstests/noPassthrough/libs/index_build.js'); // For 'assertIndexes()' - -const dbName = "test"; -const collName = jsTestName(); -const geoIndexKey = { - loc: "geoHaystack", - x: 1 -}; -const geoIndexName = "geo"; -const nonGeoIndexKey = { - y: 1 -}; -const nonGeoIndexName = "y"; - -// Set of indexes to insert. -const indexList = ["_id_", nonGeoIndexName, geoIndexName]; - -// Set of indexes that will be present after upgrade is complete. -const nonGeoIndexList = ["_id_", nonGeoIndexName]; - -function insertDocuments(coll) { - const documentList = - [{_id: 0, loc: [1, 2], x: 'foo', y: 2}, {_id: 1, loc: [1.5, 1.5], x: 'bar', y: 1}]; - assert.commandWorked(coll.insert(documentList)); -} - -function createIndexes(coll) { - assert.commandWorked(coll.createIndex(geoIndexKey, {name: geoIndexName, bucketSize: 1})); - assert.commandWorked(coll.createIndex(nonGeoIndexKey, {name: nonGeoIndexName})); -} - -// Verify that haystack indexes are deleted when upgrading a standalone. -function runStandaloneTest() { - // Set up a v4.4 mongod. - const dbPath = MongoRunner.dataPath + "/delete_haystack"; - let mongo = MongoRunner.runMongod({dbpath: dbPath, binVersion: "last-lts"}); - assert.neq(null, mongo, "mongod was unable to start up"); - let testDB = mongo.getDB(dbName); - let coll = testDB[collName]; - insertDocuments(coll); - createIndexes(coll); - IndexBuildTest.assertIndexes(testDB[collName], indexList.length, indexList); - MongoRunner.stopMongod(mongo); - - // Restart the mongod in the latest version. - mongo = MongoRunner.runMongod( - {dbpath: dbPath, binVersion: "latest", restart: true, cleanData: false}); - assert.neq(null, mongo, "mongod was unable to start up"); - testDB = mongo.getDB(dbName); - coll = testDB[collName]; - - // The haystack index should still be present before the FCV is set and the validate command - // should succeed. - IndexBuildTest.assertIndexes(coll, indexList.length, indexList); - const validate = assert.commandWorked(coll.validate({full: true})); - assert.eq(true, validate.valid); - - // Set the FCV. - const adminDB = mongo.getDB("admin"); - checkFCV(adminDB, lastLTSFCV); - assert.commandWorked(mongo.adminCommand({setFeatureCompatibilityVersion: latestFCV})); - checkFCV(adminDB, latestFCV); - - // The haystack index should no longer be present after the FCV is set. - IndexBuildTest.assertIndexes(coll, nonGeoIndexList.length, nonGeoIndexList); - MongoRunner.stopMongod(mongo); -} - -/** - * Verifies that every node in 'replSetTest' has the indexes in 'expectedIndexes'. - */ -function verifyIndexesPresentOnAllNodes(replSetTest, expectedIndexes) { - replSetTest.awaitNodesAgreeOnPrimary(); - for (const node of [replSetTest.getPrimary(), replSetTest.getSecondary()]) { - const db = node.getDB(dbName); - const coll = db[collName]; - IndexBuildTest.assertIndexes(coll, expectedIndexes.length, expectedIndexes); - } -} - -// Verify that haystack indexes get deleted when upgrading a replica set. -function runReplicaSetTest() { - // Set up a replica-set in v4.4. - const rst = new ReplSetTest({nodes: 2, nodeOptions: {binVersion: "last-lts"}}); - rst.startSet(); - rst.initiate(); - - const initialPrimary = rst.getPrimary(); - const primaryDB = initialPrimary.getDB(dbName); - const primaryColl = primaryDB[collName]; - insertDocuments(primaryColl); - createIndexes(primaryColl); - - // Wait until both nodes finish inserting the documents and building the index. - rst.awaitReplication(); - - verifyIndexesPresentOnAllNodes(rst, indexList); - - // Upgrade the replica set. - rst.upgradeSet({binVersion: "latest"}); - rst.awaitNodesAgreeOnPrimary(); - - // Verify that all nodes are in the latest version. - for (const node of rst.nodes) { - assert.binVersion(node, "latest"); - } - - verifyIndexesPresentOnAllNodes(rst, indexList); - - // Set the FCV. - const upgradedPrimary = rst.getPrimary(); - const adminDB = upgradedPrimary.getDB("admin"); - checkFCV(adminDB, lastLTSFCV); - assert.commandWorked(adminDB.runCommand({setFeatureCompatibilityVersion: latestFCV})); - checkFCV(adminDB, latestFCV); - - // Neither the primary nor the secondary should have the haystack index. - verifyIndexesPresentOnAllNodes(rst, nonGeoIndexList); - - rst.stopSet(); -} - -// Even though the 'geoSearch' command is not allowed on sharded clusters, haystack indexes can -// still be created on a sharded cluster. As such, we verify that haystack indexes get deleted -// when upgrading a sharded cluster. -function runShardingTest() { - // Set up a sharded cluster in v4.4. - const st = new ShardingTest({ - shards: 2, - rs: {nodes: 2, binVersion: "last-lts"}, - other: {mongosOptions: {binVersion: "last-lts"}, configOptions: {binVersion: "last-lts"}} - }); - - let mongos = st.s; - const ns = dbName + "." + collName; - - // Create a sharded collection with two chunks, one on each shard: [-inf, 1), [1, inf). This - // guarantees that each shard will have one of the two documents being inserted and both shards - // will create a geoHaystack index. - assert.commandWorked(mongos.adminCommand({enableSharding: dbName})); - assert.commandWorked(mongos.adminCommand({movePrimary: dbName, to: st.shard0.shardName})); - assert.commandWorked(mongos.adminCommand({shardCollection: ns, key: {_id: 1}})); - assert.commandWorked(mongos.adminCommand({split: ns, middle: {_id: 1}})); - - // Move the [1, inf) chunk to shard 1. - assert.commandWorked(mongos.adminCommand( - {moveChunk: ns, find: {_id: 1}, to: st.shard1.shardName, _waitForDelete: true})); - - const db = mongos.getDB(dbName); - const coll = db[collName]; - insertDocuments(coll); - createIndexes(coll); - - // Wait for both shards to finish replicating their document and building the indexes. - st.rs0.awaitReplication(); - st.rs1.awaitReplication(); - - /** - * Verify that each shard has each index in 'expectedIndexes'. - */ - function verifyIndexesOnAllShards(expectedIndexes) { - for (const shard of [st.rs0, st.rs1]) { - verifyIndexesPresentOnAllNodes(shard, expectedIndexes); - } - } - - verifyIndexesOnAllShards(indexList); - - // Upgrade the shards and the config servers. - st.upgradeCluster("latest", {upgradeShards: true, upgradeConfigs: true, upgradeMongos: false}); - st.waitUntilStable(); - - // Indexes should still be present. - verifyIndexesOnAllShards(indexList); - - // Upgrade the mongos. - st.upgradeCluster("latest", {upgradeShards: false, upgradeConfigs: false, upgradeMongos: true}); - st.waitUntilStable(); - - /** - * Verifies that the FCV across 'st' matches 'targetFCV'. - */ - function checkClusterFCV(targetFCV) { - checkFCV(st.configRS.getPrimary().getDB("admin"), targetFCV); - checkFCV(st.shard0.getDB("admin"), targetFCV); - checkFCV(st.shard1.getDB("admin"), targetFCV); - } - - // Set the FCV. - mongos = st.s; - const adminDB = mongos.getDB("admin"); - checkClusterFCV(lastLTSFCV); - verifyIndexesOnAllShards(indexList); - assert.commandWorked(adminDB.runCommand({setFeatureCompatibilityVersion: latestFCV})); - checkClusterFCV(latestFCV); - - // None of the nodes in the cluster should have the haystack index. - verifyIndexesOnAllShards(nonGeoIndexList); - - st.stop(); -} - -runStandaloneTest(); -runReplicaSetTest(); -runShardingTest(); -})();
\ No newline at end of file diff --git a/jstests/multiVersion/haystack_indexes_maintained_correctly.js b/jstests/multiVersion/haystack_indexes_maintained_correctly.js deleted file mode 100644 index f471ef492ab..00000000000 --- a/jstests/multiVersion/haystack_indexes_maintained_correctly.js +++ /dev/null @@ -1,208 +0,0 @@ -/** - * Verifies that haystack indexes cannot be created on 4.9+ binaries, but are maintained - * correctly in mixed version clusters. - * - * TODO SERVER-51871: This test can be deleted once 5.0 becomes last-lts. - */ -(function() { -"use strict"; -load("jstests/multiVersion/libs/multi_rs.js"); // For 'upgradeSecondaries()/upgradePrimary()' -load('jstests/noPassthrough/libs/index_build.js'); // For 'assertIndexes()' -load("jstests/libs/fixture_helpers.js"); // For 'isSharded()' - -const dbName = "test"; -const collName = jsTestName(); -const geoIndexKey = { - loc: "geoHaystack", - x: 1 -}; -const geoIndexName = "geo"; -const indexList = ["_id_", geoIndexName]; -const nonGeoIndexList = ["_id_"]; - -function insertInitialDocuments(coll) { - const documentList = - [{_id: 0, loc: [1, 2], x: 'foo', y: 2}, {_id: 1, loc: [1.5, 1.5], x: 'bar', y: 1}]; - assert.commandWorked(coll.insert(documentList)); -} - -/** - * Calls 'validate()' on 'coll' and verifies that the documents which are inserted into 'coll' - * produce the correct number of index keys for the geoHaystack index in this test. - */ -function validateAndAssertCorrectIndexKeys(coll) { - const validateResult = assert.commandWorked(coll.validate({full: true})); - let validateOutput; - if (FixtureHelpers.isSharded(coll)) { - assert(validateResult.hasOwnProperty("raw")); - validateOutput = validateResult["raw"]; - } else { - validateOutput = validateResult; - } - - // There should be as many index keys as there are documents. - const expectedNumKeys = coll.find().itcount(); - let keys = 0; - if (FixtureHelpers.isSharded(coll)) { - for (const shard of Object.keys(validateOutput)) { - keys += validateOutput[shard]["keysPerIndex"][geoIndexName]; - assert.eq(0, validateOutput[shard]["errors"].length); - assert.eq(true, validateOutput[shard]["valid"]); - } - } else { - keys = validateOutput["keysPerIndex"][geoIndexName]; - assert.eq(0, validateOutput["errors"].length); - assert.eq(true, validateOutput["valid"]); - } - - assert.eq(expectedNumKeys, keys); -} - -// Verify that haystack indexes cannot be created on a standalone in the latest version regardless -// of the FCV. -function runStandaloneTest() { - const mongo = MongoRunner.runMongod({binVersion: "latest"}); - const testDB = mongo.getDB(dbName); - const coll = testDB[collName]; - for (const fcv of [lastLTSFCV, latestFCV]) { - assert.commandWorked(mongo.adminCommand({setFeatureCompatibilityVersion: fcv})); - assert.commandFailedWithCode( - coll.createIndex(geoIndexKey, {name: geoIndexName, bucketSize: 1}), - ErrorCodes.CannotCreateIndex); - } - MongoRunner.stopMongod(mongo); -} - -// Verify that haystack indexes are maintained properly on a mixed version replica set. -function runReplicaSetTest() { - // Set up a mixed version replica-set: both nodes will be initialized to the last-lts - // binary version (4.4), but the secondary will be initialized to the latest binary version. - const rst = new ReplSetTest({nodes: [{binVersion: "last-lts"}, {binVersion: "latest"}]}); - rst.startSet(); - rst.initiate(); - let primaryDB = rst.getPrimary().getDB(dbName); - let primaryColl = primaryDB[collName]; - insertInitialDocuments(primaryColl); - rst.awaitReplication(); - - // Creating a haystack index should still work. - assert.commandWorked(primaryDB.runCommand({ - "createIndexes": collName, - indexes: [{key: geoIndexKey, name: geoIndexName, bucketSize: 1}], - writeConcern: {w: 2} - })); - - // The haystack index should replicate correctly to the secondary. - const secondaryDB = rst.getSecondary().getDB(dbName); - const secondaryColl = secondaryDB[collName]; - IndexBuildTest.assertIndexes(secondaryColl, indexList.length, indexList); - - // Verify that documents which are inserted after the index is built produce valid index keys. - assert.commandWorked( - primaryColl.insert([{_id: 4, loc: [4, 4], x: "baz"}, {_id: 5, loc: [5, 5], x: "baz"}], - {writeConcern: {w: 2}})); - validateAndAssertCorrectIndexKeys(primaryColl); - validateAndAssertCorrectIndexKeys(secondaryColl); - - // Upgrade the primary and attempt to re-create the index after the upgrade. - assert.commandWorked( - primaryDB.runCommand({"dropIndexes": collName, index: geoIndexName, writeConcern: {w: 2}})); - rst.upgradePrimary(rst.getPrimary(), {binVersion: "latest"}); - rst.awaitNodesAgreeOnPrimary(); - - // Even though we haven't bumped the FCV, index creation should still fail on a primary in - // the latest version. - primaryDB = rst.getPrimary().getDB(dbName); - primaryColl = primaryDB[collName]; - assert.commandFailedWithCode( - primaryColl.createIndex(geoIndexKey, {name: geoIndexName, bucketSize: 1}), - ErrorCodes.CannotCreateIndex); - - rst.stopSet(); -} - -// Verify that haystack indexes are maintained properly in a mixed version sharded cluster. -function runShardingTest() { - // Set up a mixed version sharded cluster, where shard0's nodes are initialized to the last-lts - // binary version (4.4) and shard1's nodes are initialized to the latest binary version. - const st = new ShardingTest({ - shards: { - rs0: {nodes: [{binVersion: "last-lts"}, {binVersion: "last-lts"}]}, - rs1: {nodes: [{binVersion: "latest"}, {binVersion: "latest"}]} - }, - other: {mongosOptions: {binVersion: "last-lts"}} - }); - - // Test that indexes are maintained properly during chunk migration. More precisely, verify - // that when a chunk from a shard consisting of 4.4 nodes with a haystack index is moved to a - // shard consisting of nodes in the latest binary version, the haystack index is built - // correctly on the shard in the latest binary version. - const mongos = st.s; - const ns = dbName + "." + collName; - - // Create a sharded collection with two chunks: [MinKey, 1), [1, MaxKey], both on shard0. - assert.commandWorked(mongos.adminCommand({enableSharding: dbName})); - assert.commandWorked(mongos.adminCommand({movePrimary: dbName, to: st.shard0.shardName})); - assert.commandWorked(mongos.adminCommand({shardCollection: ns, key: {_id: 1}})); - assert.commandWorked(mongos.adminCommand({split: ns, middle: {_id: 1}})); - - // Insert some documents and create a haystack index. - const db = mongos.getDB(dbName); - const coll = db[collName]; - insertInitialDocuments(coll); - assert.commandWorked(coll.createIndex(geoIndexKey, {name: geoIndexName, bucketSize: 1})); - - // Wait for shard0 to finish replicating its documents and building the index. - st.rs0.awaitReplication(); - - // Move the [1, MaxKey] chunk to shard1. - assert.commandWorked(mongos.adminCommand( - {moveChunk: ns, find: {_id: 1}, to: st.shard1.shardName, _waitForDelete: true})); - st.rs1.awaitReplication(); - - // Verify that shard1 has the haystack index after the chunk was moved. - const shard1primary = st.rs1.getPrimary(); - const shard1DB = shard1primary.getDB(dbName); - const shard1Coll = shard1DB[collName]; - IndexBuildTest.assertIndexes(shard1Coll, indexList.length, indexList); - - validateAndAssertCorrectIndexKeys(coll); - - // Verify that inserting documents into a shard consisting of nodes in the latest version with - // an existing haystack index will create the correct index keys for the index. - assert.commandWorked( - coll.insert([{_id: 4, loc: [4, 4], x: "baz"}, {_id: 5, loc: [5, 5], x: "blah"}], - {writeConcern: {w: 2}})); - - validateAndAssertCorrectIndexKeys(coll); - - // Creating a new haystack index against a sharded cluster with at least one shard upgraded to - // the latest version should fail. - assert.commandWorked( - db.runCommand({"dropIndexes": collName, index: geoIndexName, writeConcern: {w: 2}})); - assert.commandFailedWithCode(coll.createIndex(geoIndexKey, {name: geoIndexName, bucketSize: 1}), - ErrorCodes.CannotCreateIndex); - - // Though the command failed, the haystack index will still be created on shard0 since it is in - // version 4.4. - const shard0DB = st.rs0.getPrimary().getDB(dbName); - const shard0coll = shard0DB[collName]; - IndexBuildTest.assertIndexes(shard0coll, indexList.length, indexList); - - // Since shard1 is in the latest version, it will not have the geoHaystack index. - IndexBuildTest.assertIndexes(shard1Coll, nonGeoIndexList.length, nonGeoIndexList); - - // Though the 'dropIndexes' command will fail because shard1 does not have the haystack - // index, it should still remove the haystack index on shard0. - assert.commandFailedWithCode( - mongos.getDB(dbName).runCommand( - {"dropIndexes": collName, index: geoIndexName, writeConcern: {w: 2}}), - ErrorCodes.IndexNotFound); - IndexBuildTest.assertIndexes(shard0coll, nonGeoIndexList.length, nonGeoIndexList); - st.stop(); -} - -runStandaloneTest(); -runReplicaSetTest(); -runShardingTest(); -})();
\ No newline at end of file |