Override this function to provide custom testsuite handler.
void
Start ()
Must be called in constructor.
void
Stop ()
Must be called in destructor.
Detailed Description
Base class for mongo-based distlock worker components.
A component that implements a distlock with lock in Mongo. Inherit from DistLockComponentBase and implement DoWork(). Lock options are configured in static config.
Override this function with anything that must be done under the mongo lock.
Example implementation
void MyDistLockComponent::DoWork()
{
while (!engine::ShouldCancel())
{
// If Foo() or other function in DoWork() throws an exception,
// DoWork() will be restarted in `restart-delay` seconds.
Foo();
// Check for cancellation after cpu-intensive Foo().
// You must check for cancellation at least every `lock-ttl`
// seconds to have time to notice lock prolongation failure.
if (engine::ShouldCancel()) break;
Bar();
}
}
Note
DoWork must honour task cancellation and stop ASAP when it is cancelled, otherwise brain split is possible (IOW, two different users do work assuming both of them hold the lock, which is not true).