Skip to content

Commit 2ea5afb

Browse files
author
lexeyo
committed
feat all: Breaking: remove autostart_at_base_component default
This PR introduces breaking API changes: 1. Removes a default from `autostart_at_base_component` parameter of the `DistLockComponentBase` .ctor. 2. Removes `AutostartDistlock::kNo` enum member and introduces a new `DistLockComponentBase` .ctor accepting `DisableAutostartAtBase` tag parameter that behaves like the original .ctor with `autostart_at_base_component == AutostartDistlock::kNo`. Thus all descendants of `DistLockComponentBase` should either pass `AutostartDistlock::kYes` or `DisableAutostartAtBase{}` to the `DistLockComponentBase`'s .ctor. `DisableAutostartAtBase{}`preserves the original behaviour (with manual distlock startup/shutdown management) while `AutostartDistlock::kYes` delegates a distlock startup/shutdown to the framework. </section> Later we are going to completely remove the `autostart_at_base_component`parameter and enable automatic management of distlock stratup/shutdown by default. commit_hash:35cd7bf4a4258b8047b1e7768c04ddc9669c5964
1 parent fd9835c commit 2ea5afb

2 files changed

Lines changed: 42 additions & 12 deletions

File tree

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

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,21 @@ namespace storages::postgres {
6363
/// @see @ref scripts/docs/en/userver/periodics.md
6464
class DistLockComponentBase : public components::ComponentBase {
6565
public:
66-
enum class AutostartDistlock : bool { kNo = false, kYes = true };
66+
// This enum is going to be completely removed.
67+
enum class AutostartDistlock : bool { kYes = true };
68+
69+
struct DisableAutostartAtBase {};
70+
71+
DistLockComponentBase(
72+
const components::ComponentConfig& component_config,
73+
const components::ComponentContext& component_context,
74+
AutostartDistlock autostart_at_base_component
75+
);
6776

6877
DistLockComponentBase(
69-
const components::ComponentConfig&,
70-
const components::ComponentContext&,
71-
AutostartDistlock autostart_at_base_component = AutostartDistlock::kNo
78+
const components::ComponentConfig& component_config,
79+
const components::ComponentContext& component_context,
80+
DisableAutostartAtBase
7281
);
7382

7483
~DistLockComponentBase() override;
@@ -119,10 +128,10 @@ class DistLockComponentBase : public components::ComponentBase {
119128
/// Override this function to provide custom testsuite handler.
120129
virtual void DoWorkTestsuite() { DoWork(); }
121130

122-
/// Must be called in ctr
131+
/// Should be called in .ctor of a derived class if autostart at base .ctor is disabled.
123132
void AutostartDistLock();
124133

125-
/// Must be called in dtr
134+
/// Should be called in .dtor of a derived class if autostart at base .ctor is disabled.
126135
void StopDistLock();
127136

128137
/// Check this method when going for the next independent processing
@@ -131,6 +140,14 @@ class DistLockComponentBase : public components::ComponentBase {
131140
bool IsCancelAdvised() const;
132141

133142
private:
143+
enum class AutostartDistlockInternal : bool { kNo = false, kYes = true };
144+
145+
DistLockComponentBase(
146+
const components::ComponentConfig& component_config,
147+
const components::ComponentContext& component_context,
148+
AutostartDistlockInternal enable_autostart_at_base
149+
);
150+
134151
bool ShouldRunOnHost(const dynamic_config::Snapshot& config) const;
135152
void OnConfigUpdate(const dynamic_config::Diff& diff);
136153

@@ -140,8 +157,7 @@ class DistLockComponentBase : public components::ComponentBase {
140157
std::unique_ptr<dist_lock::DistLockedWorker> worker_;
141158
bool autostart_;
142159
bool testsuite_enabled_{false};
143-
// temporary parameter, will be removed when all AutostartDistlock calls will be removed from the ctors
144-
AutostartDistlock autostart_at_base_component_{AutostartDistlock::kNo};
160+
AutostartDistlockInternal enable_autostart_at_base_;
145161
dist_lock::DistLockSettings default_settings_;
146162

147163
concurrent::AsyncEventSubscriberScope subscription_token_;

postgresql/src/storages/postgres/dist_lock_component_base.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ namespace storages::postgres {
2424
DistLockComponentBase::DistLockComponentBase(
2525
const components::ComponentConfig& component_config,
2626
const components::ComponentContext& component_context,
27-
AutostartDistlock autostart_at_base_component
27+
AutostartDistlockInternal enable_autostart_at_base
2828
)
2929
: components::ComponentBase(component_config, component_context),
3030
config_(component_context.FindComponent<components::DynamicConfig>().GetSource()),
3131
name_(component_config.Name()),
3232
real_host_name_(hostinfo::blocking::GetRealHostName()),
33-
autostart_at_base_component_(autostart_at_base_component)
33+
enable_autostart_at_base_(enable_autostart_at_base)
3434
{
3535
auto shard_number = component_config["shard-number"].As<size_t>(components::Postgres::kDefaultShardNumber);
3636
auto cluster =
@@ -86,7 +86,7 @@ DistLockComponentBase::DistLockComponentBase(
8686
{{"distlock_name", component_config.Name()}}
8787
);
8888

89-
const bool autostart_enabled = autostart_at_base_component_ == AutostartDistlock::kYes;
89+
const bool autostart_enabled = enable_autostart_at_base_ == AutostartDistlockInternal::kYes;
9090
if (component_config["testsuite-support"].As<bool>(autostart_enabled)) {
9191
auto& testsuite_tasks = testsuite::GetTestsuiteTasks(component_context);
9292

@@ -107,14 +107,28 @@ DistLockComponentBase::DistLockComponentBase(
107107
}
108108
}
109109

110+
DistLockComponentBase::DistLockComponentBase(
111+
const components::ComponentConfig& component_config,
112+
const components::ComponentContext& component_context,
113+
AutostartDistlock
114+
)
115+
: storages::postgres::DistLockComponentBase(component_config, component_context, AutostartDistlockInternal::kYes) {}
116+
117+
DistLockComponentBase::DistLockComponentBase(
118+
const components::ComponentConfig& component_config,
119+
const components::ComponentContext& component_context,
120+
DisableAutostartAtBase
121+
)
122+
: storages::postgres::DistLockComponentBase(component_config, component_context, AutostartDistlockInternal::kNo) {}
123+
110124
DistLockComponentBase::~DistLockComponentBase() { subscription_token_.Unsubscribe(); }
111125

112126
dist_lock::DistLockedWorker& DistLockComponentBase::GetWorker() { return *worker_; }
113127

114128
bool DistLockComponentBase::OwnsLock() const noexcept { return worker_->OwnsLock() || testsuite_enabled_; }
115129

116130
void DistLockComponentBase::AutostartDistLock() {
117-
UASSERT(autostart_at_base_component_ == AutostartDistlock::kNo);
131+
UASSERT(enable_autostart_at_base_ == AutostartDistlockInternal::kNo);
118132

119133
if (testsuite_enabled_) {
120134
return;

0 commit comments

Comments
 (0)