diff options
| author | Charlie Swanson <charlie.swanson@mongodb.com> | 2023-08-02 13:19:15 +0000 |
|---|---|---|
| committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-08-18 20:24:27 +0000 |
| commit | c5454c1dc7e9c09ea26ead0793084608b0b2ddc8 (patch) | |
| tree | 558c1a65adbb22de731775e2366cebeb5e3e8fb6 | |
| parent | aaaea1402449c86c656f1b9deab315c5a2de4912 (diff) | |
SERVER-79372 Fix assertion about number of targeted shards.
(cherry picked from commit ab6e2551be05df13fb84a138282daf179b78533e)
| -rw-r--r-- | jstests/noPassthrough/dispatch_pipeline_to_all_shardservers.js | 65 | ||||
| -rw-r--r-- | src/mongo/db/pipeline/sharded_agg_helpers.cpp | 9 |
2 files changed, 65 insertions, 9 deletions
diff --git a/jstests/noPassthrough/dispatch_pipeline_to_all_shardservers.js b/jstests/noPassthrough/dispatch_pipeline_to_all_shardservers.js index 3864ceec682..c82c8bbb5a9 100644 --- a/jstests/noPassthrough/dispatch_pipeline_to_all_shardservers.js +++ b/jstests/noPassthrough/dispatch_pipeline_to_all_shardservers.js @@ -1,3 +1,11 @@ +// Various tests of the ability to establish a cursor on each mongod in a sharded cluster. + +(function() { +"use strict"; +function listMongodStats(db) { + return db.getSiblingDB("admin").aggregate([{$_internalShardServerInfo: {}}]).toArray(); +} + /** * Test that mongos can establish cursors on all nodes within a sharded cluster. */ @@ -12,13 +20,9 @@ function runTest({shards, nodes}) { rs: {nodes}, }); const db = st.s.getDB(jsTestName()); - const results = db.getSiblingDB("admin") - .aggregate([ - {$_internalShardServerInfo: {}}, - ]) - .toArray(); + const results = listMongodStats(db); - // Assert there are $currentOp results from all hosts. + // Assert there are results from all hosts. const totalHosts = shards * nodes; assert.eq(totalHosts, results.length); st.stop(); @@ -88,3 +92,52 @@ assert.soon(() => { st.stop(); }()); + +/** + * Test that we can gracefully handle an imbalanced topology where some shards have fewer replica + * set members than others (SERVER-79372). + */ +(function() { +"use strict"; +const st = new ShardingTest({ + mongos: 1, + // different numbers of mongods between shards. + shards: {rs0: {nodes: 1}, rs1: {nodes: 2}}, + config: 1, // not relevant for this test. +}); + +// This once tripped an invariant failure: SERVER-79372. +const results = listMongodStats(st.s.getDB(jsTestName())); + +// Assert there are results from all hosts. +const totalHosts = 3; +assert.eq(totalHosts, results.length, results); + +st.stop(); +}()); + +/** + * Same sort of test (SERVER-79372) but now where the config server has a different number of + * shards, and it gets migrated from a dedicated config server to be one of the shards. This is how + * the bug was originally discovered. + */ +(function() { +"use strict"; +const st = new ShardingTest({ + mongos: 1, + shards: {rs0: {nodes: 2}, rs1: {nodes: 2}}, + config: {rs: {nodes: 1}}, +}); +// This one has always worked fine. +let results = listMongodStats(st.s.getDB(jsTestName())); +assert.eq(4, results.length, results); +assert.commandWorked(st.s.getDB("admin").runCommand({transitionFromDedicatedConfigServer: 1})); +// After the above command, this once tripped an invariant failure: SERVER-79372. +results = listMongodStats(st.s.getDB(jsTestName())); + +// Assert there are results from all hosts. +assert.eq(5, results.length, results); + +st.stop(); +}()); +}()); diff --git a/src/mongo/db/pipeline/sharded_agg_helpers.cpp b/src/mongo/db/pipeline/sharded_agg_helpers.cpp index c51142298ed..e1f20c626d0 100644 --- a/src/mongo/db/pipeline/sharded_agg_helpers.cpp +++ b/src/mongo/db/pipeline/sharded_agg_helpers.cpp @@ -1226,9 +1226,12 @@ DispatchShardPipelineResults dispatchShardPipeline( MONGO_UNREACHABLE_TASSERT(6487201); } - invariant(cursors.size() % shardIds.size() == 0, - str::stream() << "Number of cursors (" << cursors.size() - << ") is not a multiple of producers (" << shardIds.size() << ")"); + tassert(7937200, + str::stream() << "Number of cursors (" << cursors.size() + << ") is not a multiple of the number of targeted shards (" + << shardIds.size() + << ") and we were not targeting each mongod in each shard", + targetEveryShardServer || cursors.size() % shardIds.size() == 0); // For $changeStream, we must open an extra cursor on the 'config.shards' collection, so // that we can monitor for the addition of new shards inline with real events. |
