diff --git a/jstests/sharding/check_metadata_consistency_with_capped_collections.js b/jstests/sharding/check_metadata_consistency_with_capped_collections.js new file mode 100644 index 00000000000..9bd8af7f027 --- /dev/null +++ b/jstests/sharding/check_metadata_consistency_with_capped_collections.js @@ -0,0 +1,63 @@ +/** + * Creates a capped sharded collection in 6.0 (reproducing the SERVER-95213 bug) and then upgrades + * to 7.0, demonstrating that we might end up in 7.0 with sharded capped collections. + */ +(function() { +"use strict"; + +load('jstests/libs/fail_point_util.js'); +load('jstests/libs/parallel_shell_helpers.js'); +load('./jstests/multiVersion/libs/multi_cluster.js'); + +const dbName = 'foo'; +const collName = 'test'; + +// Setup a sharded cluster in 6.0 +var st = new ShardingTest({ + shards: 1, + mongos: 1, + other: { + mongosOptions: {binVersion: lastLTSFCV}, + configOptions: {binVersion: lastLTSFCV}, + shardOptions: {binVersion: lastLTSFCV}, + + rsOptions: {binVersion: lastLTSFCV}, + rs: true, + } +}); + +function shardCollection(ns) { + assert.commandWorked(db.adminCommand({shardCollection: ns, key: {x: 1}, unique: false})); +} + +st.s.adminCommand({enableSharding: dbName}); +// create the sharded capped collection +const ns = `${dbName}.${collName}`; +const fp = configureFailPoint(st.rs0.getPrimary(), 'waitBeforeCreateIndex', {}, 'alwaysOn'); +fp.timesEntered = 0; +const parallelShell = startParallelShell(funWithArgs(shardCollection, ns), st.s.port); + +fp.wait(); +assert.commandWorked(st.s.getDB(dbName).createCollection(collName, {capped: true, size: 5000})); +fp.off(); +parallelShell(); + +// upgrade to 7.0 +st.upgradeCluster('latest'); +assert.commandWorked(st.s.adminCommand({setFeatureCompatibilityVersion: latestFCV})); +// Check that the collection is sharded and capped +assert.eq(1, st.s.getCollection('config.collections').countDocuments({_id: ns})); +let listCollRes = st.rs0.getPrimary().getDB(dbName).runCommand({listCollections: 1}); +assert.commandWorked(listCollRes); +assert.eq(true, listCollRes.cursor.firstBatch[0].options.capped); +// Now, run checkMetadata consistency to see if it detects the inconsistency +let res = st.s.getDB('admin').runCommand({checkMetadataConsistency: 1}); +assert.commandWorked(res); + +assert.eq(1, res.cursor.firstBatch.length); + +res = st.s.getDB(dbName).runCommand({checkMetadataConsistency: 1}); +assert.eq(1, res.cursor.firstBatch.length); + +st.stop(); +})(); \ No newline at end of file