diff options
author | Jack Mulrow <jack.mulrow@mongodb.com> | 2023-01-03 19:40:17 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-01-03 20:16:50 +0000 |
commit | 58f8289c41a567c674ee623ab49ed6f866f407cc (patch) | |
tree | 2c88034c3767b826fc3b40a4a0b4d12781364944 /jstests/noPassthrough | |
parent | 03ace3256385389bd59564c30869e38ddbf89d35 (diff) | |
download | mongo-58f8289c41a567c674ee623ab49ed6f866f407cc.tar.gz |
SERVER-72453 Support adding config server as a shard with basic operations
Diffstat (limited to 'jstests/noPassthrough')
-rw-r--r-- | jstests/noPassthrough/catalog_shard.js | 113 |
1 files changed, 112 insertions, 1 deletions
diff --git a/jstests/noPassthrough/catalog_shard.js b/jstests/noPassthrough/catalog_shard.js index c367a5e2f93..c5b5e2eec2c 100644 --- a/jstests/noPassthrough/catalog_shard.js +++ b/jstests/noPassthrough/catalog_shard.js @@ -1,14 +1,125 @@ /** * Tests catalog shard topology. + * + * Requires both catalog shard feature flags. + * @tags: [ + * featureFlagCatalogShard, + * featureFlagConfigServerAlwaysShardRemote, + * ] */ (function() { "use strict"; +const dbName = "foo"; +const collName = "bar"; +const ns = dbName + "." + collName; + +function basicCRUD(conn) { + assert.commandWorked(conn.getCollection(ns).insert({_id: 1, x: 1})); + assert.sameMembers(conn.getCollection(ns).find({x: 1}).toArray(), [{_id: 1, x: 1}]); + assert.commandWorked(conn.getCollection(ns).remove({x: 1})); + assert.eq(conn.getCollection(ns).find({x: 1}).toArray().length, 0); +} + const st = new ShardingTest({ shards: 0, - config: 1, + config: 3, configOptions: {setParameter: {featureFlagCatalogShard: true}}, }); +const configCS = st.configRS.getURL(); +let configShardName; + +// +// Dedicated config server mode tests (pre addShard). +// +{ + // Can't create user namespaces. + assert.commandFailedWithCode(st.configRS.getPrimary().getCollection(ns).insert({_id: 1, x: 1}), + ErrorCodes.InvalidNamespace); + + // Failover works. + st.configRS.stepUp(st.configRS.getSecondary()); +} + +// +// Catalog shard mode tests (post addShard). +// +{ + // + // Adding the config server as a shard works. + // + configShardName = assert.commandWorked(st.s.adminCommand({addShard: configCS})).shardAdded; + + // More than once works. + assert.commandWorked(st.s.adminCommand({addShard: configCS})); + assert.commandWorked(st.s.adminCommand({addShard: configCS})); +} + +// Refresh the logical session cache now that we have a shard to create the sessions collection to +// verify it works as expected. +st.configRS.getPrimary().adminCommand({refreshLogicalSessionCacheNow: 1}); + +{ + // + // Basic unsharded CRUD. + // + basicCRUD(st.s); +} + +{ + // + // Basic sharded CRUD. + // + assert.commandWorked(st.s.adminCommand({enableSharding: dbName})); + assert.commandWorked(st.s.adminCommand({shardCollection: ns, key: {skey: 1}})); + + basicCRUD(st.s); +} + +// Add a shard to move chunks to and from it in later tests. +const newShardRS = new ReplSetTest({name: "new-shard-rs", nodes: 1}); +newShardRS.startSet({shardsvr: ""}); +newShardRS.initiate(); +const newShardName = + assert.commandWorked(st.s.adminCommand({addShard: newShardRS.getURL()})).shardAdded; + +{ + // + // Basic sharded DDL. + // + assert.commandWorked(st.s.adminCommand({split: ns, middle: {skey: 0}})); + assert.commandWorked(st.s.getCollection(ns).insert([{skey: 1}, {skey: -1}])); + + assert.commandWorked(st.s.adminCommand({moveChunk: ns, find: {skey: 0}, to: newShardName})); + assert.commandWorked(st.s.adminCommand({moveChunk: ns, find: {skey: 0}, to: configShardName})); + assert.commandWorked(st.s.adminCommand({moveChunk: ns, find: {skey: 0}, to: newShardName})); +} + +{ + // + // Basic secondary reads. + // + assert.commandWorked( + st.s.getCollection(ns).insert({readFromSecondary: 1, skey: -1}, {writeConcern: {w: 3}})); + let secondaryRes = assert.commandWorked(st.s.getDB(dbName).runCommand({ + find: collName, + filter: {readFromSecondary: 1, skey: -1}, + $readPreference: {mode: "secondary"} + })); + assert.eq(secondaryRes.cursor.firstBatch.length, 1, tojson(secondaryRes)); +} + +{ + // + // Failover in shard role works. + // + st.configRS.stepUp(st.configRS.getSecondary()); + + // Basic CRUD and sharded DDL still works. + basicCRUD(st.s); + assert.commandWorked(st.s.adminCommand({split: ns, middle: {skey: 20}})); +} st.stop(); +newShardRS.stopSet(); }()); |