From 1b475ef190b29cb62d9a205a05bde1d2ddb6332b Mon Sep 17 00:00:00 2001 From: Gregory Wlodarek Date: Mon, 6 Feb 2023 22:51:09 +0000 Subject: SERVER-71353 Add diagnostics for when the durable catalog is scanned due to missing catalogId mapping --- src/mongo/db/catalog/collection_catalog.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/mongo/db/catalog/collection_catalog.cpp b/src/mongo/db/catalog/collection_catalog.cpp index 40b45b404d8..ed75b200986 100644 --- a/src/mongo/db/catalog/collection_catalog.cpp +++ b/src/mongo/db/catalog/collection_catalog.cpp @@ -33,6 +33,7 @@ #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/uncommitted_catalog_updates.h" +#include "mongo/db/commands/server_status.h" #include "mongo/db/concurrency/exception_util.h" #include "mongo/db/concurrency/lock_manager_defs.h" #include "mongo/db/concurrency/resource_catalog.h" @@ -60,6 +61,8 @@ static RecordId kUnknownRangeMarkerId = RecordId::minLong(); // reached we will fall back to more durable catalog scans. static constexpr int kMaxCatalogIdMappingLengthForMissingInsert = 1000; +constexpr auto kNumDurableCatalogScansDueToMissingMapping = "numScansDueToMissingMapping"_sd; + struct LatestCollectionCatalog { std::shared_ptr catalog = std::make_shared(); }; @@ -100,6 +103,27 @@ const auto minUuid = UUID::parse("00000000-0000-0000-0000-000000000000").getValu } // namespace +/** + * Defines a new serverStatus section "collectionCatalog". + */ +class CollectionCatalogSection final : public ServerStatusSection { +public: + CollectionCatalogSection() : ServerStatusSection("collectionCatalog") {} + + bool includeByDefault() const override { + return true; + } + + BSONObj generateSection(OperationContext* opCtx, const BSONElement&) const override { + BSONObjBuilder section; + section.append(kNumDurableCatalogScansDueToMissingMapping, + numScansDueToMissingMapping.loadRelaxed()); + return section.obj(); + } + + AtomicWord numScansDueToMissingMapping; +} gCollectionCatalogSection; + class IgnoreExternalViewChangesForDatabase { public: IgnoreExternalViewChangesForDatabase(OperationContext* opCtx, const DatabaseName& dbName) @@ -1036,6 +1060,7 @@ boost::optional CollectionCatalog::_fetchPITCatalogEntry( invariant(readTimestamp); // Scan durable catalog when we don't have accurate catalogId mapping for this timestamp. + gCollectionCatalogSection.numScansDueToMissingMapping.fetchAndAdd(1); auto catalogEntry = DurableCatalog::get(opCtx)->scanForCatalogEntryByNss(opCtx, nss); writeCatalogIdAfterScan(catalogEntry); return catalogEntry; -- cgit v1.2.1