From aaa930aaedec274884cac8f874c7bcddc63f948e Mon Sep 17 00:00:00 2001 From: Chenhao Qu Date: Tue, 31 Oct 2023 06:31:42 +1100 Subject: [PATCH] SERVER-56896 Log the duplicate key error concisley with arrtributes --- src/mongo/db/repl/oplog_applier_utils.cpp | 8 ++++++++ src/mongo/db/repl/replication_recovery.cpp | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/src/mongo/db/repl/oplog_applier_utils.cpp b/src/mongo/db/repl/oplog_applier_utils.cpp index 928e1f00c19..adc0910c926 100644 --- a/src/mongo/db/repl/oplog_applier_utils.cpp +++ b/src/mongo/db/repl/oplog_applier_utils.cpp @@ -641,6 +641,14 @@ Status OplogApplierUtils::applyOplogBatchCommon( "error"_attr = causedBy(redact(status))); return status; } + } catch (const ExceptionFor& e) { + auto info = e.extraInfo(); + LOGV2_FATAL_CONTINUE(5689600, + "Writer worker caught duplicate key exception", + "keyPattern"_attr = redact(info->getKeyPattern()), + "keyValue"_attr = redact(info->getDuplicatedKeyValue()), + "oplogEntry"_attr = redact(op->toBSONForLogging())); + return e.toStatus(); } catch (const DBException& e) { // SERVER-24927 If we have a NamespaceNotFound exception, then this document will be // dropped before initial sync or recovery ends anyways and we should ignore it. diff --git a/src/mongo/db/repl/replication_recovery.cpp b/src/mongo/db/repl/replication_recovery.cpp index 7df39708c4f..961dc70e752 100644 --- a/src/mongo/db/repl/replication_recovery.cpp +++ b/src/mongo/db/repl/replication_recovery.cpp @@ -509,6 +509,13 @@ boost::optional ReplicationRecoveryImpl::recoverFromOplog( opCtx, _consistencyMarkers->getAppliedThrough(opCtx), topOfOplog); } return stableTimestamp; +} catch (const ExceptionFor& e) { + auto info = e.extraInfo(); + LOGV2_FATAL_CONTINUE(5689601, + "Caught duplicate key exception during replication recovery", + "keyPattern"_attr = redact(info->getKeyPattern()), + "keyValue"_attr = redact(info->getDuplicatedKeyValue())); + std::terminate(); } catch (...) { LOGV2_FATAL_CONTINUE( 21570, "Caught exception during replication recovery", "error"_attr = exceptionToStatus());