MongoDB C++ Driver
legacy-1.1.2
|
A simple thread-safe fail point implementation that can be activated and deactivated, as well as embed temporary data into it. More...
#include <fail_point.h>
Public Member Functions | |
bool | shouldFail () |
Note: This is not side-effect free - it can change the state to OFF after calling. More... | |
RetCode | shouldFailOpenBlock () |
Checks whether fail point is active and increments the reference counter without decrementing it. More... | |
void | shouldFailCloseBlock () |
Decrements the reference counter. More... | |
void | setMode (Mode mode, ValType val=0, const BSONObj &extra=BSONObj()) |
Changes the settings of this fail point. More... | |
BSONObj | toBSON () const |
A simple thread-safe fail point implementation that can be activated and deactivated, as well as embed temporary data into it.
The fail point has a static instance, which is represented by a FailPoint object, and dynamic instance, which are all the threads in between shouldFailOpenBlock and shouldFailCloseBlock.
Sample use: // Declared somewhere: FailPoint makeBadThingsHappen;
// Somewhere in the code return false || MONGO_FAIL_POINT(makeBadThingsHappen);
or
// Somewhere in the code MONGO_FAIL_POINT_BLOCK(makeBadThingsHappen, blockMakeBadThingsHappen) { const BSONObj& data = blockMakeBadThingsHappen.getData(); // Do something }
Invariants:
Changes the settings of this fail point.
This will turn off the fail point and waits for all dynamic instances referencing this fail point to go away before actually modifying the settings.
mode | the new mode for this fail point. |
val | the value that can have different usage depending on the mode: - off, alwaysOn: ignored - random: - nTimes: the number of times this fail point will be active when #shouldFail or #shouldFailOpenBlock is called. |
extra | arbitrary BSON object that can be stored to this fail point that can be referenced afterwards with #getData. Defaults to an empty document. |
|
inline |
Note: This is not side-effect free - it can change the state to OFF after calling.
void mongo::FailPoint::shouldFailCloseBlock | ( | ) |
Decrements the reference counter.
|
inline |
Checks whether fail point is active and increments the reference counter without decrementing it.
Must call shouldFailCloseBlock afterwards when the return value is not fastOff. Otherwise, this will remain read-only forever.
BSONObj mongo::FailPoint::toBSON | ( | ) | const |