mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2024-12-14 11:58:02 +00:00
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:
parent
ba641677ac
commit
14e9ba4849
3 changed files with 6 additions and 14 deletions
|
@ -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()) {
|
||||
|
|
|
@ -44,8 +44,6 @@ class ClusterConfig {
|
|||
|
||||
using ClusterShards = std::vector<ClusterShard>;
|
||||
|
||||
ClusterConfig& operator=(const ClusterConfig&) = default;
|
||||
|
||||
static SlotId KeySlot(std::string_view key);
|
||||
|
||||
static void EnableCluster() {
|
||||
|
@ -61,11 +59,11 @@ class ClusterConfig {
|
|||
|
||||
// Returns an instance with `config` if it is valid.
|
||||
// Returns heap-allocated object as it is too big for a stack frame.
|
||||
static std::unique_ptr<ClusterConfig> CreateFromConfig(std::string_view my_id,
|
||||
static std::shared_ptr<ClusterConfig> CreateFromConfig(std::string_view my_id,
|
||||
const ClusterShards& config);
|
||||
|
||||
// Parses `json_config` into `ClusterShards` and calls the above overload.
|
||||
static std::unique_ptr<ClusterConfig> CreateFromConfig(std::string_view my_id,
|
||||
static std::shared_ptr<ClusterConfig> CreateFromConfig(std::string_view my_id,
|
||||
const JsonType& json_config);
|
||||
|
||||
// If key is in my slots ownership return true
|
||||
|
|
|
@ -461,13 +461,7 @@ void ClusterFamily::DflyClusterConfig(CmdArgList args, ConnectionContext* cntx)
|
|||
before = tl_cluster_config->GetOwnedSlots();
|
||||
}
|
||||
|
||||
auto cb = [&](util::ProactorBase* pb) {
|
||||
if (tl_cluster_config == nullptr) {
|
||||
tl_cluster_config = new_config;
|
||||
} else {
|
||||
*tl_cluster_config = *new_config;
|
||||
}
|
||||
};
|
||||
auto cb = [&](util::ProactorBase* pb) { tl_cluster_config = new_config; };
|
||||
server_family_->service().proactor_pool().AwaitFiberOnAll(std::move(cb));
|
||||
|
||||
DCHECK(tl_cluster_config != nullptr);
|
||||
|
|
Loading…
Reference in a new issue