fix(cluster): Fix race when setting cluster config (#1428)

* fix(cluster): Fix race when setting cluster config

* Return `shared_ptr` from Create factory function.
This commit is contained in:
Chaka 2023-06-19 11:24:26 +03:00 committed by GitHub
parent ba641677ac
commit 14e9ba4849
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 14 deletions

View file

@ -103,13 +103,13 @@ bool IsConfigValid(const ClusterConfig::ClusterShards& new_config) {
} // namespace
/* static */
unique_ptr<ClusterConfig> ClusterConfig::CreateFromConfig(string_view my_id,
shared_ptr<ClusterConfig> ClusterConfig::CreateFromConfig(string_view my_id,
const ClusterShards& config) {
if (!IsConfigValid(config)) {
return nullptr;
}
unique_ptr<ClusterConfig> result(new ClusterConfig());
shared_ptr<ClusterConfig> result(new ClusterConfig());
result->config_ = config;
@ -254,7 +254,7 @@ optional<ClusterConfig::ClusterShards> BuildClusterConfigFromJson(const JsonType
} // namespace
/* static */
unique_ptr<ClusterConfig> ClusterConfig::CreateFromConfig(string_view my_id,
shared_ptr<ClusterConfig> ClusterConfig::CreateFromConfig(string_view my_id,
const JsonType& json_config) {
optional<ClusterShards> config = BuildClusterConfigFromJson(json_config);
if (!config.has_value()) {