Skip to content

Commit 84f5bc6

Browse files
author
lexeyo
committed
feat all: Breaking: new DistLockComponentBase .ctor that enables automatic distlock startup and shutdown
This PR changes the `DistLockComponentBase` behaviour and could break the existing code relying on it. The initial API required manual distlock startup/shutdown via `AutostartDistlock()`/`StopDistlock()` calls in a derived class .ctor/.dtor. Now the distlock startup and shutdown are managed by the framework. So, `AutostartDistlock()`/`StopDistlock()`calls should be removed from derived classes. Or `DisableAutostartAtBase{}` should be passed to the `DistLockComponentBase` .ctor to preserve the old behaviour. commit_hash:e9114d91866007a17f05b476be4fc39d03dfa4c1
1 parent 868e14a commit 84f5bc6

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

postgresql/include/userver/storages/postgres/dist_lock_component_base.hpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ namespace storages::postgres {
1919
///
2020
/// A component that implements a distlock with lock in Postgres. Inherit from
2121
/// DistLockComponentBase and implement DoWork(). Lock options are configured
22-
/// in static config.
22+
/// in static config. To customize a distlock for testsuite override DoWorkTestsuite().
23+
///
24+
/// By default the distlock is started and stopped automatically by the framework
25+
/// in all environments except testsuite. If manual control over the distlock startup
26+
/// and shutdown is needed pass DisableAutostartAtBase{} to the DistLockComponentBase .ctor.
2327
///
2428
/// The class must be used for infinite loop jobs. If you want a distributed
2529
/// periodic, you should look at locked_periodiccomponents::PgLockedPeriodic.
@@ -68,12 +72,21 @@ class DistLockComponentBase : public components::ComponentBase {
6872

6973
struct DisableAutostartAtBase {};
7074

75+
// This .ctor is going to be completely removed.
7176
DistLockComponentBase(
7277
const components::ComponentConfig& component_config,
7378
const components::ComponentContext& component_context,
7479
AutostartDistlock autostart_at_base_component
7580
);
7681

82+
/// @brief Constructs the distlock base and enables automatic startup and shutdown of the distlock.
83+
DistLockComponentBase(
84+
const components::ComponentConfig& component_config,
85+
const components::ComponentContext& component_context
86+
);
87+
88+
/// @brief Constructs the distlock base and disables automatic startup and shutdown of the distlock.
89+
/// The dislock should be started and stopped manually via AutostartDistlock() and StopDistLock() calls.
7790
DistLockComponentBase(
7891
const components::ComponentConfig& component_config,
7992
const components::ComponentContext& component_context,
@@ -128,10 +141,12 @@ class DistLockComponentBase : public components::ComponentBase {
128141
/// Override this function to provide custom testsuite handler.
129142
virtual void DoWorkTestsuite() { DoWork(); }
130143

131-
/// Should be called in .ctor of a derived class if autostart at base .ctor is disabled.
144+
/// Should be called in a .ctor of a derived class iff DisableAutostartAtBase{}
145+
/// has been passed to the DistLockComponentBase .ctor.
132146
void AutostartDistLock();
133147

134-
/// Should be called in .dtor of a derived class if autostart at base .ctor is disabled.
148+
/// Should be called in a .dtor of a derived class iff DisableAutostartAtBase{}
149+
/// has been passed to the DistLockComponentBase .ctor.
135150
void StopDistLock();
136151

137152
/// Check this method when going for the next independent processing

postgresql/src/storages/postgres/dist_lock_component_base.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ DistLockComponentBase::DistLockComponentBase(
111111
const components::ComponentConfig& component_config,
112112
const components::ComponentContext& component_context,
113113
AutostartDistlock
114+
)
115+
: storages::postgres::DistLockComponentBase(component_config, component_context) {}
116+
117+
DistLockComponentBase::DistLockComponentBase(
118+
const components::ComponentConfig& component_config,
119+
const components::ComponentContext& component_context
114120
)
115121
: storages::postgres::DistLockComponentBase(component_config, component_context, AutostartDistlockInternal::kYes) {}
116122

0 commit comments

Comments
 (0)