1
- // @tags : [featureFlagAccuratePercentiles]
2
-
3
- import {
4
- testLargeUniformDataset ,
5
- testLargeUniformDataset_WithInfinities ,
6
- testWithMultipleGroups ,
7
- testWithSingleGroup
8
- } from "jstests/aggregation/libs/percentiles_util.js" ;
9
-
10
1
// Tests that certain aggregation operators have configurable memory limits.
11
2
const conn = MongoRunner . runMongod ( ) ;
12
3
assert . neq ( null , conn , "mongod was unable to start up" ) ;
13
4
const db = conn . getDB ( "test" ) ;
14
5
const coll = db . agg_configurable_memory_limit ;
15
6
7
+ // Function to change the parameter value and return the previous value.
8
+ function setParam ( param , val ) {
9
+ const res = db . adminCommand ( { setParameter : 1 , [ param ] : val } ) ;
10
+ assert . commandWorked ( res ) ;
11
+ return res . was ;
12
+ }
13
+
16
14
// The approximate size of the strings below is 22-25 bytes, so configure one memory limit such that
17
15
// 100 of these strings will surely exceed it but 24 of them won't, and another such that 24 will
18
16
// exceed as well.
@@ -36,10 +34,23 @@ assert.commandWorked(bulk.execute());
36
34
assert . doesNotThrow ( ( ) => coll . aggregate ( [ { $group : { _id : null , strings : { $push : "$y" } } } ] ) ) ;
37
35
38
36
// Now lower the limit to test that its configuration is obeyed.
39
- assert . commandWorked (
40
- db . adminCommand ( { setParameter : 1 , internalQueryMaxPushBytes : memLimitArray } ) ) ;
37
+ const originalVal = setParam ( 'internalQueryMaxPushBytes' , memLimitArray ) ;
41
38
assert . throwsWithCode ( ( ) => coll . aggregate ( [ { $group : { _id : null , strings : { $push : "$y" } } } ] ) ,
42
39
ErrorCodes . ExceededMemoryLimit ) ;
40
+ setParam ( 'internalQueryMaxPushBytes' , originalVal ) ;
41
+ } ( ) ) ;
42
+
43
+ ( function testInternalQueryMaxPushBytesSettingWindowFunc ( ) {
44
+ let pipeline = [
45
+ { $setWindowFields : { sortBy : { _id : 1 } , output : { v : { $push : '$y' } } } } ,
46
+ ] ;
47
+ // Test that the default 100MB memory limit isn't reached with our data.
48
+ assert . doesNotThrow ( ( ) => coll . aggregate ( pipeline ) ) ;
49
+
50
+ // Now lower the limit to test that its configuration is obeyed.
51
+ const originalVal = setParam ( 'internalQueryMaxPushBytes' , memLimitArray ) ;
52
+ assert . throwsWithCode ( ( ) => coll . aggregate ( pipeline ) , ErrorCodes . ExceededMemoryLimit ) ;
53
+ setParam ( 'internalQueryMaxPushBytes' , originalVal ) ;
43
54
} ( ) ) ;
44
55
45
56
( function testInternalQueryMaxAddToSetBytesSetting ( ) {
@@ -48,14 +59,31 @@ assert.commandWorked(bulk.execute());
48
59
49
60
// Test that $addToSet needs a tighter limit than $push (because some of the strings are the
50
61
// same).
51
- assert . commandWorked (
52
- db . adminCommand ( { setParameter : 1 , internalQueryMaxAddToSetBytes : memLimitArray } ) ) ;
62
+ const originalVal = setParam ( 'internalQueryMaxAddToSetBytes' , memLimitArray ) ;
53
63
assert . doesNotThrow ( ( ) => coll . aggregate ( [ { $group : { _id : null , strings : { $addToSet : "$y" } } } ] ) ) ;
54
64
55
- assert . commandWorked (
56
- db . adminCommand ( { setParameter : 1 , internalQueryMaxAddToSetBytes : memLimitSet } ) ) ;
65
+ setParam ( 'internalQueryMaxAddToSetBytes' , memLimitSet ) ;
57
66
assert . throwsWithCode ( ( ) => coll . aggregate ( [ { $group : { _id : null , strings : { $addToSet : "$y" } } } ] ) ,
58
67
ErrorCodes . ExceededMemoryLimit ) ;
68
+ setParam ( 'internalQueryMaxAddToSetBytes' , originalVal ) ;
69
+ } ( ) ) ;
70
+
71
+ ( function testInternalQueryMaxAddToSetBytesSettingWindowFunc ( ) {
72
+ let pipeline = [
73
+ { $setWindowFields : { sortBy : { _id : 1 } , output : { v : { $addToSet : '$y' } } } } ,
74
+ ] ;
75
+ // Test that the default 100MB memory limit isn't reached with our data.
76
+ assert . doesNotThrow ( ( ) => coll . aggregate ( pipeline ) ) ;
77
+
78
+ // Test that $addToSet needs a tighter limit than $concatArrays (because some of the strings are
79
+ // the same).
80
+ const originalVal = setParam ( 'internalQueryMaxAddToSetBytes' , memLimitArray ) ;
81
+ assert . doesNotThrow ( ( ) => coll . aggregate ( pipeline ) ) ;
82
+
83
+ // Test that a tighter limit for $addToSet is obeyed.
84
+ setParam ( 'internalQueryMaxAddToSetBytes' , memLimitSet ) ;
85
+ assert . throwsWithCode ( ( ) => coll . aggregate ( pipeline ) , ErrorCodes . ExceededMemoryLimit ) ;
86
+ setParam ( 'internalQueryMaxAddToSetBytes' , originalVal ) ;
59
87
} ( ) ) ;
60
88
61
89
( function testInternalQueryTopNAccumulatorBytesSetting ( ) {
0 commit comments