diff options
author | Esha Maharishi <esha.maharishi@mongodb.com> | 2017-08-22 18:06:47 -0400 |
---|---|---|
committer | Esha Maharishi <esha.maharishi@mongodb.com> | 2017-09-25 11:27:23 -0400 |
commit | 62fe0f89e9fa15c69f912d31b822b3631f691fe7 (patch) | |
tree | f1f1644eee12ca54fd1a02d111d3155ea6707c21 | |
parent | f9a41c8419554d727381c0b5766193f48c0ddc98 (diff) | |
download | mongo-62fe0f89e9fa15c69f912d31b822b3631f691fe7.tar.gz |
SERVER-30511 call checkUUIDsConsistentAcrossCluster() before shutting down a ShardingTest
33 files changed, 251 insertions, 58 deletions
diff --git a/buildscripts/resmokelib/core/programs.py b/buildscripts/resmokelib/core/programs.py index 1a0257d7b6b..bcf8e807d68 100644 --- a/buildscripts/resmokelib/core/programs.py +++ b/buildscripts/resmokelib/core/programs.py @@ -203,6 +203,10 @@ def mongo_shell_program(logger, executable=None, connection_string=None, filenam # Load this file to allow a callback to validate collections before shutting down mongod. eval_sb.append("load('jstests/libs/override_methods/validate_collections_on_shutdown.js');") + # Load a callback to check UUID consistency before shutting down a ShardingTest. + eval_sb.append( + "load('jstests/libs/override_methods/check_uuids_consistent_across_cluster.js');") + eval_str = "; ".join(eval_sb) args.append("--eval") args.append(eval_str) diff --git a/jstests/gle/gle_sharded_wc.js b/jstests/gle/gle_sharded_wc.js index ba7594588e3..8031e154f89 100644 --- a/jstests/gle/gle_sharded_wc.js +++ b/jstests/gle/gle_sharded_wc.js @@ -5,6 +5,10 @@ // so cannot be run on the ephemeralForTest storage engine, as it accepts all journaled writes. // @tags: [SERVER-21420] +// Checking UUID consistency involves talking to the shard primaries, but by the end of this test, +// one shard does not have a primary. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { 'use strict'; diff --git a/jstests/gle/gle_sharded_write.js b/jstests/gle/gle_sharded_write.js index 0f0d1017d66..687cdf1596e 100644 --- a/jstests/gle/gle_sharded_write.js +++ b/jstests/gle/gle_sharded_write.js @@ -2,6 +2,10 @@ // Ensures GLE correctly reports basic write stats and failures // Note that test should work correctly with and without write commands. // + +// Checking UUID consistency involves talking to shards, but this test shuts down one shard. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { 'use strict'; diff --git a/jstests/libs/override_methods/check_uuids_consistent_across_cluster.js b/jstests/libs/override_methods/check_uuids_consistent_across_cluster.js new file mode 100644 index 00000000000..2b5e62ab220 --- /dev/null +++ b/jstests/libs/override_methods/check_uuids_consistent_across_cluster.js @@ -0,0 +1,97 @@ +/** + * Load this file when starting a sharded cluster to provide a callback to check that collection + * UUIDs are consistent across shards and the config server. + */ + +"use strict"; + +ShardingTest.prototype.checkUUIDsConsistentAcrossCluster = function() { + if (jsTest.options().skipCheckingUUIDsConsistentAcrossCluster) { + print("Skipping checking UUID consistency across the cluster"); + return; + } + print("Checking UUID consistency across the cluster"); + + function parseNs(dbDotColl) { + assert.gt(dbDotColl.indexOf('.'), + 0, + "expected " + dbDotColl + " to represent a full collection name"); + const dbName = dbDotColl.substring(0, dbDotColl.indexOf('.')); + const collName = dbDotColl.substring(dbDotColl.indexOf('.') + 1, dbDotColl.length); + return [dbName, collName]; + } + + try { + // Read from config.collections, config.shards, and config.chunks to construct a picture + // of which shards own data for which collections, and what the UUIDs for those collections + // are. + let authoritativeCollMetadataArr = + this.s.getDB("config") + .chunks + .aggregate([ + { + $lookup: { + from: "shards", + localField: "shard", + foreignField: "_id", + as: "shardHost" + } + }, + {$unwind: "$shardHost"}, + {$group: {_id: "$ns", shardConnStrings: {$addToSet: "$shardHost.host"}}}, + { + $lookup: { + from: "collections", + localField: "_id", + foreignField: "_id", + as: "collInfo" + } + }, + {$unwind: "$collInfo"} + ]) + .toArray(); + + print("Aggregated authoritative metadata on config server for all sharded collections: " + + tojson(authoritativeCollMetadataArr)); + + // The ShardingTest object maintains a connection to each shard in its _connections array, + // where each connection is tagged with the shard's connection string in a 'host' field. + // Create a reverse mapping of connection string to connection to efficiently retrieve a + // connection by connection string. + let shardConnStringToConn = {}; + this._connections.forEach(function(conn) { + shardConnStringToConn[conn.host] = conn; + }); + + for (let authoritativeCollMetadata of authoritativeCollMetadataArr) { + const[dbName, collName] = parseNs(authoritativeCollMetadata._id); + + for (let shardConnString of authoritativeCollMetadata.shardConnStrings) { + // A connection the shard may not be cached in ShardingTest if the shard was added + // manually to the cluster by the test. + if (!(shardConnStringToConn.hasOwnProperty(shardConnString))) { + print("Creating connection to manually added shard: " + shardConnString); + shardConnStringToConn[shardConnString] = new Mongo(shardConnString); + } + let shardConn = shardConnStringToConn[shardConnString]; + + print("running listCollections against " + shardConn + + " to check UUID consistency for " + authoritativeCollMetadata._id); + const actualCollMetadata = + shardConn.getDB(dbName).getCollectionInfos({name: collName})[0]; + assert.eq(authoritativeCollMetadata.collInfo.uuid, + actualCollMetadata.info.uuid, + "authoritative collection info on config server: " + + tojson(authoritativeCollMetadata.collInfo) + + ", actual collection info on shard " + shardConnString + ": " + + tojson(actualCollMetadata)); + } + } + } catch (e) { + if (e.message.indexOf("Unauthorized") < 0) { + throw e; + } + print("ignoring exception " + tojson(e) + + " while checking UUID consistency across cluster"); + } +}; diff --git a/jstests/libs/override_methods/continuous_stepdown.js b/jstests/libs/override_methods/continuous_stepdown.js index 04e364ed1aa..de9bab2adc6 100644 --- a/jstests/libs/override_methods/continuous_stepdown.js +++ b/jstests/libs/override_methods/continuous_stepdown.js @@ -341,5 +341,11 @@ let ContinuousStepdown; }; Object.extend(ShardingTest, originalShardingTest); + + // The checkUUIDsConsistentAcrossCluster() function is defined on ShardingTest's prototype, + // but ShardingTest's prototype gets reset when ShardingTest is reassigned. We reload the + // override to redefine checkUUIDsConsistentAcrossCluster() on the new ShardingTest's + // prototype. + load('jstests/libs/override_methods/check_uuids_consistent_across_cluster.js'); }; })(); diff --git a/jstests/libs/override_methods/sharding_continuous_config_stepdown.js b/jstests/libs/override_methods/sharding_continuous_config_stepdown.js index 4acac5e0168..362310b5248 100644 --- a/jstests/libs/override_methods/sharding_continuous_config_stepdown.js +++ b/jstests/libs/override_methods/sharding_continuous_config_stepdown.js @@ -27,4 +27,10 @@ // Automatically start the continuous stepdown thread on the config server replica set. this.startContinuousFailover(); }; + + // The checkUUIDsConsistentAcrossCluster() function is defined on ShardingTest's prototype, but + // ShardingTest's prototype gets reset when ShardingTest is reassigned. We reload the override + // to redefine checkUUIDsConsistentAcrossCluster() on the new ShardingTest's prototype. + load('jstests/libs/override_methods/check_uuids_consistent_across_cluster.js'); + })(); diff --git a/jstests/multiVersion/set_feature_compatibility_version.js b/jstests/multiVersion/set_feature_compatibility_version.js index 898f2821710..0ede68d44b2 100644 --- a/jstests/multiVersion/set_feature_compatibility_version.js +++ b/jstests/multiVersion/set_feature_compatibility_version.js @@ -392,8 +392,10 @@ assert.docEq(expectedEntry, actualEntry); }); - latestShard.stopSet(); + // Call ShardingTest.stop before shutting down latestShard, so that the UUID check in + // ShardingTest.stop can talk to latestShard. st.stop(); + latestShard.stopSet(); // Create cluster with 3.4 mongos so that we can add 3.4 shards. st = new ShardingTest({shards: 0, other: {mongosOptions: {binVersion: downgrade}}}); @@ -421,8 +423,10 @@ assert.commandWorked(res); assert.eq(res.featureCompatibilityVersion, "3.4"); - downgradeShard.stopSet(); + // call ShardingTest.stop before shutting down downgradeShard, so that the UUID check in + // ShardingTest.stop can talk to downgradeShard. st.stop(); + downgradeShard.stopSet(); // Create a cluster running with featureCompatibilityVersion=3.6. st = new ShardingTest({shards: 1, mongos: 1}); diff --git a/jstests/multiVersion/upgrade_cluster.js b/jstests/multiVersion/upgrade_cluster.js index c1634d00ab5..4f861ed7860 100644 --- a/jstests/multiVersion/upgrade_cluster.js +++ b/jstests/multiVersion/upgrade_cluster.js @@ -5,6 +5,13 @@ load('./jstests/multiVersion/libs/multi_rs.js'); load('./jstests/multiVersion/libs/multi_cluster.js'); +// When checking UUID consistency, the shell attempts to run a command on the node it believes is +// primary in each shard. However, this test restarts shards, and the node that is elected primary +// after the restart may be different from the original primary. Since the shell does not retry on +// NotMaster errors, and whether or not it detects the new primary before issuing the command is +// nondeterministic, skip the consistency check for this test. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { /** diff --git a/jstests/noPassthroughWithMongod/ttl_sharded.js b/jstests/noPassthroughWithMongod/ttl_sharded.js index 4d837303b27..36b1a02796f 100644 --- a/jstests/noPassthroughWithMongod/ttl_sharded.js +++ b/jstests/noPassthroughWithMongod/ttl_sharded.js @@ -6,6 +6,10 @@ * deleted. */ +// TODO (SERVER-30344): enable UUID consistency check once createIndexes does not cause shards to +// have inconsistent UUIDs. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + // start up a new sharded cluster var s = new ShardingTest({shards: 2, mongos: 1}); diff --git a/jstests/sharding/all_config_hosts_down.js b/jstests/sharding/all_config_hosts_down.js index 2376ca063b8..712b9b2dc19 100644 --- a/jstests/sharding/all_config_hosts_down.js +++ b/jstests/sharding/all_config_hosts_down.js @@ -2,6 +2,11 @@ // Test for what happens when config servers are down and the database config is loaded // Should fail sanely // + +// Checking UUID consistency involves talking to the config servers, which are shut down in this +// test. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { "use strict"; diff --git a/jstests/sharding/all_config_servers_blackholed_from_mongos.js b/jstests/sharding/all_config_servers_blackholed_from_mongos.js index f575ba26276..f10d1c71fa2 100644 --- a/jstests/sharding/all_config_servers_blackholed_from_mongos.js +++ b/jstests/sharding/all_config_servers_blackholed_from_mongos.js @@ -1,5 +1,10 @@ // Ensures that if the config servers are blackholed from the point of view of MongoS, metadata // operations do not get stuck forever. + +// Checking UUID consistency involves talking to config servers through mongos, but mongos is +// blackholed from the config servers in this test. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { 'use strict'; diff --git a/jstests/sharding/authConnectionHook.js b/jstests/sharding/authConnectionHook.js index c06383804c2..24b512b6f18 100644 --- a/jstests/sharding/authConnectionHook.js +++ b/jstests/sharding/authConnectionHook.js @@ -8,6 +8,11 @@ * * @tags: [requires_persistence] */ + +// The UUID consistency check uses connections to shards cached on the ShardingTest object, but this +// test restarts a shard, so the cached connection is not usable. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { 'use strict'; diff --git a/jstests/sharding/auth_no_config_primary.js b/jstests/sharding/auth_no_config_primary.js index a767ce4eee7..8620c317272 100644 --- a/jstests/sharding/auth_no_config_primary.js +++ b/jstests/sharding/auth_no_config_primary.js @@ -5,6 +5,11 @@ * across a restart. * @tags: [requires_persistence] */ + +// Checking UUID consistency involves talking to the config server primary, but there is no config +// server primary by the end of this test. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { 'use strict'; diff --git a/jstests/sharding/batch_write_command_sharded.js b/jstests/sharding/batch_write_command_sharded.js index 7ede1900455..a0d4b6356f1 100644 --- a/jstests/sharding/batch_write_command_sharded.js +++ b/jstests/sharding/batch_write_command_sharded.js @@ -3,6 +3,11 @@ // NOTE: Basic write functionality is tested via the passthrough tests, this file should contain // *only* mongos-specific tests. // + +// Checking UUID consistency involves talking to the config server primary, but there is no config +// server primary by the end of this test. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { "use strict"; @@ -233,4 +238,4 @@ MongoRunner.stopMongos(staleMongos); st.stop(); -}());
\ No newline at end of file +}()); diff --git a/jstests/sharding/config_rs_no_primary.js b/jstests/sharding/config_rs_no_primary.js index 11d9a8e41aa..fee859a994e 100644 --- a/jstests/sharding/config_rs_no_primary.js +++ b/jstests/sharding/config_rs_no_primary.js @@ -1,5 +1,10 @@ // Tests operation of the cluster when the config servers have no primary and thus the cluster // metadata is in read-only mode. + +// Checking UUID consistency involves talking to the config server primary, but there is no config +// server primary by the end of this test. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { "use strict"; @@ -51,4 +56,4 @@ testOps(st.s); st.stop(); -}());
\ No newline at end of file +}()); diff --git a/jstests/sharding/cursor_valid_after_shard_stepdown.js b/jstests/sharding/cursor_valid_after_shard_stepdown.js index c51e7191e3f..ea0dd72338f 100644 --- a/jstests/sharding/cursor_valid_after_shard_stepdown.js +++ b/jstests/sharding/cursor_valid_after_shard_stepdown.js @@ -1,3 +1,8 @@ + +// Checking UUID consistency involves talking to the shard primary, but by the end of this test, the +// shard does not have a primary. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { 'use strict'; diff --git a/jstests/sharding/features1.js b/jstests/sharding/features1.js index 254e919f237..d7f0fa13239 100644 --- a/jstests/sharding/features1.js +++ b/jstests/sharding/features1.js @@ -1,3 +1,7 @@ +// TODO (SERVER-30344): enable UUID consistency check once createIndexes does not cause shards to +// have inconsistent UUIDs. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { var s = new ShardingTest({name: "features1", shards: 2, mongos: 1}); diff --git a/jstests/sharding/geo_near_random1.js b/jstests/sharding/geo_near_random1.js index 707d3c550a0..23c98df2fd1 100644 --- a/jstests/sharding/geo_near_random1.js +++ b/jstests/sharding/geo_near_random1.js @@ -1,4 +1,9 @@ // This tests all points using $near + +// TODO (SERVER-30344): enable UUID consistency check once createIndexes does not cause shards to +// have inconsistent UUIDs. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { load("jstests/libs/geo_near_random.js"); diff --git a/jstests/sharding/geo_near_random2.js b/jstests/sharding/geo_near_random2.js index 4833f5bc0d0..aac8aa55209 100644 --- a/jstests/sharding/geo_near_random2.js +++ b/jstests/sharding/geo_near_random2.js @@ -1,4 +1,9 @@ // This tests 1% of all points using $near and $nearSphere + +// TODO (SERVER-30344): enable UUID consistency check once createIndexes does not cause shards to +// have inconsistent UUIDs. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { load("jstests/libs/geo_near_random.js"); diff --git a/jstests/sharding/lagged_config_secondary.js b/jstests/sharding/lagged_config_secondary.js index 3d109dd9056..95e68a7a7c0 100644 --- a/jstests/sharding/lagged_config_secondary.js +++ b/jstests/sharding/lagged_config_secondary.js @@ -2,6 +2,11 @@ * Test that mongos times out when the config server replica set only contains nodes that * are behind the majority opTime. */ + +// Checking UUID consistency involves mongos being able to do a read from the config server, but +// this test is designed to make mongos time out when reading from the config server. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { var st = new ShardingTest( {shards: 1, configReplSetTestOptions: {settings: {chainingAllowed: false}}}); diff --git a/jstests/sharding/localhostAuthBypass.js b/jstests/sharding/localhostAuthBypass.js index 319c0eb2b79..61bbabd762a 100644 --- a/jstests/sharding/localhostAuthBypass.js +++ b/jstests/sharding/localhostAuthBypass.js @@ -2,6 +2,12 @@ // // This test is to ensure that localhost authentication works correctly against a sharded // cluster whether they are hosted with "localhost" or a hostname. + +// Checking UUID consistency, which occurs on ShardingTest.stop, involves using a mongos to read +// data on the config server, but this test uses a special shutdown function which stops the +// mongoses before calling ShardingTest.stop. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { 'use strict'; diff --git a/jstests/sharding/migration_sets_fromMigrate_flag.js b/jstests/sharding/migration_sets_fromMigrate_flag.js index a61e2efd7e6..5ec4121ea77 100644 --- a/jstests/sharding/migration_sets_fromMigrate_flag.js +++ b/jstests/sharding/migration_sets_fromMigrate_flag.js @@ -14,6 +14,11 @@ // delete op is done during chunk migration within the chunk range. // +// This test inserts documents into a sharded collection by directly writing to the shards, so the +// collection is created on the non-primary shard with a shard-generated UUID rather than with a +// UUID propagated from the primary shard. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + load('./jstests/libs/chunk_manipulation_util.js'); (function() { diff --git a/jstests/sharding/mongos_rs_auth_shard_failure_tolerance.js b/jstests/sharding/mongos_rs_auth_shard_failure_tolerance.js index a23d93829db..a5ae6c62aa6 100644 --- a/jstests/sharding/mongos_rs_auth_shard_failure_tolerance.js +++ b/jstests/sharding/mongos_rs_auth_shard_failure_tolerance.js @@ -11,6 +11,10 @@ // (connection connected after shard change). // +// Checking UUID consistency involves talking to shard primaries, but by the end of this test, one +// shard does not have a primary. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + var options = {rs: true, rsOptions: {nodes: 2}, keyFile: "jstests/libs/key1"}; var st = new ShardingTest({shards: 3, mongos: 1, other: options}); diff --git a/jstests/sharding/mongos_rs_shard_failure_tolerance.js b/jstests/sharding/mongos_rs_shard_failure_tolerance.js index 7ec30374c22..ac117877cb5 100644 --- a/jstests/sharding/mongos_rs_shard_failure_tolerance.js +++ b/jstests/sharding/mongos_rs_shard_failure_tolerance.js @@ -10,6 +10,11 @@ // sequence), idle (connection is connected but not used before a shard change), and new // (connection connected after shard change). // + +// Checking UUID consistency involves talking to shard primaries, but by the end of this test, one +// shard does not have a primary. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { 'use strict'; diff --git a/jstests/sharding/mongos_shard_failure_tolerance.js b/jstests/sharding/mongos_shard_failure_tolerance.js index aa4351e6303..0c189fd1a55 100644 --- a/jstests/sharding/mongos_shard_failure_tolerance.js +++ b/jstests/sharding/mongos_shard_failure_tolerance.js @@ -10,6 +10,9 @@ // sequence), idle (connection is connected but not used before a shard change), and new // (connection connected after shard change). // +// Checking UUID consistency involves talking to shards, but this test shuts down shards. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { 'use strict'; diff --git a/jstests/sharding/move_chunk_missing_idx.js b/jstests/sharding/move_chunk_missing_idx.js index 8125e8e6600..40ff85f9df0 100644 --- a/jstests/sharding/move_chunk_missing_idx.js +++ b/jstests/sharding/move_chunk_missing_idx.js @@ -3,6 +3,10 @@ * have the index and is not empty. */ +// TODO (SERVER-30344): enable UUID consistency check once createIndexes does not cause shards to +// have inconsistent UUIDs. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + var st = new ShardingTest({shards: 2}); var testDB = st.s.getDB('test'); diff --git a/jstests/sharding/read_pref_cmd.js b/jstests/sharding/read_pref_cmd.js index 62ac98b80bc..10b8a883507 100644 --- a/jstests/sharding/read_pref_cmd.js +++ b/jstests/sharding/read_pref_cmd.js @@ -2,6 +2,10 @@ load("jstests/replsets/rslib.js"); var NODE_COUNT = 2; +// Checking UUID consistency involves reading from the config server through mongos, but this test +// sets an invalid readPreference on the connection to the mongos. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + /** * Prepare to call testReadPreference() or assertFailure(). */ diff --git a/jstests/sharding/remove2.js b/jstests/sharding/remove2.js index 1fed38f6dae..da609e50577 100644 --- a/jstests/sharding/remove2.js +++ b/jstests/sharding/remove2.js @@ -2,6 +2,10 @@ load("jstests/replsets/rslib.js"); +// The UUID consistency check uses connections to shards cached on the ShardingTest object, but this +// test restarts a shard, so the cached connection is not usable. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { 'use strict'; diff --git a/jstests/sharding/return_partial_shards_down.js b/jstests/sharding/return_partial_shards_down.js index 6d1c215127f..c3e0f3f2e27 100644 --- a/jstests/sharding/return_partial_shards_down.js +++ b/jstests/sharding/return_partial_shards_down.js @@ -2,6 +2,9 @@ // Tests that zero results are correctly returned with returnPartial and shards down // +// Checking UUID consistency involves talking to shards, but this test shuts down shards. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + var st = new ShardingTest({shards: 3, mongos: 1, other: {mongosOptions: {verbose: 2}}}); // Stop balancer, we're doing our own manual chunk distribution diff --git a/jstests/sharding/sharding_multiple_ns_rs.js b/jstests/sharding/sharding_multiple_ns_rs.js index 183d6c24878..d59eac888cb 100644 --- a/jstests/sharding/sharding_multiple_ns_rs.js +++ b/jstests/sharding/sharding_multiple_ns_rs.js @@ -1,3 +1,9 @@ +// When checking UUID consistency, the shell attempts to run a command on the node it believes is +// primary in each shard. However, this test shuts down the primary of the shard. Since whether or +// not the shell detects the new primary before issuing the command is nondeterministic, skip the +// consistency check for this test. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { load("jstests/replsets/rslib.js"); diff --git a/jstests/sharding/startup_with_all_configs_down.js b/jstests/sharding/startup_with_all_configs_down.js index e97442b6dd8..bd791b71b2f 100644 --- a/jstests/sharding/startup_with_all_configs_down.js +++ b/jstests/sharding/startup_with_all_configs_down.js @@ -5,6 +5,11 @@ // This test involves restarting a standalone shard, so cannot be run on ephemeral storage engines. // A restarted standalone will lose all data when using an ephemeral storage engine. // @tags: [requires_persistence] + +// The UUID consistency check uses connections to shards cached on the ShardingTest object, but this +// test restarts a shard, so the cached connection is not usable. +TestData.skipCheckingUUIDsConsistentAcrossCluster = true; + (function() { "use strict"; diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js index 585f5f11de2..90599de44f4 100644 --- a/src/mongo/shell/shardingtest.js +++ b/src/mongo/shell/shardingtest.js @@ -377,6 +377,8 @@ var ShardingTest = function(params) { }; this.stop = function(opts) { + this.checkUUIDsConsistentAcrossCluster(); + for (var i = 0; i < this._mongos.length; i++) { this.stopMongos(i, opts); } @@ -934,60 +936,6 @@ var ShardingTest = function(params) { assert(res.ok || res.errmsg == "it is already the primary", tojson(res)); }; - this.checkUUIDsConsistentAcrossCluster = function() { - print("Checking if UUIDs are consistent across the cluster"); - - let parseNs = function(dbDotColl) { - assert.gt(dbDotColl.indexOf('.'), 0); - let dbName = dbDotColl.substring(0, dbDotColl.indexOf('.')); - let collName = dbDotColl.substring(dbDotColl.indexOf('.') + 1, dbDotColl.length); - return [dbName, collName]; - }; - - // Read from config.collections, config.shards, and config.chunks to construct a picture of - // which shards own data for which collections, and what the UUID for those collections are. - let authoritativeCollMetadatas = - this.s.getDB("config") - .chunks - .aggregate([ - { - $lookup: { - from: "shards", - localField: "shard", - foreignField: "_id", - as: "shardHost" - } - }, - {$unwind: "$shardHost"}, - {$group: {_id: "$ns", shards: {$addToSet: "$shardHost.host"}}}, - { - $lookup: { - from: "collections", - localField: "_id", - foreignField: "_id", - as: "collInfo" - } - }, - {$unwind: "$collInfo"} - ]) - .toArray(); - - for (authoritativeCollMetadata of authoritativeCollMetadatas) { - let [dbName, collName] = parseNs(authoritativeCollMetadata._id); - for (shard of authoritativeCollMetadata.shards) { - let shardConn = new Mongo(shard); - let actualCollMetadata = - shardConn.getDB(dbName).getCollectionInfos({name: collName})[0]; - assert.eq(authoritativeCollMetadata.collInfo.uuid, - actualCollMetadata.info.uuid, - "authoritative collection info on config server: " + - tojson(authoritativeCollMetadata.collInfo) + - ", actual collection info on shard " + shard + ": " + - tojson(actualCollMetadata)); - } - } - }; - /** * Returns whether any settings to ShardingTest or jsTestOptions indicate this is a multiversion * cluster. @@ -1557,3 +1505,7 @@ var ShardingTest = function(params) { }, "waiting for all mongos servers to return cluster times", 60 * 1000, 500); } }; + +// Stub for a hook to check that collection UUIDs are consistent across shards and the config +// server. +ShardingTest.prototype.checkUUIDsConsistentAcrossCluster = function() {}; diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js index 97761b61a1d..63b41528e49 100644 --- a/src/mongo/shell/utils.js +++ b/src/mongo/shell/utils.js @@ -253,6 +253,8 @@ jsTestOptions = function() { TestData.hasOwnProperty("skipValidationOnNamespaceNotFound") ? TestData.skipValidationOnNamespaceNotFound : true, + skipCheckingUUIDsConsistentAcrossCluster: + TestData.skipCheckingUUIDsConsistentAcrossCluster || false, jsonSchemaTestFile: TestData.jsonSchemaTestFile, excludedDBsFromDBHash: TestData.excludedDBsFromDBHash, }); |