From c8ab2de5e1c1dea00aa7506efd19d4aabd92bf0f Mon Sep 17 00:00:00 2001 From: Jason Chan Date: Wed, 27 Jan 2021 19:20:31 +0000 Subject: SERVER-53831 Force SpiderMonkey to garbage collect in ReplSetTest.checkOplogs (cherry picked from commit 96fe72c36d370a4067240738f051021d4daf72ce) --- src/mongo/shell/replsettest.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/mongo/shell/replsettest.js b/src/mongo/shell/replsettest.js index 481c1f60339..1017d5072ce 100644 --- a/src/mongo/shell/replsettest.js +++ b/src/mongo/shell/replsettest.js @@ -2268,8 +2268,13 @@ var ReplSetTest = function(opts) { const firstReader = readers[firstReaderIndex]; let prevOplogEntry; assert(firstReader.hasNext(), "oplog is empty while checkOplogs is called"); + // Track the number of bytes we are reading as we check the oplog. We use this to avoid + // out-of-memory issues by calling to garbage collect whenever the memory footprint is + // large. + let bytesSinceGC = 0; while (firstReader.hasNext()) { const oplogEntry = firstReader.next(); + bytesSinceGC += Object.bsonsize(oplogEntry); if (oplogEntry === kCappedPositionLostSentinel) { // When using legacy OP_QUERY/OP_GET_MORE reads against mongos, it is // possible for hasNext() to return true but for next() to throw an exception. @@ -2284,6 +2289,7 @@ var ReplSetTest = function(opts) { } const otherOplogEntry = readers[i].next(); + bytesSinceGC += Object.bsonsize(otherOplogEntry); if (otherOplogEntry && otherOplogEntry !== kCappedPositionLostSentinel) { assertOplogEntriesEq.call(this, oplogEntry, @@ -2293,6 +2299,11 @@ var ReplSetTest = function(opts) { prevOplogEntry); } } + // Garbage collect every 10MB. + if (bytesSinceGC > (10 * 1024 * 1024)) { + gc(); + bytesSinceGC = 0; + } prevOplogEntry = oplogEntry; } } -- cgit v1.2.1