summaryrefslogtreecommitdiff
path: root/jstests/sharding/in_memory_sort_limit.js
blob: 83aa88399867b4b91ae3b369535e4fa8fdf36751 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Test SERVER-14306.  Do a query directly against a mongod with an in-memory sort and a limit that
// doesn't cause the in-memory sort limit to be reached, then make sure the same limit also doesn't
// cause the in-memory sort limit to be reached when running through a mongos.
(function() {
     "use strict";

     var st = new ShardingTest({ shards: 2 });
     var db = st.s.getDB('test');
     var mongosCol = db.getCollection('skip');
     db.adminCommand({ enableSharding: 'test' });
     st.ensurePrimaryShard('test', 'shard0001');
     db.adminCommand({ shardCollection: 'test.skip', key: { _id: 1 }});

     var filler = new Array(10000).toString();
     var bulk = [];
     // create enough data to exceed 32MB in-memory sort limit.
     for (var i = 0; i < 20000; i++) {
         bulk.push({x:i, str:filler});
     }
     assert.writeOK(mongosCol.insert(bulk));

     // Make sure that at least 1 chunk is on another shard so that mongos doesn't treat this as a
     // single-shard query (which doesn't exercise the bug).
     st.startBalancer();
     st.awaitBalance('skip', 'test');

     var docCount = mongosCol.count();
     var shardCol = st.shard0.getDB('test').getCollection('skip');
     var passLimit = 2000;
     var failLimit = 4000;
     jsTestLog("Test no error with limit of " + passLimit + " on mongod");
     assert.eq(passLimit, shardCol.find().sort({x:1}).limit(passLimit).itcount());

     jsTestLog("Test error with limit of " + failLimit + " on mongod");
     assert.throws( function() {shardCol.find().sort({x:1}).limit(failLimit).itcount(); } );

     jsTestLog("Test no error with limit of " + passLimit + " on mongos");
     assert.eq(passLimit, mongosCol.find().sort({x:1}).limit(passLimit).itcount());

     jsTestLog("Test error with limit of " + failLimit + " on mongos");
     assert.throws( function() {mongosCol.find().sort({x:1}).limit(failLimit).itcount(); } );

     st.stop();

 })();