diff options
author | Gabriel Marks <gabriel.marks@mongodb.com> | 2022-07-06 18:50:30 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-07 21:01:15 +0000 |
commit | aef40887716046f0ac3503d3142630a23ae8b1e5 (patch) | |
tree | 32f8ec81899c63c47763d022461dfec4567dbb48 | |
parent | 4f48766343c4d029d2b5cf373c3a6c46ddf6b576 (diff) | |
download | mongo-aef40887716046f0ac3503d3142630a23ae8b1e5.tar.gz |
SERVER-67532 Fail oplog server status section less
-rw-r--r-- | jstests/replsets/optime.js | 7 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_info.cpp | 14 |
2 files changed, 12 insertions, 9 deletions
diff --git a/jstests/replsets/optime.js b/jstests/replsets/optime.js index 7311c5e9b9d..0c633d490c4 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 primary = replTest.getPrimary(); diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp index fe056f4c41c..ede3d0268e1 100644 --- a/src/mongo/db/repl/replication_info.cpp +++ b/src/mongo/db/repl/replication_info.cpp @@ -227,11 +227,11 @@ public: BSONObjBuilder result; result.append("latestOptime", replCoord->getMyLastAppliedOpTime().getTimestamp()); - auto earliestOplogTimestampFetch = [&]() -> StatusWith<Timestamp> { + auto earliestOplogTimestampFetch = [&]() -> Timestamp { auto oplog = CollectionCatalog::get(opCtx)->lookupCollectionByNamespaceForRead( opCtx, NamespaceString::kRsOplogNamespace); if (!oplog) { - 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. @@ -261,13 +261,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(); } |