diff options
-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; \ |