Skip to content

Commit 68767e2

Browse files
author
lexeyo
committed
refactor postgres: completely remove public AutostartDistlock enum
Completely removes the `DistLockComponentBase::AutostartDistlock` public enum and finalizes a series of refactorings, replacing manual distlock startup/shutdown management with an automated solution. commit_hash:d8ac7fdf0e4f5a897071178035568c78342bb80d
1 parent 4728a1e commit 68767e2

2 files changed

Lines changed: 8 additions & 25 deletions

File tree

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

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,8 @@ namespace storages::postgres {
6767
/// @see @ref scripts/docs/en/userver/periodics.md
6868
class DistLockComponentBase : public components::ComponentBase {
6969
public:
70-
// This enum is going to be completely removed.
71-
enum class AutostartDistlock : bool { kYes = true };
72-
7370
struct DisableAutostartAtBase {};
7471

75-
// This .ctor is going to be completely removed.
76-
DistLockComponentBase(
77-
const components::ComponentConfig& component_config,
78-
const components::ComponentContext& component_context,
79-
AutostartDistlock autostart_at_base_component
80-
);
81-
8272
/// @brief Constructs the distlock base and enables automatic startup and shutdown of the distlock.
8373
DistLockComponentBase(
8474
const components::ComponentConfig& component_config,
@@ -155,12 +145,12 @@ class DistLockComponentBase : public components::ComponentBase {
155145
bool IsCancelAdvised() const;
156146

157147
private:
158-
enum class AutostartDistlockInternal : bool { kNo = false, kYes = true };
148+
enum class AutostartDistlock : bool { kNo = false, kYes = true };
159149

160150
DistLockComponentBase(
161151
const components::ComponentConfig& component_config,
162152
const components::ComponentContext& component_context,
163-
AutostartDistlockInternal enable_autostart_at_base
153+
AutostartDistlock enable_autostart_at_base
164154
);
165155

166156
bool ShouldRunOnHost(const dynamic_config::Snapshot& config) const;
@@ -172,7 +162,7 @@ class DistLockComponentBase : public components::ComponentBase {
172162
std::unique_ptr<dist_lock::DistLockedWorker> worker_;
173163
bool autostart_;
174164
bool testsuite_enabled_{false};
175-
AutostartDistlockInternal enable_autostart_at_base_;
165+
AutostartDistlock enable_autostart_at_base_;
176166
dist_lock::DistLockSettings default_settings_;
177167

178168
concurrent::AsyncEventSubscriberScope subscription_token_;

postgresql/src/storages/postgres/dist_lock_component_base.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace storages::postgres {
2424
DistLockComponentBase::DistLockComponentBase(
2525
const components::ComponentConfig& component_config,
2626
const components::ComponentContext& component_context,
27-
AutostartDistlockInternal enable_autostart_at_base
27+
AutostartDistlock enable_autostart_at_base
2828
)
2929
: components::ComponentBase(component_config, component_context),
3030
config_(component_context.FindComponent<components::DynamicConfig>().GetSource()),
@@ -86,7 +86,7 @@ DistLockComponentBase::DistLockComponentBase(
8686
{{"distlock_name", component_config.Name()}}
8787
);
8888

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

@@ -107,25 +107,18 @@ 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) {}
116-
117110
DistLockComponentBase::DistLockComponentBase(
118111
const components::ComponentConfig& component_config,
119112
const components::ComponentContext& component_context
120113
)
121-
: storages::postgres::DistLockComponentBase(component_config, component_context, AutostartDistlockInternal::kYes) {}
114+
: storages::postgres::DistLockComponentBase(component_config, component_context, AutostartDistlock::kYes) {}
122115

123116
DistLockComponentBase::DistLockComponentBase(
124117
const components::ComponentConfig& component_config,
125118
const components::ComponentContext& component_context,
126119
DisableAutostartAtBase
127120
)
128-
: storages::postgres::DistLockComponentBase(component_config, component_context, AutostartDistlockInternal::kNo) {}
121+
: storages::postgres::DistLockComponentBase(component_config, component_context, AutostartDistlock::kNo) {}
129122

130123
DistLockComponentBase::~DistLockComponentBase() { subscription_token_.Unsubscribe(); }
131124

@@ -134,7 +127,7 @@ dist_lock::DistLockedWorker& DistLockComponentBase::GetWorker() { return *worker
134127
bool DistLockComponentBase::OwnsLock() const noexcept { return worker_->OwnsLock() || testsuite_enabled_; }
135128

136129
void DistLockComponentBase::AutostartDistLock() {
137-
UASSERT(enable_autostart_at_base_ == AutostartDistlockInternal::kNo);
130+
UASSERT(enable_autostart_at_base_ == AutostartDistlock::kNo);
138131

139132
if (testsuite_enabled_) {
140133
return;

0 commit comments

Comments
 (0)