diff options
author | Louis Williams <louis.williams@mongodb.com> | 2022-04-08 08:08:51 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-04-08 08:38:42 +0000 |
commit | 6c397f3bfd171476f348e71afca9ecdb5ea9a312 (patch) | |
tree | f1de8627479376c9d15a0634c6311ea726e12ffc /src | |
parent | 13e435912a9880d265ec400e921e8a3743b13c65 (diff) | |
download | mongo-6c397f3bfd171476f348e71afca9ecdb5ea9a312.tar.gz |
SERVER-65254 Disable TemporarilyUnavailableExceptions by default
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/catalog/README.md | 5 | ||||
-rw-r--r-- | src/mongo/db/concurrency/write_conflict_exception.idl | 8 | ||||
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp | 28 |
3 files changed, 26 insertions, 15 deletions
diff --git a/src/mongo/db/catalog/README.md b/src/mongo/db/catalog/README.md index 3a21446485d..ddb5d479da2 100644 --- a/src/mongo/db/catalog/README.md +++ b/src/mongo/db/catalog/README.md @@ -406,8 +406,9 @@ See [writeConflictRetry](https://github.com/mongodb/mongo/blob/r4.4.0/src/mongo/ ## TemporarilyUnavailableException -A TemporarilyUnavailableException may be thrown inside the server to indicate that an operation -cannot complete without blocking and must be retried. The storage engine may throw a +When the server parameter `enableTemporarilyUnavailableExceptions` is enabled (off by default), a +TemporarilyUnavailableException may be thrown inside the server to indicate that an operation cannot +complete without blocking and must be retried. The storage engine may throw a TemporarilyUnavailableException (converted to a TemporarilyUnavailable error for users) when an operation is excessively rolled-back in the storage engine due to cache pressure or any reason that would prevent the operation from completing without impacting concurrent operations. The operation diff --git a/src/mongo/db/concurrency/write_conflict_exception.idl b/src/mongo/db/concurrency/write_conflict_exception.idl index c1ec8cb57e5..fe2206cec67 100644 --- a/src/mongo/db/concurrency/write_conflict_exception.idl +++ b/src/mongo/db/concurrency/write_conflict_exception.idl @@ -36,6 +36,14 @@ server_parameters: set_at: [ startup, runtime ] cpp_varname: 'WriteConflictException::trace' + enableTemporarilyUnavailableExceptions: + description: 'Enables the use of TemporarilyUnavailableExceptions. When disabled, reverts to + throwing WriteConflictException.' + set_at: [ startup, runtime ] + cpp_varname: 'gEnableTemporarilyUnavailableExceptions' + cpp_vartype: AtomicWord<bool> + default: false + temporarilyUnavailableMaxRetries: description: 'The number of times to retry a TemporarilyUnavailable error internally' set_at: [ startup, runtime ] diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp index 3605eb90a76..de31ec10751 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp @@ -42,6 +42,7 @@ #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/concurrency/temporarily_unavailable_exception.h" #include "mongo/db/concurrency/write_conflict_exception.h" +#include "mongo/db/concurrency/write_conflict_exception_gen.h" #include "mongo/db/global_settings.h" #include "mongo/db/server_options_general_gen.h" #include "mongo/db/snapshot_window_options_gen.h" @@ -162,24 +163,25 @@ Mutex WiredTigerUtil::_tableLoggingInfoMutex = MONGO_MAKE_LATCH("WiredTigerUtil::_tableLoggingInfoMutex"); WiredTigerUtil::TableLoggingInfo WiredTigerUtil::_tableLoggingInfo; +bool wasRollbackReasonCachePressure(WT_SESSION* session) { + if (session) { + const auto reason = session->get_rollback_reason(session); + if (reason) { + return strncmp(WT_TXN_ROLLBACK_REASON_CACHE, + reason, + sizeof(WT_TXN_ROLLBACK_REASON_CACHE)) == 0; + } + } + return false; +} + Status wtRCToStatus_slow(int retCode, WT_SESSION* session, StringData prefix) { if (retCode == 0) return Status::OK(); if (retCode == WT_ROLLBACK) { - const auto reasonIsCachePressure = [&] { - if (session) { - const auto reason = session->get_rollback_reason(session); - if (reason) { - return strncmp(WT_TXN_ROLLBACK_REASON_CACHE, - reason, - sizeof(WT_TXN_ROLLBACK_REASON_CACHE)) == 0; - } - } - return false; - }(); - - if (reasonIsCachePressure) { + if (gEnableTemporarilyUnavailableExceptions.load() && + wasRollbackReasonCachePressure(session)) { str::stream s; if (!prefix.empty()) s << prefix << " "; |