Override this function to provide custom testsuite handler.
void
AutostartDistLock ()
Must be called in ctr.
void
StopDistLock ()
Must be called in dtr.
Detailed Description
Base class for postgres-based distlock worker components.
A component that implements a distlock with lock in Postgres. Inherit from DistLockComponentBase and implement DoWork(). Lock options are configured in static config.
The class must be used for infinite loop jobs. If you want a distributed periodic, you should look at locked_periodiccomponents::PgLockedPeriodic.
Override this function with anything that must be done under the pg 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).