diff options
author | Pol Pinol Castuera <pol.pinol@mongodb.com> | 2023-04-27 15:46:33 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-04-27 16:52:59 +0000 |
commit | 7cc123ecf2bbc38450ac2792203a3e41900d25a7 (patch) | |
tree | a1a9394056e658cf8fe1cebb221ef3074a37eae3 /src/mongo | |
parent | 7ba940ca2e7dfe4751e58a5b6fcb9ce7923de3f6 (diff) | |
download | mongo-7cc123ecf2bbc38450ac2792203a3e41900d25a7.tar.gz |
SERVER-75390 Fix CheckMetadataConsistency command with many results
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/s/metadata_consistency_util.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/s/shardsvr_check_metadata_consistency_participant_command.cpp | 30 |
2 files changed, 32 insertions, 9 deletions
diff --git a/src/mongo/db/s/metadata_consistency_util.cpp b/src/mongo/db/s/metadata_consistency_util.cpp index 42481d41fe4..f98b2fd35a6 100644 --- a/src/mongo/db/s/metadata_consistency_util.cpp +++ b/src/mongo/db/s/metadata_consistency_util.cpp @@ -49,6 +49,8 @@ namespace metadata_consistency_util { namespace { +MONGO_FAIL_POINT_DEFINE(insertFakeInconsistencies); + /* * Emit a warning log containing information about the given inconsistency */ @@ -153,6 +155,15 @@ std::unique_ptr<PlanExecutor, PlanExecutor::Deleter> makeQueuedPlanExecutor( auto ws = std::make_unique<WorkingSet>(); auto root = std::make_unique<QueuedDataStage>(expCtx.get(), ws.get()); + insertFakeInconsistencies.execute([&](const BSONObj& data) { + const auto numInconsistencies = data["numInconsistencies"].safeNumberLong(); + for (int i = 0; i < numInconsistencies; i++) { + inconsistencies.emplace_back(makeInconsistency( + MetadataInconsistencyTypeEnum::kCollectionUUIDMismatch, + CollectionUUIDMismatchDetails{nss, ShardId{"shard"}, UUID::gen(), UUID::gen()})); + } + }); + for (auto&& inconsistency : inconsistencies) { // Every inconsistency encountered need to be logged with the same format // to allow log injestion systems to correctly detect them. diff --git a/src/mongo/db/s/shardsvr_check_metadata_consistency_participant_command.cpp b/src/mongo/db/s/shardsvr_check_metadata_consistency_participant_command.cpp index 4fe358478a0..0d57f8494ed 100644 --- a/src/mongo/db/s/shardsvr_check_metadata_consistency_participant_command.cpp +++ b/src/mongo/db/s/shardsvr_check_metadata_consistency_participant_command.cpp @@ -32,13 +32,13 @@ #include "mongo/db/catalog/collection_catalog.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" -#include "mongo/db/cursor_manager.h" #include "mongo/db/s/ddl_lock_manager.h" #include "mongo/db/s/metadata_consistency_util.h" #include "mongo/db/s/sharding_state.h" #include "mongo/logv2/log.h" #include "mongo/s/grid.h" #include "mongo/s/query/cluster_aggregate.h" +#include "mongo/s/query/cluster_cursor_manager.h" #include "mongo/s/request_types/sharded_ddl_commands_gen.h" #include "mongo/s/stale_shard_version_helpers.h" @@ -157,15 +157,27 @@ std::vector<MetadataInconsistencyItem> checkIndexesInconsistencies( return; } - auto cursorPin = uassertStatusOK( - CursorManager::get(opCtx)->pinCursor(opCtx, indexStatsCursor.getCursorId())); - auto exec = cursorPin->getExecutor(); + const auto authzSession = AuthorizationSession::get(opCtx->getClient()); + const auto authChecker = + [&authzSession](const boost::optional<UserName>& userName) -> Status { + return authzSession->isCoauthorizedWith(userName) + ? Status::OK() + : Status(ErrorCodes::Unauthorized, "User not authorized to access cursor"); + }; + + // Check out the cursor. If the cursor is not found, all data was retrieve in the + // first batch. + const auto cursorManager = Grid::get(opCtx)->getCursorManager(); + auto pinnedCursor = uassertStatusOK(cursorManager->checkOutCursor( + indexStatsCursor.getCursorId(), opCtx, authChecker)); + while (true) { + auto next = pinnedCursor->next(); + if (!next.isOK() || next.getValue().isEOF()) { + break; + } - BSONObj nextDoc; - while (!exec->isEOF()) { - auto state = exec->getNext(&nextDoc, nullptr); - if (state == PlanExecutor::ADVANCED) { - results.emplace_back(nextDoc); + if (auto data = next.getValue().getResult()) { + results.emplace_back(data.get().getOwned()); } } }); |