summaryrefslogtreecommitdiff
path: root/src/mongo/db/concurrency
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/concurrency')
-rw-r--r--src/mongo/db/concurrency/d_concurrency_test.cpp8
-rw-r--r--src/mongo/db/concurrency/deferred_writer.cpp2
-rw-r--r--src/mongo/db/concurrency/exception_util.h18
3 files changed, 18 insertions, 10 deletions
diff --git a/src/mongo/db/concurrency/d_concurrency_test.cpp b/src/mongo/db/concurrency/d_concurrency_test.cpp
index fd3c6e5de70..db14817b030 100644
--- a/src/mongo/db/concurrency/d_concurrency_test.cpp
+++ b/src/mongo/db/concurrency/d_concurrency_test.cpp
@@ -183,7 +183,7 @@ public:
TEST_F(DConcurrencyTestFixture, WriteConflictRetryInstantiatesOK) {
auto opCtx = makeOperationContext();
getClient()->swapLockState(std::make_unique<LockerImpl>(opCtx->getServiceContext()));
- writeConflictRetry(opCtx.get(), "", "", [] {});
+ writeConflictRetry(opCtx.get(), "", NamespaceString(), [] {});
}
TEST_F(DConcurrencyTestFixture, WriteConflictRetryRetriesFunctionOnWriteConflictException) {
@@ -191,7 +191,7 @@ TEST_F(DConcurrencyTestFixture, WriteConflictRetryRetriesFunctionOnWriteConflict
getClient()->swapLockState(std::make_unique<LockerImpl>(opCtx->getServiceContext()));
auto&& opDebug = CurOp::get(opCtx.get())->debug();
ASSERT_EQUALS(0, opDebug.additiveMetrics.writeConflicts.load());
- ASSERT_EQUALS(100, writeConflictRetry(opCtx.get(), "", "", [&opDebug] {
+ ASSERT_EQUALS(100, writeConflictRetry(opCtx.get(), "", NamespaceString(), [&opDebug] {
if (0 == opDebug.additiveMetrics.writeConflicts.load()) {
throwWriteConflictException(
str::stream()
@@ -208,7 +208,7 @@ TEST_F(DConcurrencyTestFixture, WriteConflictRetryPropagatesNonWriteConflictExce
getClient()->swapLockState(std::make_unique<LockerImpl>(opCtx->getServiceContext()));
ASSERT_THROWS_CODE(writeConflictRetry(opCtx.get(),
"",
- "",
+ NamespaceString(),
[] {
uassert(ErrorCodes::OperationFailed, "", false);
MONGO_UNREACHABLE;
@@ -226,7 +226,7 @@ TEST_F(DConcurrencyTestFixture,
ASSERT_THROWS(writeConflictRetry(
opCtx.get(),
"",
- "",
+ NamespaceString(),
[] {
throwWriteConflictException(
str::stream() << "Verify that WriteConflictExceptions are propogated "
diff --git a/src/mongo/db/concurrency/deferred_writer.cpp b/src/mongo/db/concurrency/deferred_writer.cpp
index 558f3e282cc..a74a2723fdb 100644
--- a/src/mongo/db/concurrency/deferred_writer.cpp
+++ b/src/mongo/db/concurrency/deferred_writer.cpp
@@ -111,7 +111,7 @@ Status DeferredWriter::_worker(InsertStatement stmt) noexcept try {
const CollectionPtr& collection = agc->getCollection();
- Status status = writeConflictRetry(opCtx, "deferred insert", _nss.ns(), [&] {
+ Status status = writeConflictRetry(opCtx, "deferred insert", _nss, [&] {
WriteUnitOfWork wuow(opCtx);
Status status =
collection_internal::insertDocument(opCtx, collection, stmt, nullptr, false);
diff --git a/src/mongo/db/concurrency/exception_util.h b/src/mongo/db/concurrency/exception_util.h
index dca5b4f109e..103015d2d25 100644
--- a/src/mongo/db/concurrency/exception_util.h
+++ b/src/mongo/db/concurrency/exception_util.h
@@ -126,7 +126,10 @@ template <ErrorCodes::Error ec>
* invocation of the argument function f without any exception handling and retry logic.
*/
template <typename F>
-auto writeConflictRetry(OperationContext* opCtx, StringData opStr, StringData ns, F&& f) {
+auto writeConflictRetry(OperationContext* opCtx,
+ StringData opStr,
+ const NamespaceStringOrUUID& nssOrUUID,
+ F&& f) {
invariant(opCtx);
invariant(opCtx->lockState());
invariant(opCtx->recoveryUnit());
@@ -141,7 +144,9 @@ auto writeConflictRetry(OperationContext* opCtx, StringData opStr, StringData ns
return f();
} catch (TemporarilyUnavailableException const& e) {
if (opCtx->inMultiDocumentTransaction()) {
- handleTemporarilyUnavailableExceptionInTransaction(opCtx, opStr, ns, e);
+ // TODO SERVER-76897: use nssOrUUID.toStringForLogging().
+ handleTemporarilyUnavailableExceptionInTransaction(
+ opCtx, opStr, nssOrUUID.toStringForErrorMsg(), e);
}
throw;
}
@@ -154,13 +159,16 @@ auto writeConflictRetry(OperationContext* opCtx, StringData opStr, StringData ns
return f();
} catch (WriteConflictException const& e) {
CurOp::get(opCtx)->debug().additiveMetrics.incrementWriteConflicts(1);
- logWriteConflictAndBackoff(writeConflictAttempts, opStr, e.reason(), ns);
+ logWriteConflictAndBackoff(
+ writeConflictAttempts, opStr, e.reason(), nssOrUUID.toStringForErrorMsg());
++writeConflictAttempts;
opCtx->recoveryUnit()->abandonSnapshot();
} catch (TemporarilyUnavailableException const& e) {
- handleTemporarilyUnavailableException(opCtx, ++attemptsTempUnavailable, opStr, ns, e);
+ handleTemporarilyUnavailableException(
+ opCtx, ++attemptsTempUnavailable, opStr, nssOrUUID.toStringForErrorMsg(), e);
} catch (TransactionTooLargeForCacheException const& e) {
- handleTransactionTooLargeForCacheException(opCtx, &writeConflictAttempts, opStr, ns, e);
+ handleTransactionTooLargeForCacheException(
+ opCtx, &writeConflictAttempts, opStr, nssOrUUID.toStringForErrorMsg(), e);
}
}
}