summaryrefslogtreecommitdiff
path: root/jstests/noPassthrough/views_count_distinct_disk_use.js
diff options
context:
space:
mode:
authorRomans Kasperovics <romans.kasperovics@mongodb.com>2022-04-12 16:43:51 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-12 22:54:31 +0000
commitf285f0af3d8d1448db1abafcaf4506a96af9e511 (patch)
tree4b72f79e7899358c8a882588ccf4017ff41354d7 /jstests/noPassthrough/views_count_distinct_disk_use.js
parentfd75059c83cfa4be0225bd03b9c96a21aea39887 (diff)
downloadmongo-f285f0af3d8d1448db1abafcaf4506a96af9e511.tar.gz
SERVER-63208 Make allowDiskUse opt-out rather than opt-in
Diffstat (limited to 'jstests/noPassthrough/views_count_distinct_disk_use.js')
-rw-r--r--jstests/noPassthrough/views_count_distinct_disk_use.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/jstests/noPassthrough/views_count_distinct_disk_use.js b/jstests/noPassthrough/views_count_distinct_disk_use.js
new file mode 100644
index 00000000000..a8c5167c0b2
--- /dev/null
+++ b/jstests/noPassthrough/views_count_distinct_disk_use.js
@@ -0,0 +1,45 @@
+// Test count and distinct on views use with different values of the allowDiskUseByDefault
+// parameter.
+
+(function() {
+"use strict";
+
+const conn = MongoRunner.runMongod();
+assert.neq(null, conn, "mongod was unable to start up");
+
+const viewsDB = conn.getDB(jsTestName());
+viewsDB.largeColl.drop();
+
+const memoryLimitMb = 1;
+const largeStr = "A".repeat(1024 * 1024); // 1MB string
+
+// Create a collection exceeding the memory limit.
+for (let i = 0; i < memoryLimitMb + 1; ++i)
+ assert.commandWorked(viewsDB.largeColl.insert({x: i, largeStr: largeStr}));
+
+viewsDB.largeView.drop();
+assert.commandWorked(viewsDB.createView("largeView", "largeColl", [{$sort: {x: -1}}]));
+
+function testDiskUse(cmd) {
+ assert.commandWorked(viewsDB.adminCommand({setParameter: 1, allowDiskUseByDefault: false}));
+ assert.commandFailedWithCode(viewsDB.runCommand(cmd),
+ ErrorCodes.QueryExceededMemoryLimitNoDiskUseAllowed);
+
+ assert.commandWorked(viewsDB.adminCommand({setParameter: 1, allowDiskUseByDefault: true}));
+ assert.commandWorked(viewsDB.runCommand(cmd));
+}
+
+// The 'count' command executes the view definition pipeline containing the '$sort' stage. This
+// stage needs to spill to disk if the memory limit is reached.
+assert.commandWorked(viewsDB.adminCommand(
+ {setParameter: 1, internalQueryMaxBlockingSortMemoryUsageBytes: memoryLimitMb * 1024 * 1024}));
+testDiskUse({count: "largeView"});
+
+// The 'distinct' command involves '$groupBy' stage. This stage needs to spill to disk if the memory
+// limit is reached.
+assert.commandWorked(viewsDB.adminCommand(
+ {setParameter: 1, internalDocumentSourceGroupMaxMemoryBytes: memoryLimitMb * 1024 * 1024}));
+testDiskUse({distinct: "largeView", key: "largeStr"});
+
+MongoRunner.stopMongod(conn);
+})();