diff options
author | Benety Goh <benety@mongodb.com> | 2021-10-28 12:30:19 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-10-28 17:00:29 +0000 |
commit | 2d428795b0bf58f39f46ab75e9ec638ce8f83a17 (patch) | |
tree | f330c1e8232dfe65b328b1ff881c087150c66ce0 /src/mongo | |
parent | b584a21a0ae45e6f25660138b3fc7e6b5a2f1def (diff) | |
download | mongo-2d428795b0bf58f39f46ab75e9ec638ce8f83a17.tar.gz |
SERVER-60986 add support for context expression to wtRCToStatus()
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_util.h | 10 |
2 files changed, 12 insertions, 4 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp index 61674baea80..f682d3b0b29 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp @@ -127,19 +127,19 @@ Mutex WiredTigerUtil::_tableLoggingInfoMutex = MONGO_MAKE_LATCH("WiredTigerUtil::_tableLoggingInfoMutex"); WiredTigerUtil::TableLoggingInfo WiredTigerUtil::_tableLoggingInfo; -Status wtRCToStatus_slow(int retCode, const char* prefix) { +Status wtRCToStatus_slow(int retCode, StringData prefix) { if (retCode == 0) return Status::OK(); if (retCode == WT_ROLLBACK) { - throw WriteConflictException(); + throw WriteConflictException(prefix); } // Don't abort on WT_PANIC when repairing, as the error will be handled at a higher layer. fassert(28559, retCode != WT_PANIC || storageGlobalParams.repair); str::stream s; - if (prefix) + if (!prefix.empty()) s << prefix << " "; s << retCode << ": " << wiredtiger_strerror(retCode); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.h b/src/mongo/db/storage/wiredtiger/wiredtiger_util.h index c7097e8b508..3b7357de733 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.h @@ -46,7 +46,7 @@ class WiredTigerConfigParser; class WiredTigerKVEngine; class WiredTigerSession; -Status wtRCToStatus_slow(int retCode, const char* prefix); +Status wtRCToStatus_slow(int retCode, StringData prefix); /** * converts wiredtiger return codes to mongodb statuses. @@ -58,6 +58,14 @@ inline Status wtRCToStatus(int retCode, const char* prefix = nullptr) { return wtRCToStatus_slow(retCode, prefix); } +template <typename ContextExpr> +Status wtRCToStatus(int retCode, ContextExpr&& contextExpr) { + if (MONGO_likely(retCode == 0)) + return Status::OK(); + + return wtRCToStatus_slow(retCode, std::forward<ContextExpr>(contextExpr)()); +} + #define MONGO_invariantWTOK_1(expression) \ do { \ int _invariantWTOK_retCode = expression; \ |