mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
SERVER-48171 FailPoint wait functions accept Interruptible
This commit is contained in:
parent
2787a803ac
commit
e9d23f4045
@ -115,11 +115,11 @@ auto FailPoint::waitForTimesEntered(EntryCountT targetTimesEntered) const noexce
|
||||
return timesEntered;
|
||||
}
|
||||
|
||||
auto FailPoint::waitForTimesEntered(OperationContext* opCtx, EntryCountT targetTimesEntered) const
|
||||
-> EntryCountT {
|
||||
auto FailPoint::waitForTimesEntered(Interruptible* interruptible,
|
||||
EntryCountT targetTimesEntered) const -> EntryCountT {
|
||||
auto timesEntered = _timesEntered.load();
|
||||
for (; timesEntered < targetTimesEntered; timesEntered = _timesEntered.load()) {
|
||||
opCtx->sleepFor(kWaitGranularity);
|
||||
interruptible->sleepFor(kWaitGranularity);
|
||||
};
|
||||
return timesEntered;
|
||||
}
|
||||
|
@ -35,11 +35,11 @@
|
||||
#include "mongo/base/status.h"
|
||||
#include "mongo/base/status_with.h"
|
||||
#include "mongo/db/jsobj.h"
|
||||
#include "mongo/db/operation_context.h"
|
||||
#include "mongo/platform/atomic_word.h"
|
||||
#include "mongo/platform/mutex.h"
|
||||
#include "mongo/stdx/unordered_map.h"
|
||||
#include "mongo/util/duration.h"
|
||||
#include "mongo/util/interruptible.h"
|
||||
|
||||
namespace mongo {
|
||||
|
||||
@ -272,11 +272,11 @@ public:
|
||||
EntryCountT waitForTimesEntered(EntryCountT targetTimesEntered) const noexcept;
|
||||
|
||||
/**
|
||||
* Like `waitForTimesEntered`, but interruptible via the `opCtx->sleepFor` mechanism. See
|
||||
* `mongo::Interruptible::sleepFor` (Interruptible is a base class of
|
||||
* OperationContext).
|
||||
* Like `waitForTimesEntered`, but interruptible via the `interruptible->sleepFor` mechanism.
|
||||
* See `mongo::Interruptible::sleepFor`.
|
||||
*/
|
||||
EntryCountT waitForTimesEntered(OperationContext* opCtx, EntryCountT targetTimesEntered) const;
|
||||
EntryCountT waitForTimesEntered(Interruptible* interruptible,
|
||||
EntryCountT targetTimesEntered) const;
|
||||
|
||||
/**
|
||||
* @returns a BSON object showing the current mode and data stored.
|
||||
@ -338,14 +338,13 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
* Like `pauseWhileSet`, but interruptible via the `opCtx->sleepFor` mechanism. See
|
||||
* `mongo::Interruptible::sleepFor` (Interruptible is a base class of
|
||||
* OperationContext).
|
||||
* Like `pauseWhileSet`, but interruptible via the `interruptible->sleepFor` mechanism. See
|
||||
* `mongo::Interruptible::sleepFor`.
|
||||
*/
|
||||
void pauseWhileSet(OperationContext* opCtx) {
|
||||
void pauseWhileSet(Interruptible* interruptible) {
|
||||
for (auto entryMode = kFirstTimeEntered; MONGO_unlikely(shouldFail(entryMode));
|
||||
entryMode = kEnteredAlready) {
|
||||
opCtx->sleepFor(Milliseconds(100));
|
||||
interruptible->sleepFor(Milliseconds(100));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -441,9 +441,9 @@ namespace mongo {
|
||||
|
||||
/**
|
||||
* Runs the given function with an operation context that has a deadline and asserts that
|
||||
* the function is interruptable.
|
||||
* the function is interruptible.
|
||||
*/
|
||||
void assertFunctionInterruptable(std::function<void(OperationContext* opCtx)> f) {
|
||||
void assertFunctionInterruptable(std::function<void(Interruptible* interruptible)> f) {
|
||||
const auto service = ServiceContext::make();
|
||||
const std::shared_ptr<ClockSourceMock> mockClock = std::make_shared<ClockSourceMock>();
|
||||
service->setFastClockSource(std::make_unique<SharedClockSourceAdapter>(mockClock));
|
||||
@ -467,7 +467,7 @@ TEST(FailPoint, PauseWhileSetInterruptibility) {
|
||||
failPoint.setMode(FailPoint::alwaysOn);
|
||||
|
||||
assertFunctionInterruptable(
|
||||
[&failPoint](OperationContext* opCtx) { failPoint.pauseWhileSet(opCtx); });
|
||||
[&failPoint](Interruptible* interruptible) { failPoint.pauseWhileSet(interruptible); });
|
||||
|
||||
failPoint.setMode(FailPoint::off);
|
||||
}
|
||||
@ -476,8 +476,9 @@ TEST(FailPoint, WaitForFailPointTimeout) {
|
||||
FailPoint failPoint;
|
||||
failPoint.setMode(FailPoint::alwaysOn);
|
||||
|
||||
assertFunctionInterruptable(
|
||||
[&failPoint](OperationContext* opCtx) { failPoint.waitForTimesEntered(opCtx, 1); });
|
||||
assertFunctionInterruptable([&failPoint](Interruptible* interruptible) {
|
||||
failPoint.waitForTimesEntered(interruptible, 1);
|
||||
});
|
||||
|
||||
failPoint.setMode(FailPoint::off);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user