summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Marks <gabriel.marks@mongodb.com>2022-04-27 16:59:55 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-27 17:13:55 +0000
commitc3a1283b77ac3852a30c9a5c7069c8b2e3f30a8c (patch)
tree32d1ff97664b5f3fdd3a1d59b9996d18d8f9ba05
parentdcd58499e169085955b294fb013eebe50b8fe1a5 (diff)
downloadmongo-c3a1283b77ac3852a30c9a5c7069c8b2e3f30a8c.tar.gz
SERVER-62941 Add oplog server status to FTDC
-rw-r--r--src/mongo/db/ftdc/ftdc_server.cpp3
-rw-r--r--src/mongo/db/repl/replication_info.cpp38
2 files changed, 30 insertions, 11 deletions
diff --git a/src/mongo/db/ftdc/ftdc_server.cpp b/src/mongo/db/ftdc/ftdc_server.cpp
index da7a6cbfcc5..c9bca99d8fd 100644
--- a/src/mongo/db/ftdc/ftdc_server.cpp
+++ b/src/mongo/db/ftdc/ftdc_server.cpp
@@ -210,6 +210,8 @@ public:
// "defaultRWConcern" is excluded because it changes rarely and instead included in rotation
// "mirroredReads" is included to append the number of mirror-able operations observed and
// mirrored by this process in FTDC collections.
+ // "oplog" is included to append the earliest and latest optimes, which allow calculation of
+ // the oplog window.
BSONObjBuilder commandBuilder;
commandBuilder.append(kCommand, 1);
@@ -217,6 +219,7 @@ public:
commandBuilder.append("timing", false);
commandBuilder.append("defaultRWConcern", false);
commandBuilder.append(MirrorMaestro::kServerStatusSectionName, true);
+ commandBuilder.append("oplog", true);
// Exclude 'serverStatus.transactions.lastCommittedTransactions' because it triggers
// frequent schema changes.
diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp
index 3bb8c198deb..8d994dd93b2 100644
--- a/src/mongo/db/repl/replication_info.cpp
+++ b/src/mongo/db/repl/replication_info.cpp
@@ -273,25 +273,41 @@ public:
}
BSONObjBuilder result;
- // TODO(siyuan) Output term of OpTime
result.append("latestOptime", replCoord->getMyLastAppliedOpTime().getTimestamp());
- auto earliestOplogTimestampFetch = [&] {
+ auto earliestOplogTimestampFetch = [&]() -> StatusWith<Timestamp> {
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;
- if (Helpers::getSingleton(opCtx, NamespaceString::kRsOplogNamespace.ns().c_str(), o)) {
- earliestOplogTimestampFetch = o["ts"].timestamp();
+ // Try to get the lock. If it's already locked, immediately return null timestamp.
+ Lock::GlobalLock lk(
+ opCtx, MODE_IS, Date_t::now(), Lock::InterruptBehavior::kLeaveUnlocked);
+ if (!lk.isLocked()) {
+ LOGV2_DEBUG(
+ 6294100, 2, "Failed to get global lock for oplog server status section");
+ return Timestamp();
}
- }
+
+ // Try getting earliest oplog timestamp using getEarliestOplogTimestamp
+ auto swEarliestOplogTimestamp =
+ oplogRead.getCollection()->getRecordStore()->getEarliestOplogTimestamp(opCtx);
+
+ if (swEarliestOplogTimestamp.getStatus() == ErrorCodes::OplogOperationUnsupported) {
+ // Falling back to use getSingleton if the storage engine does not support
+ // getEarliestOplogTimestamp.
+ // Note that getSingleton will take a global IS lock, but this won't block because
+ // we are already holding the global IS lock.
+ BSONObj o;
+ if (Helpers::getSingleton(
+ opCtx, NamespaceString::kRsOplogNamespace.ns().c_str(), o)) {
+ return o["ts"].timestamp();
+ }
+ }
+
+ return swEarliestOplogTimestamp;
+ }();
uassert(
17347, "Problem reading earliest entry from oplog", earliestOplogTimestampFetch.isOK());