void FailPoint::setMode(Mode mode, ValType val, const BSONObj& extra) { /** * Outline: * * 1. Deactivates fail point to enter write-only mode * 2. Waits for all current readers of the fail point to finish * 3. Sets the new mode. */ stdx::lock_guard<stdx::mutex> scoped(_modMutex); // Step 1 disableFailPoint(); // Step 2 while (_fpInfo.load() != 0) { sleepmillis(50); } _mode = mode; _timesOrPeriod.store(val); _data = extra.copy(); if (_mode != off) { enableFailPoint(); } }
void FailPoint::setMode(Mode mode, ValType val, const BSONObj& extra) { /** * Outline: * * 1. Deactivates fail point to enter write-only mode * 2. Waits for all current readers of the fail point to finish * 3. Sets the new mode. */ scoped_lock scoped(_modMutex); // Step 1 disableFailPoint(); // Step 2 while (_fpInfo.load() != 0) { sleepmillis(50); } // Step 3 uassert(16442, stream() << "mode not supported " << static_cast<int>(mode), mode >= off && mode < numModes); _mode = mode; _timesOrPeriod.store(val); _data = extra.copy(); if (_mode != off) { enableFailPoint(); } }
FailPoint::RetCode FailPoint::slowShouldFailOpenBlock() { ValType localFpInfo = _fpInfo.addAndFetch(1); if ((localFpInfo & ACTIVE_BIT) == 0) { return slowOff; } switch (_mode) { case alwaysOn: return slowOn; case random: { const AtomicInt32::WordType maxActivationValue = _timesOrPeriod.load(); if (prngNextPositiveInt32() < maxActivationValue) { return slowOn; } return slowOff; } case nTimes: { AtomicInt32::WordType newVal = _timesOrPeriod.subtractAndFetch(1); if (newVal <= 0) { disableFailPoint(); } return slowOn; } default: error() << "FailPoint Mode not supported: " << static_cast<int>(_mode); fassertFailed(16444); } }
FailPoint::RetCode FailPoint::slowShouldFailOpenBlock() { ValType localFpInfo = _fpInfo.addAndFetch(1); if ((localFpInfo & ACTIVE_BIT) == 0) { return slowOff; } switch (_mode) { case alwaysOn: return slowOn; case random: // TODO: randomly determine if should be active or not error() << "FailPoint Mode random is not yet supported." << endl; fassertFailed(16443); case nTimes: { AtomicInt32::WordType newVal = _timesOrPeriod.subtractAndFetch(1); if (newVal <= 0) { disableFailPoint(); } return slowOn; } default: error() << "FailPoint Mode not supported: " << static_cast<int>(_mode) << endl; fassertFailed(16444); } }