diff options
author | Antonio Fuschetto <antonio.fuschetto@mongodb.com> | 2021-08-26 21:04:10 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-08-26 21:26:26 +0000 |
commit | 7f1ec52be8e1a04af3fa542d3de245d83adddd01 (patch) | |
tree | 20ffdf20b8b4460a3e3c1afecd9b4d8befcd237b /jstests | |
parent | f40810c7c8706754b647992fbde1dc2745616b7c (diff) | |
download | mongo-7f1ec52be8e1a04af3fa542d3de245d83adddd01.tar.gz |
SERVER-58574 Modify the setFCV command to set/unset the long names flag
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/libs/parallelTester.js | 4 | ||||
-rw-r--r-- | jstests/multiVersion/upgrade_downgrade_sharded_cluster.js | 230 | ||||
-rw-r--r-- | jstests/sharding/long_collection_names.js | 87 |
3 files changed, 165 insertions, 156 deletions
diff --git a/jstests/libs/parallelTester.js b/jstests/libs/parallelTester.js index c52a0c06f69..fa0202287ea 100644 --- a/jstests/libs/parallelTester.js +++ b/jstests/libs/parallelTester.js @@ -200,10 +200,6 @@ if (typeof _threadInject != "undefined") { "views/views_all_commands.js", // Drops test DB. "views/view_with_invalid_dbname.js", // Puts invalid view definitions in system.views. - // This test works close to the BSON document limit for entries in the durable catalog, - // so running it in parallel with other tests will cause failures. - "long_collection_names.js", - // This test causes collMod commands to hang, which interferes with other tests running // collMod. "crud_ops_do_not_throw_locktimeout.js", diff --git a/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js b/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js index 92e687cdfcf..529727c0131 100644 --- a/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js +++ b/jstests/multiVersion/upgrade_downgrade_sharded_cluster.js @@ -1,102 +1,202 @@ /** - * The goal of this test is to verify that some metadata is properly updated when - * upgrading/downgrading a sharded cluster. More specifically: + * Verify that some metadata is properly changed after the upgrade and downgrade of a sharded + * cluster. More specifically: * - * 1. We create a sharded cluster running and old binary version (lastLTSFCV or lastContinuousFCV) - * 2. We setup some state on cluster - * 3. We upgrade the binaries of the sharded cluster to the latest version + set FCV to latestFCV - * 4. We verify that upgrade procedures have been performed - * 5. We set FCV to old bin version + downgrade the binaries of the sharded cluster to that version - * 6. We verify that downgrade procedures have been performed - * - * @tags: [disabled_due_to_server_58295] + * 1. Create a sharded cluster in replica set running an old binary version + * 2. Setup some data on cluster + * 3. Upgrade binaries and FCV of the cluster to the latest version + * 4. Verify the data consistency after the upgrade procedure + * 5. Downgrade binaries and FCV of the cluster to an old version + * 6. Verify the data consistency after the downgrade procedure */ (function() { -"use strict"; +'use strict'; + +load('jstests/libs/uuid_util.js'); // For extractUUIDFromObject +load('jstests/multiVersion/libs/multi_cluster.js'); // For upgradeCluster + +function setupClusterAndDatabase(binVersion) { + const st = new ShardingTest({ + mongos: 1, + config: 1, + shards: 2, + other: { + mongosOptions: {binVersion: binVersion}, + configOptions: {binVersion: binVersion}, + shardOptions: {binVersion: binVersion}, + rs: {nodes: 2} + } + }); + st.configRS.awaitReplication(); -load('./jstests/multiVersion/libs/multi_cluster.js'); // for upgradeCluster() + assert.commandWorked( + st.s.adminCommand({enableSharding: jsTestName(), primaryShard: st.shard0.shardName})); -function setupInitialStateOnOldVersion(oldVersion) { + return st; +} + +function getNodeName(node) { + const info = node.adminCommand({hello: 1}); + return info.setName + '_' + (info.secondary ? 'secondary' : 'primary'); } function checkConfigAndShardsFCV(expectedFCV) { - var configFCV = st.configRS.getPrimary() - .adminCommand({getParameter: 1, featureCompatibilityVersion: 1}) - .featureCompatibilityVersion.version; - assert.eq(expectedFCV, configFCV); - - var shard0FCV = st.rs0.getPrimary() - .adminCommand({getParameter: 1, featureCompatibilityVersion: 1}) - .featureCompatibilityVersion.version; - assert.eq(expectedFCV, shard0FCV); - - var shard1FCV = st.rs1.getPrimary() - .adminCommand({getParameter: 1, featureCompatibilityVersion: 1}) - .featureCompatibilityVersion.version; - assert.eq(expectedFCV, shard1FCV); + const configPrimary = st.configRS.getPrimary(); + + const shard0Primary = st.rs0.getPrimary(); + const shard0Secondary = st.rs0.getSecondary(); + shard0Secondary.setSecondaryOk(); + + const shard1Primary = st.rs1.getPrimary(); + const shard1Secondary = st.rs1.getSecondary(); + shard1Secondary.setSecondaryOk(); + + for (const node + of [configPrimary, shard0Primary, shard0Secondary, shard1Primary, shard1Secondary]) { + jsTest.log('Verify that the FCV is properly set on node ' + getNodeName(node)); + + const fcvDoc = node.adminCommand({getParameter: 1, featureCompatibilityVersion: 1}); + assert.eq(expectedFCV, fcvDoc.featureCompatibilityVersion.version); + } +} + +var collIndex = 1; +function createShardedCollection() { + const collNs = jsTestName() + '.sharded_coll' + collIndex++; + assert.commandWorked(st.s.adminCommand({shardCollection: collNs, key: {x: 1}})); + + const coll = st.s.getCollection(collNs); + assert.commandWorked(coll.insert({x: -1})); + assert.commandWorked(coll.insert({x: 1})); + + assert.commandWorked(st.s.adminCommand({split: collNs, middle: {x: 0}})); + assert.commandWorked( + st.s.adminCommand({moveChunk: collNs, find: {x: 1}, to: st.shard1.shardName})); + + return collNs; +} + +function testDisabledLongNameSupport(collNs) { + jsTestLog('Verify that long name support is properly disabled on collection ' + collNs); + + const collConfigDoc = st.s.getDB('config').collections.findOne({_id: collNs}); + assert.eq(collConfigDoc.supportingLongName, undefined); + + const shard0Primary = st.rs0.getPrimary(); + const shard0Secondary = st.rs0.getSecondary(); + shard0Secondary.setSecondaryOk(); + + const shard1Primary = st.rs1.getPrimary(); + const shard1Secondary = st.rs1.getSecondary(); + shard1Secondary.setSecondaryOk(); + + for (const node of [shard0Primary, shard0Secondary, shard1Primary, shard1Secondary]) { + jsTestLog('Verify the consistency of the persisted cache on node ' + getNodeName(node)); + + const configDb = node.getDB('config'); + + const cachedCollDoc = configDb['cache.collections'].findOne({_id: collNs}); + assert.neq(cachedCollDoc, null); + + assert(configDb['cache.chunks.' + collNs].exists()); + assert(!configDb['cache.chunks.' + extractUUIDFromObject(cachedCollDoc.uuid)].exists()); + } } -function runChecksAfterUpgrade() { - checkConfigAndShardsFCV(latestFCV); +function testImplicitlyEnabledLongNameSupport(collNs) { + jsTestLog('Verify that long name support is properly enabled on collection ' + collNs); + + const collConfigDoc = st.s.getDB('config').collections.findOne({_id: collNs}); + assert.eq(collConfigDoc.supportingLongName, 'implicitly_enabled'); + + const shard0Primary = st.rs0.getPrimary(); + const shard0Secondary = st.rs0.getSecondary(); + shard0Secondary.setSecondaryOk(); + + const shard1Primary = st.rs1.getPrimary(); + const shard1Secondary = st.rs1.getSecondary(); + shard1Secondary.setSecondaryOk(); + + for (const node of [shard0Primary, shard0Secondary, shard1Primary, shard1Secondary]) { + jsTestLog('Verify the consistency of the persisted cache on node ' + getNodeName(node)); + + const configDb = node.getDB('config'); + + const cachedCollDoc = configDb['cache.collections'].findOne({_id: collNs}); + assert.neq(cachedCollDoc, null); + + assert(!configDb['cache.chunks.' + collNs].exists()); + assert(configDb['cache.chunks.' + extractUUIDFromObject(cachedCollDoc.uuid)].exists()); + } } -function setupStateBeforeDowngrade() { +function checkClusterBeforeUpgrade(fcv, collNs) { + checkConfigAndShardsFCV(fcv); + testDisabledLongNameSupport(collNs); } -function runChecksAfterFCVDowngrade(oldVersion) { - checkConfigAndShardsFCV(oldVersion); +function checkClusterAfterBinaryUpgrade() { + // To implement in the future, if necessary. } -function runChecksAfterBinDowngrade() { +function checkClusterAfterFCVUpgrade(fcv, call1Ns, call2Ns) { + checkConfigAndShardsFCV(fcv); + testImplicitlyEnabledLongNameSupport(call1Ns); + testImplicitlyEnabledLongNameSupport(call2Ns); } -for (let oldVersion of [lastLTSFCV, lastContinuousFCV]) { - var st = new ShardingTest({ - shards: 2, - mongos: 1, - other: { - mongosOptions: {binVersion: oldVersion}, - configOptions: {binVersion: oldVersion}, - shardOptions: {binVersion: oldVersion}, +function checkClusterAfterFCVDowngrade() { + // To implement in the future, if necessary. +} - rsOptions: {binVersion: oldVersion}, - rs: true, - } - }); +function checkClusterAfterBinaryDowngrade(fcv, call1Ns, call2Ns, call3Ns) { + checkConfigAndShardsFCV(fcv); + testDisabledLongNameSupport(call1Ns); + testDisabledLongNameSupport(call2Ns); + testDisabledLongNameSupport(call3Ns); +} - jsTest.log('oldVersion: ' + oldVersion); +for (const oldVersion of [lastLTSFCV, lastContinuousFCV]) { + ////////////////////////////// + // Setting and testing cluster using old binaries in default FCV mode - st.configRS.awaitReplication(); + jsTest.log('Deploying cluster version ' + oldVersion); + var st = setupClusterAndDatabase(oldVersion); + + const collCreatedBeforeClusterUpgrade = createShardedCollection(); + checkClusterBeforeUpgrade(oldVersion, collCreatedBeforeClusterUpgrade); + + ////////////////////////////// + // Setting and testing cluster using latest binaries in latest FCV mode - // Setup initial conditions - setupInitialStateOnOldVersion(oldVersion); + jsTest.log('Upgrading binaries to latest version'); + st.upgradeCluster('latest'); - // Upgrade the entire cluster to the latest version. - jsTest.log('upgrading cluster binaries'); - st.upgradeCluster(latestFCV); + checkClusterAfterBinaryUpgrade(); - jsTest.log('upgrading cluster FCV'); + jsTest.log('Upgrading FCV to ' + latestFCV); assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: latestFCV})); - // Tests after upgrade - runChecksAfterUpgrade(); + const collCreatedAfterClusterUpgrade = createShardedCollection(); + checkClusterAfterFCVUpgrade( + latestFCV, collCreatedBeforeClusterUpgrade, collCreatedAfterClusterUpgrade); - // Setup state before downgrade - setupStateBeforeDowngrade(); + ////////////////////////////// + // Setting and testing cluster using old binaries in old FCV mode - // Downgrade FCV back to oldVersion - jsTest.log('downgrading cluster FCV'); + jsTest.log('Downgrading FCV to ' + oldVersion); assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: oldVersion})); - // Tests after FCV downgrade to oldVersion - runChecksAfterFCVDowngrade(oldVersion); + checkClusterAfterFCVDowngrade(); - // Downgrade binaries back to oldVersion - jsTest.log('downgrading cluster binaries'); + jsTest.log('Downgrading binaries to version ' + oldVersion); st.upgradeCluster(oldVersion); - // Tests after binaries downgrade to oldVersion - runChecksAfterBinDowngrade(); + const collCreatedAfterClusterDowngrade = createShardedCollection(); + checkClusterAfterBinaryDowngrade(oldVersion, + collCreatedBeforeClusterUpgrade, + collCreatedAfterClusterUpgrade, + collCreatedAfterClusterDowngrade); st.stop(); } diff --git a/jstests/sharding/long_collection_names.js b/jstests/sharding/long_collection_names.js deleted file mode 100644 index 313dbbfd7de..00000000000 --- a/jstests/sharding/long_collection_names.js +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Tests long collection name support in sharded collections. - * - * @tags: [ - * requires_fcv_51, - * ] - */ - -(function() { -"use strict"; - -load("jstests/libs/uuid_util.js"); - -const st = new ShardingTest({mongos: 1, config: 1, shards: {rs0: {nodes: 2}}}); -const mongos = st.s; -const primaryNode = st.rs0.getPrimary(); -const secondaryNode = st.rs0.getSecondary(); -secondaryNode.setSecondaryOk(); - -var collIndex = 1; -function createShardedCollection() { - const collNs = testDb + ".sharded_coll" + collIndex++; - assert.commandWorked(mongos.adminCommand({shardCollection: collNs, key: {x: 1}})); - return collNs; -} - -function testDisabledLongNameSupport(collNs) { - jsTestLog("Verify that the feature is disabled on collection '" + collNs + "'"); - - // Verify that long name support is properly disabled - const collConfigDoc = mongos.getDB("config").collections.findOne({_id: collNs}); - assert.eq(collConfigDoc.supportingLongName, undefined); - - for (const configDb of [primaryNode.getDB('config'), secondaryNode.getDB('config')]) { - // Verify that the collection exists in the cached metadata - const cachedCollDoc = configDb['cache.collections'].findOne({_id: collNs}); - assert.neq(cachedCollDoc, null); - - // Verify that the chunks collection with the proper namespace (i.e., based on the - // collection namespace) exists in the cached metadata - assert(configDb['cache.chunks.' + collNs].exists()); - assert(!configDb['cache.chunks.' + extractUUIDFromObject(cachedCollDoc.uuid)].exists()); - } -} - -function testImplicitlyEnabledLongNameSupport(collNs) { - jsTestLog("Verify that the feature is implicitly enabled on collection '" + collNs + "'"); - - // Verify that long name support is properly disabled - const collConfigDoc = mongos.getDB("config").collections.findOne({_id: collNs}); - assert.eq(collConfigDoc.supportingLongName, "implicitly_enabled"); - - for (const configDb of [primaryNode.getDB('config'), secondaryNode.getDB('config')]) { - // Verify that the collection exists in the cached metadata - const cachedCollDoc = configDb['cache.collections'].findOne({_id: collNs}); - assert.neq(cachedCollDoc, null); - - // Verify that the chunks collection with the proper namespace (i.e., based on the - // collection namespace) exists in the cached metadata - assert(!configDb['cache.chunks.' + collNs].exists()); - assert(configDb['cache.chunks.' + extractUUIDFromObject(cachedCollDoc.uuid)].exists()); - } -} - -const testDb = "test_db"; -assert.commandWorked(mongos.adminCommand({enableSharding: testDb})); - -////////////////////////////// -// Working with FCV 5.0 -- Long name support must be disabled on all collections. - -assert.commandWorked(mongos.getDB("admin").runCommand({setFeatureCompatibilityVersion: "5.0"})); - -const collCreatedWithFCV50 = createShardedCollection(); -testDisabledLongNameSupport(collCreatedWithFCV50); - -////////////////////////////// -// Working with FCV 5.1 -- Long name support must be explicitly enabled on new collections. - -assert.commandWorked(mongos.getDB("admin").runCommand({setFeatureCompatibilityVersion: "5.1"})); - -testDisabledLongNameSupport(collCreatedWithFCV50); - -const collCreatedWithFCV51 = createShardedCollection(); -testImplicitlyEnabledLongNameSupport(collCreatedWithFCV51); - -st.stop(); -})(); |