summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHana Pearlman <hana.pearlman@mongodb.com>2021-04-09 14:11:17 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-04-09 21:54:36 +0000
commit08a3670941791e132aac71298c94d35b9c8ecc25 (patch)
tree30d4a49560648daef2331299e9c432f378c45871
parentbb3810d2f1b076e3726ec7f9a8d558e08b3427bf (diff)
downloadmongo-08a3670941791e132aac71298c94d35b9c8ecc25.tar.gz
SERVER-55904: Consolidate getFirstOplogEntry and getLeastRecentOp helpers
-rw-r--r--jstests/noPassthrough/change_streams_oplog_rollover.js2
-rw-r--r--jstests/noPassthrough/oplog_rollover_agg.js2
-rw-r--r--jstests/replsets/rslib.js25
-rw-r--r--jstests/sharding/change_streams/resume_change_stream.js3
4 files changed, 13 insertions, 19 deletions
diff --git a/jstests/noPassthrough/change_streams_oplog_rollover.js b/jstests/noPassthrough/change_streams_oplog_rollover.js
index d483e345279..29bb2a15e42 100644
--- a/jstests/noPassthrough/change_streams_oplog_rollover.js
+++ b/jstests/noPassthrough/change_streams_oplog_rollover.js
@@ -94,7 +94,7 @@ function oplogIsRolledOver() {
// oplog's current oldest entry. Said another way, the oplog is rolled over when
// everything in the oplog is newer than what used to be the newest entry.
return bsonWoCompare(mostRecentOplogEntry.ts,
- getLeastRecentOp({server: primaryNode, readConcern: "majority"}).ts) < 0;
+ getFirstOplogEntry(primaryNode, {readConcern: "majority"}).ts) < 0;
}
while (!oplogIsRolledOver()) {
diff --git a/jstests/noPassthrough/oplog_rollover_agg.js b/jstests/noPassthrough/oplog_rollover_agg.js
index 23607e95395..56a77ffcd6f 100644
--- a/jstests/noPassthrough/oplog_rollover_agg.js
+++ b/jstests/noPassthrough/oplog_rollover_agg.js
@@ -88,7 +88,7 @@ function oplogIsRolledOver() {
// oplog's current oldest entry. Said another way, the oplog is rolled over when
// everything in the oplog is newer than what used to be the newest entry.
return bsonWoCompare(mostRecentOplogEntry.ts,
- getLeastRecentOp({server: primaryNode, readConcern: "majority"}).ts) < 0;
+ getFirstOplogEntry(primaryNode, {readConcern: "majority"}).ts) < 0;
}
while (!oplogIsRolledOver()) {
diff --git a/jstests/replsets/rslib.js b/jstests/replsets/rslib.js
index 42d9ea73cce..52ea59eab39 100644
--- a/jstests/replsets/rslib.js
+++ b/jstests/replsets/rslib.js
@@ -3,7 +3,6 @@ var wait;
var occasionally;
var reconnect;
var getLatestOp;
-var getLeastRecentOp;
var waitForAllMembers;
var reconfig;
var awaitOpTime;
@@ -160,16 +159,6 @@ getLatestOp = function(server) {
return null;
};
-getLeastRecentOp = function({server, readConcern}) {
- server.getDB("admin").getMongo().setSecondaryOk();
- const oplog = server.getDB("local").oplog.rs;
- const cursor = oplog.find().sort({$natural: 1}).limit(1).readConcern(readConcern);
- if (cursor.hasNext()) {
- return cursor.next();
- }
- return null;
-};
-
waitForAllMembers = function(master, timeout) {
var failCount = 0;
@@ -631,16 +620,22 @@ getLastOpTime = function(conn) {
/**
* Returns the oldest oplog entry.
*/
-getFirstOplogEntry = function(conn) {
- let firstEntry;
+getFirstOplogEntry = function(server, opts = {}) {
+ server.getDB("admin").getMongo().setSecondaryOk();
+
+ let firstEntryQuery = server.getDB('local').oplog.rs.find().sort({$natural: 1}).limit(1);
+ if (opts.readConcern) {
+ firstEntryQuery = firstEntryQuery.readConcern(opts.readConcern);
+ }
+
// The query plan may yield between the cursor establishment and iterating to retrieve the first
// result. During this yield it's possible for the oplog to "roll over" or shrink. This is rare,
// but if these both happen the cursor will be unable to resume after yielding and return a
// "CappedPositionLost" error. This can be safely retried.
+ let firstEntry;
assert.soon(() => {
try {
- firstEntry =
- conn.getDB('local').oplog.rs.find().sort({$natural: 1}).limit(1).toArray()[0];
+ firstEntry = firstEntryQuery.toArray()[0];
return true;
} catch (e) {
if (e.code == ErrorCodes.CappedPositionLost) {
diff --git a/jstests/sharding/change_streams/resume_change_stream.js b/jstests/sharding/change_streams/resume_change_stream.js
index f96dfc113af..4ba7520f8c9 100644
--- a/jstests/sharding/change_streams/resume_change_stream.js
+++ b/jstests/sharding/change_streams/resume_change_stream.js
@@ -103,8 +103,7 @@ function testResume(mongosColl, collToWatch) {
// everything in the oplog is newer than what used to be the newest entry.
return bsonWoCompare(
mostRecentOplogEntry.ts,
- getLeastRecentOp({server: shardWithResumeToken, readConcern: "majority"}).ts) <
- 0;
+ getFirstOplogEntry(shardWithResumeToken, {readConcern: "majority"}).ts) < 0;
}
while (!oplogIsRolledOver()) {