better code, add warning

This commit is contained in:
Alexander Tokmakov 2024-05-24 21:34:33 +02:00
parent 73f42b0858
commit 6725168b98
4 changed files with 13 additions and 4 deletions

View File

@ -122,6 +122,13 @@ DatabaseReplicated::DatabaseReplicated(
fillClusterAuthInfo(db_settings.collection_name.value, context_->getConfigRef()); fillClusterAuthInfo(db_settings.collection_name.value, context_->getConfigRef());
replica_group_name = context_->getConfigRef().getString("replica_group_name", ""); replica_group_name = context_->getConfigRef().getString("replica_group_name", "");
if (!replica_group_name.empty() && database_name.starts_with(DatabaseReplicated::ALL_GROUPS_CLUSTER_PREFIX))
{
context_->addWarningMessage(fmt::format("There's a Replicated database with a name starting from '{}', "
"and replica_group_name is configured. It may cause collisions in cluster names.",
ALL_GROUPS_CLUSTER_PREFIX));
}
} }
String DatabaseReplicated::getFullReplicaName(const String & shard, const String & replica) String DatabaseReplicated::getFullReplicaName(const String & shard, const String & replica)
@ -311,7 +318,7 @@ ClusterPtr DatabaseReplicated::getClusterImpl(bool all_groups) const
String cluster_name = TSA_SUPPRESS_WARNING_FOR_READ(database_name); /// FIXME String cluster_name = TSA_SUPPRESS_WARNING_FOR_READ(database_name); /// FIXME
if (all_groups) if (all_groups)
cluster_name = "all_groups." + cluster_name; cluster_name = ALL_GROUPS_CLUSTER_PREFIX + cluster_name;
ClusterConnectionParameters params{ ClusterConnectionParameters params{
cluster_auth_info.cluster_username, cluster_auth_info.cluster_username,

View File

@ -20,6 +20,8 @@ using ClusterPtr = std::shared_ptr<Cluster>;
class DatabaseReplicated : public DatabaseAtomic class DatabaseReplicated : public DatabaseAtomic
{ {
public: public:
static constexpr auto ALL_GROUPS_CLUSTER_PREFIX = "all_groups.";
DatabaseReplicated(const String & name_, const String & metadata_path_, UUID uuid, DatabaseReplicated(const String & name_, const String & metadata_path_, UUID uuid,
const String & zookeeper_path_, const String & shard_name_, const String & replica_name_, const String & zookeeper_path_, const String & shard_name_, const String & replica_name_,
DatabaseReplicatedSettings db_settings_, DatabaseReplicatedSettings db_settings_,

View File

@ -570,9 +570,9 @@ ClusterPtr tryGetReplicatedDatabaseCluster(const String & cluster_name)
{ {
String name = cluster_name; String name = cluster_name;
bool all_groups = false; bool all_groups = false;
if (name.starts_with("all_groups.")) if (name.starts_with(DatabaseReplicated::ALL_GROUPS_CLUSTER_PREFIX))
{ {
name = name.substr(strlen("all_groups.")); name = name.substr(strlen(DatabaseReplicated::ALL_GROUPS_CLUSTER_PREFIX));
all_groups = true; all_groups = true;
} }

View File

@ -56,7 +56,7 @@ void StorageSystemClusters::fillData(MutableColumns & res_columns, ContextPtr co
replicated->tryGetAreReplicasActive(database_cluster)); replicated->tryGetAreReplicasActive(database_cluster));
if (auto database_cluster = replicated->tryGetAllGroupsCluster()) if (auto database_cluster = replicated->tryGetAllGroupsCluster())
writeCluster(res_columns, {"all_groups." + name_and_database.first, database_cluster}, writeCluster(res_columns, {DatabaseReplicated::ALL_GROUPS_CLUSTER_PREFIX + name_and_database.first, database_cluster},
replicated->tryGetAreReplicasActive(database_cluster)); replicated->tryGetAreReplicasActive(database_cluster));
} }
} }