mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
SERVER-47179: Fix crash when requesting serverStatus oplog before the oplog collection is created
This commit is contained in:
parent
f44ca2e82c
commit
d34b92cb31
@ -59,7 +59,11 @@ function optimesAndWallTimesAreEqual(replTest, isPersistent) {
|
||||
var replTest = new ReplSetTest(
|
||||
{name: "replStatus", nodes: 3, oplogSize: 1, waitForKeys: true, nodeOptions: {syncdelay: 1}});
|
||||
|
||||
replTest.startSet();
|
||||
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);
|
||||
|
||||
replTest.initiate();
|
||||
var master = replTest.getPrimary();
|
||||
replTest.awaitReplication();
|
||||
|
@ -268,21 +268,27 @@ public:
|
||||
// TODO(siyuan) Output term of OpTime
|
||||
result.append("latestOptime", replCoord->getMyLastAppliedOpTime().getTimestamp());
|
||||
|
||||
AutoGetOplog oplogRead(opCtx, OplogAccessMode::kRead);
|
||||
auto earliestOplogTimestampFetch =
|
||||
oplogRead.getCollection()->getRecordStore()->getEarliestOplogTimestamp(opCtx);
|
||||
Timestamp earliestOplogTimestamp;
|
||||
if (earliestOplogTimestampFetch.isOK()) {
|
||||
earliestOplogTimestamp = earliestOplogTimestampFetch.getValue();
|
||||
} else {
|
||||
auto earliestOplogTimestampFetch = [&] {
|
||||
AutoGetOplog oplogRead(opCtx, OplogAccessMode::kRead);
|
||||
if (!oplogRead.getCollection()) {
|
||||
return StatusWith<Timestamp>(ErrorCodes::NamespaceNotFound, "oplog doesn't exist");
|
||||
}
|
||||
return oplogRead.getCollection()->getRecordStore()->getEarliestOplogTimestamp(opCtx);
|
||||
}();
|
||||
|
||||
if (earliestOplogTimestampFetch.getStatus() == ErrorCodes::OplogOperationUnsupported) {
|
||||
// Falling back to use getSingleton if the storage engine does not support
|
||||
// getEarliestOplogTimestamp.
|
||||
BSONObj o;
|
||||
uassert(
|
||||
17347,
|
||||
"Problem reading earliest entry from oplog",
|
||||
Helpers::getSingleton(opCtx, NamespaceString::kRsOplogNamespace.ns().c_str(), o));
|
||||
earliestOplogTimestamp = o["ts"].timestamp();
|
||||
if (Helpers::getSingleton(opCtx, NamespaceString::kRsOplogNamespace.ns().c_str(), o)) {
|
||||
earliestOplogTimestampFetch = o["ts"].timestamp();
|
||||
}
|
||||
}
|
||||
result.append("earliestOptime", earliestOplogTimestamp);
|
||||
|
||||
uassert(
|
||||
17347, "Problem reading earliest entry from oplog", earliestOplogTimestampFetch.isOK());
|
||||
result.append("earliestOptime", earliestOplogTimestampFetch.getValue());
|
||||
|
||||
return result.obj();
|
||||
}
|
||||
} oplogInfoServerStatus;
|
||||
|
Loading…
Reference in New Issue
Block a user