diff options
author | Jennifer Peshansky <jennifer.peshansky@mongodb.com> | 2022-11-03 16:13:20 +0000 |
---|---|---|
committer | Jennifer Peshansky <jennifer.peshansky@mongodb.com> | 2022-11-03 16:13:20 +0000 |
commit | e74d2910bbe76790ad131d53fee277829cd95982 (patch) | |
tree | cabe148764529c9623652374fbc36323a550cd44 /src/mongo/db/service_entry_point_common.cpp | |
parent | 280145e9940729480bb8a35453d4056afac87641 (diff) | |
parent | ba467f46cc1bc49965e1d72b541eff0cf1d7b22e (diff) | |
download | mongo-e74d2910bbe76790ad131d53fee277829cd95982.tar.gz |
Merge branch 'master' into jenniferpeshansky/SERVER-70854jenniferpeshansky/SERVER-70854
Diffstat (limited to 'src/mongo/db/service_entry_point_common.cpp')
-rw-r--r-- | src/mongo/db/service_entry_point_common.cpp | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp index 0c4766739e4..84f46d900dd 100644 --- a/src/mongo/db/service_entry_point_common.cpp +++ b/src/mongo/db/service_entry_point_common.cpp @@ -2105,7 +2105,20 @@ DbResponse makeCommandResponse(std::shared_ptr<HandleRequest::ExecutionContext> } } - dbResponse.response = replyBuilder->done(); + try { + dbResponse.response = replyBuilder->done(); + } catch (const ExceptionFor<ErrorCodes::BSONObjectTooLarge>& ex) { + // Create a new reply builder as subsequently calling any methods on a builder after + // 'done()' results in undefined behavior. + auto errorReplyBuilder = execContext->getReplyBuilder(); + BSONObjBuilder metadataBob; + BSONObjBuilder extraFieldsBuilder; + appendClusterAndOperationTime( + opCtx, &extraFieldsBuilder, &metadataBob, LogicalTime::kUninitialized); + generateErrorResponse( + opCtx, errorReplyBuilder, ex.toStatus(), metadataBob.obj(), extraFieldsBuilder.obj()); + dbResponse.response = errorReplyBuilder->done(); + } CurOp::get(opCtx)->debug().responseLength = dbResponse.response.header().dataLen(); return dbResponse; @@ -2347,10 +2360,26 @@ BSONObj ServiceEntryPointCommon::getRedactedCopyForLogging(const Command* comman return bob.obj(); } -void onHandleRequestException(const Status& status) { +void logHandleRequestFailure(const Status& status) { LOGV2_ERROR(4879802, "Failed to handle request", "error"_attr = redact(status)); } +void onHandleRequestException(const HandleRequest& hr, const Status& status) { + auto isMirrorOp = [&] { + const auto& obj = hr.executionContext->getRequest().body; + if (auto e = obj.getField("mirrored"); MONGO_unlikely(e.ok() && e.boolean())) + return true; + return false; + }; + + // TODO SERVER-70510 revert changes introduced by SERVER-60553 that suppresses errors occurred + // during handling of mirroring operations on recovering secondaries. + if (MONGO_unlikely(status == ErrorCodes::NotWritablePrimary && isMirrorOp())) + return; + + logHandleRequestFailure(status); +} + Future<DbResponse> ServiceEntryPointCommon::handleRequest( OperationContext* opCtx, const Message& m, @@ -2362,7 +2391,7 @@ Future<DbResponse> ServiceEntryPointCommon::handleRequest( invariant(opRunner); return opRunner->run() - .then([hr = std::move(hr)](DbResponse response) mutable { + .then([&hr](DbResponse response) mutable { hr.completeOperation(response); auto opCtx = hr.executionContext->getOpCtx(); @@ -2377,10 +2406,10 @@ Future<DbResponse> ServiceEntryPointCommon::handleRequest( return response; }) - .tapError([](Status status) { onHandleRequestException(status); }); + .tapError([hr = std::move(hr)](Status status) { onHandleRequestException(hr, status); }); } catch (const DBException& ex) { auto status = ex.toStatus(); - onHandleRequestException(status); + logHandleRequestFailure(status); return status; } |