summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2014-11-20 14:22:05 -0500
committerMathias Stearn <mathias@10gen.com>2014-11-21 14:11:43 -0500
commit8e0e873320a0962460c7a8e821495a325efe176b (patch)
tree4975c29637e2950e8d006c7e099391c546377daf /src
parentf56ea73672e1eebde4d2e9cef2f8fca0d84f0956 (diff)
downloadmongo-8e0e873320a0962460c7a8e821495a325efe176b.tar.gz
SERVER-16254 Add invariantOK and improve invariantWTOK
Diffstat (limited to 'src')
-rw-r--r--src/mongo/client/redef_macros.h3
-rw-r--r--src/mongo/client/undef_macros.h2
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_util.h13
-rw-r--r--src/mongo/util/assert_util.cpp9
-rw-r--r--src/mongo/util/assert_util.h13
5 files changed, 32 insertions, 8 deletions
diff --git a/src/mongo/client/redef_macros.h b/src/mongo/client/redef_macros.h
index 70eb992ff12..8a4f5ffe4cb 100644
--- a/src/mongo/client/redef_macros.h
+++ b/src/mongo/client/redef_macros.h
@@ -41,6 +41,9 @@
#pragma push_macro("invariant")
#undef invariant
#define invariant MONGO_invariant
+#pragma push_macro("invariantOK")
+#undef invariantOK
+#define invariantOK MONGO_invariantOK
#pragma push_macro("dassert")
#undef dassert
#define dassert MONGO_dassert
diff --git a/src/mongo/client/undef_macros.h b/src/mongo/client/undef_macros.h
index cf5350989db..4a395d73508 100644
--- a/src/mongo/client/undef_macros.h
+++ b/src/mongo/client/undef_macros.h
@@ -46,6 +46,8 @@
#pragma pop_macro("verify")
#undef invariant
#pragma pop_macro("invariant")
+#undef invariantOK
+#pragma pop_macro("invariantOK")
#undef DESTRUCTOR_GUARD
#pragma pop_macro("DESTRUCTOR_GUARD")
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.h b/src/mongo/db/storage/wiredtiger/wiredtiger_util.h
index 4401d52ac0c..d8abf27b732 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.h
@@ -75,12 +75,13 @@ namespace mongo {
return Status(ErrorCodes::UnknownError, s);
}
- inline void invariantWTOK(int retCode) {
- if (MONGO_likely(retCode == 0))
- return;
-
- fassertFailedWithStatus(28519, wtRCToStatus(retCode));
- }
+#define invariantWTOK(expression) do { \
+ int _invariantWTOK_retCode = expression; \
+ if (MONGO_unlikely(_invariantWTOK_retCode != 0)) { \
+ invariantOKFailed(#expression, wtRCToStatus(_invariantWTOK_retCode), \
+ __FILE__, __LINE__); \
+ } \
+ } while (false)
struct WiredTigerItem : public WT_ITEM {
WiredTigerItem(const void *d, size_t s) {
diff --git a/src/mongo/util/assert_util.cpp b/src/mongo/util/assert_util.cpp
index 7133dec63bb..ac84e99a539 100644
--- a/src/mongo/util/assert_util.cpp
+++ b/src/mongo/util/assert_util.cpp
@@ -147,6 +147,15 @@ namespace mongo {
abort();
}
+ NOINLINE_DECL void invariantOKFailed(const char *msg, const Status& status, const char *file,
+ unsigned line) {
+ log() << "Invariant failure " << msg << ' ' << status << ' ' << file << ' ' << dec << line;
+ logContext();
+ breakpoint();
+ log() << "\n\n***aborting after invariant() failure\n\n" << endl;
+ abort();
+ }
+
NOINLINE_DECL void fassertFailed( int msgid ) {
log() << "Fatal Assertion " << msgid << endl;
logContext();
diff --git a/src/mongo/util/assert_util.h b/src/mongo/util/assert_util.h
index a2a343c92c3..50d57da669b 100644
--- a/src/mongo/util/assert_util.h
+++ b/src/mongo/util/assert_util.h
@@ -179,6 +179,7 @@ namespace mongo {
MONGO_CLIENT_API MONGO_COMPILER_NORETURN void verifyFailed(const char *msg, const char *file, unsigned line);
MONGO_CLIENT_API MONGO_COMPILER_NORETURN void invariantFailed(const char *msg, const char *file, unsigned line);
+ MONGO_CLIENT_API MONGO_COMPILER_NORETURN void invariantOKFailed(const char *msg, const Status& status, const char *file, unsigned line);
MONGO_CLIENT_API void wasserted(const char *msg, const char *file, unsigned line);
MONGO_CLIENT_API MONGO_COMPILER_NORETURN void fassertFailed( int msgid );
MONGO_CLIENT_API MONGO_COMPILER_NORETURN void fassertFailedNoTrace( int msgid );
@@ -267,17 +268,24 @@ namespace mongo {
/* same as massert except no msgid */
#define MONGO_verify(_Expression) do { \
- if (MONGO_unlikely(!(_Expression))) { \
+ if (MONGO_unlikely(!(_Expression))) { \
::mongo::verifyFailed(#_Expression, __FILE__, __LINE__); \
} \
} while (false)
#define MONGO_invariant(_Expression) do { \
- if (MONGO_unlikely(!(_Expression))) { \
+ if (MONGO_unlikely(!(_Expression))) { \
::mongo::invariantFailed(#_Expression, __FILE__, __LINE__); \
} \
} while (false)
+#define MONGO_invariantOK(expression) do { \
+ const ::mongo::Status _invariantOK_status = expression; \
+ if (MONGO_unlikely(!_invariantOK_status.isOK())) { \
+ ::mongo::invariantOKFailed(#expression, _invariantOK_status, __FILE__, __LINE__); \
+ } \
+ } while (false)
+
/* dassert is 'debug assert' -- might want to turn off for production as these
could be slow.
*/
@@ -291,6 +299,7 @@ namespace mongo {
# define dassert MONGO_dassert
# define verify MONGO_verify
# define invariant MONGO_invariant
+# define invariantOK MONGO_invariantOK
# define uassert MONGO_uassert
# define wassert MONGO_wassert
# define massert MONGO_massert