From e4528b06f85b1431f5526e5acb14aa58cb8bfcf7 Mon Sep 17 00:00:00 2001 From: Gabriel Marks Date: Wed, 6 Jul 2022 18:50:30 +0000 Subject: SERVER-67532 Fail oplog server status section less --- etc/backports_required_for_multiversion_tests.yml | 2 ++ jstests/replsets/optime.js | 7 +++++-- src/mongo/db/repl/replication_info.cpp | 14 +++++++------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml index d1200365bde..adddb435d8c 100644 --- a/etc/backports_required_for_multiversion_tests.yml +++ b/etc/backports_required_for_multiversion_tests.yml @@ -215,6 +215,8 @@ all: test_file: jstests/change_streams/show_raw_update_description_v1_oplog.js - ticket: SERVER-63159 test_file: jstests/core/internal_apply_oplog_update.js + - ticket: SERVER-67532 + test_file: jstests/replsets/optime.js suites: 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 { + auto earliestOplogTimestampFetch = [&]() -> Timestamp { AutoGetOplog oplogRead(opCtx, OplogAccessMode::kRead); if (!oplogRead.getCollection()) { - return StatusWith(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(); } -- cgit v1.2.1