summaryrefslogtreecommitdiff
path: root/src/mongo/util/fail_point.cpp
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2018-05-15 14:19:45 -0400
committerJason Carey <jcarey@argv.me>2018-05-16 15:09:15 -0400
commit066b3749d946e435c7b8d95f0b7cd0d71903c0bc (patch)
treece13ce0ed6d420c9dd5f8523cf438e3d727429b4 /src/mongo/util/fail_point.cpp
parenta2774d00b637d178ed593abd212b0f8e7ee38669 (diff)
downloadmongo-066b3749d946e435c7b8d95f0b7cd0d71903c0bc.tar.gz
SERVER-34960 Add MONGO_FAIL_POINT_BLOCK_IF
It's sometimes useful to be able to check a pre-condition on a fail point without manipulating the fail point state (decrementing nTimes for instance). Adding a callable to shouldFailOpenBlock and shouldFail, and threading that through a new block macro MONGO_FAIL_POINT_BLOCK_IF, allows for observation of the fail point payload and a chance to abort without extra overhead if the fail point is disabled.
Diffstat (limited to 'src/mongo/util/fail_point.cpp')
-rw-r--r--src/mongo/util/fail_point.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/mongo/util/fail_point.cpp b/src/mongo/util/fail_point.cpp
index 75be5f48231..4ba84bee3ec 100644
--- a/src/mongo/util/fail_point.cpp
+++ b/src/mongo/util/fail_point.cpp
@@ -141,13 +141,18 @@ void FailPoint::disableFailPoint() {
} while (expectedCurrentVal != currentVal);
}
-FailPoint::RetCode FailPoint::slowShouldFailOpenBlock() {
+FailPoint::RetCode FailPoint::slowShouldFailOpenBlock(
+ stdx::function<bool(const BSONObj&)> cb) noexcept {
ValType localFpInfo = _fpInfo.addAndFetch(1);
if ((localFpInfo & ACTIVE_BIT) == 0) {
return slowOff;
}
+ if (cb && !cb(getData())) {
+ return userIgnored;
+ }
+
switch (_mode) {
case alwaysOn:
return slowOn;