diff options
author | Davis Haupt <davis.haupt@mongodb.com> | 2022-12-19 21:22:35 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-12-21 01:17:48 +0000 |
commit | 70bbc40c52b10395d0c54d63e4f7c35abadd8756 (patch) | |
tree | 2b19dc0d583f6b04af13042d5185f7f4817fef64 /jstests/sharding | |
parent | 21b2615135067cdb67409f9cae670b315425b0df (diff) | |
download | mongo-70bbc40c52b10395d0c54d63e4f7c35abadd8756.tar.gz |
SERVER-72222 fix mapReduce single reduce optimization in sharded clusters
Diffstat (limited to 'jstests/sharding')
-rw-r--r-- | jstests/sharding/mr_single_reduce_split.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/jstests/sharding/mr_single_reduce_split.js b/jstests/sharding/mr_single_reduce_split.js new file mode 100644 index 00000000000..1a6d20f0e1f --- /dev/null +++ b/jstests/sharding/mr_single_reduce_split.js @@ -0,0 +1,55 @@ +/** + * This jstest verifies that the mrEnableSingleReduceOptimization flag works properly in a sharded + * cluster when there are documents on multiple chunks that need to be merged. + * @tags: [ + * backport_required_multiversion, + * ] + */ +(function() { +const st = new ShardingTest({ + shards: 2, + mongos: 1, + other: { + mongosOptions: {setParameter: {mrEnableSingleReduceOptimization: true}}, + shardOptions: {setParameter: {mrEnableSingleReduceOptimization: true}}, + } +}); + +const mongosDB = st.s0.getDB(jsTestName()); +const mongosColl = mongosDB[jsTestName()]; + +assert.commandWorked(mongosDB.dropDatabase()); +assert.commandWorked(mongosDB.adminCommand({enableSharding: mongosDB.getName()})); +st.ensurePrimaryShard(mongosDB.getName(), st.shard0.shardName); + +assert.commandWorked( + mongosDB.adminCommand({shardCollection: mongosColl.getFullName(), key: {_id: 1}})); + +// Split the collection into 2 chunks: [minKey, 0) and [0, maxKey]. +assert.commandWorked(mongosDB.adminCommand({split: mongosColl.getFullName(), middle: {_id: 0}})); + +// Move the [0, MaxKey) chunk to the second shard. +assert.commandWorked(mongosDB.adminCommand( + {moveChunk: mongosColl.getFullName(), find: {_id: 50}, to: st.shard1.shardName})); + +assert.commandWorked(mongosColl.insert({_id: -1})); +const map = function() { + emit(0, {val: "mapped value"}); +}; + +const reduce = function(key, values) { + return {val: "reduced value"}; +}; + +let res = assert.commandWorked(mongosDB.runCommand( + {mapReduce: mongosColl.getName(), map: map, reduce: reduce, out: {inline: 1}})); +assert.eq(res.results[0], {_id: 0, value: {val: "mapped value"}}); + +assert.commandWorked(mongosColl.insert({_id: 1})); + +res = assert.commandWorked(mongosDB.runCommand( + {mapReduce: mongosColl.getName(), map: map, reduce: reduce, out: {inline: 1}})); +assert.eq(res.results[0], {_id: 0, value: {val: "reduced value"}}); + +st.stop(); +}()); |