diff options
author | Esha Maharishi <esha.maharishi@mongodb.com> | 2018-02-09 17:09:36 -0500 |
---|---|---|
committer | Esha Maharishi <esha.maharishi@mongodb.com> | 2018-02-13 11:03:28 -0500 |
commit | fe5b3058c3ba27f8262fa5198cf243053ba50b9b (patch) | |
tree | 50594aade94a429ffdac0dbd68947b684e059dcd /jstests/libs | |
parent | bb1a895bf84fdeb1e0ef084fd40160f2f694e05d (diff) | |
download | mongo-fe5b3058c3ba27f8262fa5198cf243053ba50b9b.tar.gz |
SERVER-32368 do not perform UUID check against a shard's config cache in the sharding_csrs_continuous_config_stepdown_WT suite
Diffstat (limited to 'jstests/libs')
-rw-r--r-- | jstests/libs/override_methods/check_uuids_consistent_across_cluster.js | 84 |
1 files changed, 54 insertions, 30 deletions
diff --git a/jstests/libs/override_methods/check_uuids_consistent_across_cluster.js b/jstests/libs/override_methods/check_uuids_consistent_across_cluster.js index 3b6636df7ac..4fbc9add333 100644 --- a/jstests/libs/override_methods/check_uuids_consistent_across_cluster.js +++ b/jstests/libs/override_methods/check_uuids_consistent_across_cluster.js @@ -1,28 +1,42 @@ /** - * 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. + * Provides a hook to check that shards' storage catalogs and catalog caches are consistent + * with the sharding catalog on the config server. * - * To disable this check on a specific test, add the following to the JS file: + * The hook currently checks that: if the sharding catalog says a shard owns chunks for a sharded + * collection, then the shard has an entry for the collection + * - in its storage catalog, with the same UUID as the collection has in the sharding catalog + * - in its catalog cache, with the same UUID as the collection has in the sharding catalog * - * TestData.skipCheckingUUIDsConsistentAcrossCluster = true; - * - * Common test actions that can cause the UUID check to fail are: - * - Causing a shard not to have a primary. The UUID check must run commands against primaries. - * - Restarting shard replica sets / primaries. The UUID consistency check uses shard primary - * connections cached in ShardingTest._connections, which may become out of date if the primary - * changes and the shell doesn't detect the new primary before this check occurs. - * - No config primary. The check queries the config collections. - * - Blackholing mongos from the config servers. The UUID check uses the mongos to query the config. + * TODO (SERVER-33252): extend the hook to add consistency checks for databases + * TODO (SERVER-33253): extend the hook to add consistency checks for collection indexes and options */ - "use strict"; ShardingTest.prototype.checkUUIDsConsistentAcrossCluster = function() { if (jsTest.options().skipCheckingUUIDsConsistentAcrossCluster) { - print("Skipping checking UUID consistency across the cluster"); + // A test may want to skip the consistency checks for a few reasons: + // 1) The checks are performed against shard and config primaries, and the connections + // cached on ShardingTest are used. So, tests that end with a different (or no) shard or + // config primary should skip the checks. + // 2) The sharding catalog is read from the config server via mongos, so tests that cause + // the config primary to be unreachable from mongos should skip the checks. + print( + "Skipping checking consistency of the sharding catalog with shards' storage catalogs and catalog caches"); return; } - print("Checking UUID consistency across the cluster"); + + if (jsTest.options().skipCheckingCatalogCacheConsistencyWithShardingCatalog) { + // When a shard takes or loses ownership of a chunk (through shardCollection, moveChunk, or + // dropCollection), a best-effort is made to make the shard refresh its routing table cache. + // But since sharding catalog changes are not transactional, it's possible the shard's + // catalog cache will be stale. A test or suite that induces stepdowns or otherwise makes it + // likely that this "best-effort" will fail should skip checks for only the catalog caches. + print( + "Checking consistency of the sharding catalog with shards' storage catalogs, but not with shards' catalog caches"); + } else { + print( + "Checking consistency of the sharding catalog with shards' storage catalogs and catalog caches"); + } function parseNs(dbDotColl) { assert.gt(dbDotColl.indexOf('.'), @@ -88,8 +102,10 @@ ShardingTest.prototype.checkUUIDsConsistentAcrossCluster = function() { } let shardConn = shardConnStringToConn[shardConnString]; - print("checking that the UUID in the storage catalog for " + ns + " on " + - shardConn + " is consistent with the config server"); + print("Checking that the UUID for " + ns + " returned by listCollections on " + + shardConn + + " is consistent with the UUID in config.collections on the config server"); + const actualCollMetadata = shardConn.getDB(dbName).getCollectionInfos({name: collName})[0]; assert.eq(authoritativeCollMetadata.collInfo.uuid, @@ -99,19 +115,27 @@ ShardingTest.prototype.checkUUIDsConsistentAcrossCluster = function() { ", actual collection info on shard " + shardConnString + ": " + tojson(actualCollMetadata)); - print("checking that the UUID in config.cache.collections for " + ns + " on " + - shardConn + " is consistent with the config server"); - assert.commandWorked(shardConn.adminCommand( - {_flushRoutingTableCacheUpdates: ns, syncFromConfig: false})); - const actualConfigMetadata = - shardConn.getDB("config").getCollection("cache.collections").find({"_id": - ns})[0]; - assert.eq(authoritativeCollMetadata.collInfo.uuid, - actualConfigMetadata.uuid, - "authoritative collection info on config server: " + - tojson(authoritativeCollMetadata.collInfo) + - ", actual config info on shard " + shardConnString + ": " + - tojson(actualConfigMetadata)); + if (!jsTest.options().skipCheckingCatalogCacheConsistencyWithShardingCatalog) { + print( + "Checking that the UUID for " + ns + " in config.cache.collections on " + + shardConn + + " is consistent with the UUID in config.collections on the config server"); + + // Wait for the shard to finish writing its last refresh to disk. + assert.commandWorked(shardConn.adminCommand( + {_flushRoutingTableCacheUpdates: ns, syncFromConfig: false})); + + const actualConfigMetadata = + shardConn.getDB("config").getCollection("cache.collections").find({ + "_id": ns + })[0]; + assert.eq(authoritativeCollMetadata.collInfo.uuid, + actualConfigMetadata.uuid, + "authoritative collection info on config server: " + + tojson(authoritativeCollMetadata.collInfo) + + ", actual config info on shard " + shardConnString + ": " + + tojson(actualConfigMetadata)); + } } } } catch (e) { |