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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/**
* Test that densify correctly limits the number of generated documents.
* @tags: [
* # Needed as $densify is a 51 feature.
* requires_fcv_51,
* ]
*/
(function() {
"use strict";
load("jstests/noPassthrough/libs/server_parameter_helpers.js"); // For setParameterOnAllHosts.
load("jstests/libs/discover_topology.js"); // For findNonConfigNodes.
const paramName = "internalQueryMaxAllowedDensifyDocs";
const origParamValue = assert.commandWorked(
db.adminCommand({getParameter: 1, internalQueryMaxAllowedDensifyDocs: 1}))[paramName];
function setMaxDocs(max) {
setParameterOnAllHosts(DiscoverTopology.findNonConfigNodes(db.getMongo()), paramName, max);
}
const coll = db[jsTestName()];
coll.drop();
function runAggregate(densifyStage, failCode = null) {
if (failCode === null) {
return db.runCommand({aggregate: coll.getName(), pipeline: [densifyStage], cursor: {}});
} else {
assert.commandFailedWithCode(
db.runCommand({aggregate: coll.getName(), pipeline: [densifyStage], cursor: {}}),
failCode);
}
}
// Test that with explicit range and no documents we can't generate more than the limit.
setMaxDocs(10);
runAggregate({$densify: {field: "val", range: {step: 1, bounds: [0, 11]}}}, 5897900);
runAggregate({$densify: {field: "val", range: {step: 4, bounds: [0, 45]}}}, 5897900);
// Exactly ten documents should pass.
runAggregate({$densify: {field: "val", range: {step: 1, bounds: [0, 10]}}});
// Full fails if there are enough points between min and max to pass limit
assert.commandWorked(coll.insert({val: 0, part: 1}));
assert.commandWorked(coll.insert({val: 12, part: 1}));
runAggregate({$densify: {field: "val", range: {step: 1, bounds: "full"}}}, 5897900);
// Test that count is shared across partitions.
setMaxDocs(20);
assert.commandWorked(coll.insert({val: 0, part: 2}));
assert.commandWorked(coll.insert({val: 12, part: 2}));
runAggregate(
{$densify: {field: "val", partitionByFields: ["part"], range: {step: 1, bounds: "partition"}}},
5897900);
// Test that already existing documents don't count towards the limit.
coll.drop();
setMaxDocs(10);
assert.commandWorked(coll.insert({val: 0, part: 1}));
assert.commandWorked(coll.insert({val: 12, part: 1}));
runAggregate({$densify: {field: "val", range: {step: 1, bounds: "full"}}}, 5897900);
assert.commandWorked(coll.insert({val: 5, part: 1}));
runAggregate({$densify: {field: "val", range: {step: 1, bounds: "full"}}});
// Reset parameter.
setMaxDocs(origParamValue);
})();
|