summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Marks <gabriel.marks@mongodb.com>2022-07-06 18:50:30 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-07-07 21:40:33 +0000
commit0380c2736e2af6977362bda891e1a71b940cdd83 (patch)
treeadacc057c6c34afa0e7b6a2ebe1b1e7fa297c1b6
parent9827d2a5d878ff635285e394b98648231dbea268 (diff)
downloadmongo-0380c2736e2af6977362bda891e1a71b940cdd83.tar.gz
SERVER-67532 Fail oplog server status section less
-rw-r--r--jstests/replsets/optime.js7
-rw-r--r--src/mongo/db/repl/replication_info.cpp14
2 files changed, 12 insertions, 9 deletions
diff --git a/jstests/replsets/optime.js b/jstests/replsets/optime.js
index 4ba7720a516..7fdbd61c201 100644
--- a/jstests/replsets/optime.js
+++ b/jstests/replsets/optime.js
@@ -62,8 +62,11 @@ var replTest = new ReplSetTest(
const nodes = replTest.startSet();
-// Tests that serverStatus oplog returns an error if the oplog collection doesn't exist.
-assert.commandFailedWithCode(nodes[0].getDB('admin').serverStatus({oplog: true}), 17347);
+// Tests that serverStatus oplog returns null timestamps if the oplog collection doesn't exist.
+const zeroTs = new Timestamp(0, 0);
+const oplogStatus = nodes[0].getDB('admin').serverStatus({oplog: true}).oplog;
+assert.eq(oplogStatus.earliestOptime, zeroTs);
+assert.eq(oplogStatus.latestOptime, zeroTs);
replTest.initiate();
var master = replTest.getPrimary();
diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp
index 8d994dd93b2..0e827661882 100644
--- a/src/mongo/db/repl/replication_info.cpp
+++ b/src/mongo/db/repl/replication_info.cpp
@@ -275,10 +275,10 @@ public:
BSONObjBuilder result;
result.append("latestOptime", replCoord->getMyLastAppliedOpTime().getTimestamp());
- auto earliestOplogTimestampFetch = [&]() -> StatusWith<Timestamp> {
+ auto earliestOplogTimestampFetch = [&]() -> Timestamp {
AutoGetOplog oplogRead(opCtx, OplogAccessMode::kRead);
if (!oplogRead.getCollection()) {
- return StatusWith<Timestamp>(ErrorCodes::NamespaceNotFound, "oplog doesn't exist");
+ return Timestamp();
}
// Try to get the lock. If it's already locked, immediately return null timestamp.
@@ -305,13 +305,13 @@ public:
return o["ts"].timestamp();
}
}
-
- return swEarliestOplogTimestamp;
+ if (!swEarliestOplogTimestamp.isOK()) {
+ return Timestamp();
+ }
+ return swEarliestOplogTimestamp.getValue();
}();
- uassert(
- 17347, "Problem reading earliest entry from oplog", earliestOplogTimestampFetch.isOK());
- result.append("earliestOptime", earliestOplogTimestampFetch.getValue());
+ result.append("earliestOptime", earliestOplogTimestampFetch);
return result.obj();
}