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-09-23 00:04:43 +0000
commit3e22135e6be46b70ac466c3783fbcf3cc0084ded (patch)
treecc0df3e90a74a7b898b19807b10a9792f2a2f524
parent801fc62596caee9c1c5aa6b4edf1a3e2ee857690 (diff)
downloadmongo-3e22135e6be46b70ac466c3783fbcf3cc0084ded.tar.gz
SERVER-55904: Consolidate getFirstOplogEntry and getLeastRecentOp helpers
-rw-r--r--jstests/replsets/rslib.js25
-rw-r--r--jstests/sharding/resume_change_stream.js3
2 files changed, 11 insertions, 17 deletions
diff --git a/jstests/replsets/rslib.js b/jstests/replsets/rslib.js
index 84c7d8db92a..76820184355 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;
@@ -155,16 +154,6 @@ getLatestOp = function(server) {
return null;
};
-getLeastRecentOp = function({server, readConcern}) {
- server.getDB("admin").getMongo().setSlaveOk();
- 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;
@@ -601,16 +590,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/resume_change_stream.js b/jstests/sharding/resume_change_stream.js
index 34afc9c0208..2da931c0fa6 100644
--- a/jstests/sharding/resume_change_stream.js
+++ b/jstests/sharding/resume_change_stream.js
@@ -109,8 +109,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()) {