diff --git a/src/config.rs b/src/config.rs index 7f49b83b5f1c5859f48eaf8b267feec0e349fee7..f0f012bae7a06d72e90dc04850a9608e5012a68f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -772,18 +772,20 @@ pub struct ClusterConfig { impl ClusterConfig { pub fn tiers(&self) -> HashMap<String, Tier> { - if self.tiers.is_empty() { - return HashMap::from([( - DEFAULT_TIER.to_string(), + let mut tier_defs = HashMap::with_capacity(self.tiers.len()); + + let contains_default_tier_definition = self.tiers.get(DEFAULT_TIER).is_some(); + if !contains_default_tier_definition { + tier_defs.insert( + DEFAULT_TIER.into(), Tier { name: DEFAULT_TIER.into(), replication_factor: self.default_replication_factor(), can_vote: true, }, - )]); + ); } - let mut tier_defs = HashMap::with_capacity(self.tiers.len()); for (name, info) in &self.tiers { let replication_factor = info .replication_factor diff --git a/test/int/test_config_file.py b/test/int/test_config_file.py index e17b75e2437eb69e762868bda8bb5e78360be06d..698759f2d3b61bb4725cc2c71dbfe4aa7e5c5509 100644 --- a/test/int/test_config_file.py +++ b/test/int/test_config_file.py @@ -401,3 +401,42 @@ def test_picodata_default_config(cluster: Cluster): i.start() i.wait_online() + + +def test_default_tier_without_default_replication_factor(cluster: Cluster): + # default tier wasn't created only in case of explicit configuration file + cluster.set_config_file( + yaml=""" +cluster: + cluster_id: test + tiers: + not_default: +""" + ) + + instance = cluster.add_instance() + + dql = instance.sudo_sql( + 'select "replication_factor" from "_pico_tier" where "name" = \'default\'' + ) + assert dql["rows"][0][0] == 1 + + +def test_default_tier_with_default_replication_factor(cluster: Cluster): + # default tier wasn't created only in case of explicit configuration file + cluster.set_config_file( + yaml=""" +cluster: + default_replication_factor: 3 + cluster_id: test + tiers: + not_default: +""" + ) + + instance = cluster.add_instance() + + dql = instance.sudo_sql( + 'select "replication_factor" from "_pico_tier" where "name" = \'default\'' + ) + assert dql["rows"][0][0] == 3