fix "incorrect replica identifier"

This commit is contained in:
Alexander Tokmakov 2022-08-18 16:13:27 +02:00
parent e2c1d06032
commit 629690c32b
4 changed files with 23 additions and 18 deletions

View File

@ -126,13 +126,30 @@ std::pair<String, String> DatabaseReplicated::parseFullReplicaName(const String
return {shard, replica};
}
ClusterPtr DatabaseReplicated::getCluster() const
ClusterPtr DatabaseReplicated::tryGetCluster() const
{
std::lock_guard lock{mutex};
if (cluster)
return cluster;
cluster = getClusterImpl();
/// Database is probably not created or not initialized yet, it's ok to return nullptr
if (is_readonly)
return cluster;
try
{
/// A quick fix for stateless tests with DatabaseReplicated. Its ZK
/// node can be destroyed at any time. If another test lists
/// system.clusters to get client command line suggestions, it will
/// get an error when trying to get the info about DB from ZK.
/// Just ignore these inaccessible databases. A good example of a
/// failing test is `01526_client_start_and_exit`.
cluster = getClusterImpl();
}
catch (...)
{
tryLogCurrentException(log);
}
return cluster;
}

View File

@ -60,7 +60,7 @@ public:
const String & getZooKeeperPath() const { return zookeeper_path; }
/// Returns cluster consisting of database replicas
ClusterPtr getCluster() const;
ClusterPtr tryGetCluster() const;
void drop(ContextPtr /*context*/) override;

View File

@ -469,7 +469,7 @@ void ZooKeeperMetadataTransaction::commit()
ClusterPtr tryGetReplicatedDatabaseCluster(const String & cluster_name)
{
if (const auto * replicated_db = dynamic_cast<const DatabaseReplicated *>(DatabaseCatalog::instance().tryGetDatabase(cluster_name).get()))
return replicated_db->getCluster();
return replicated_db->tryGetCluster();
return {};
}

View File

@ -39,20 +39,8 @@ void StorageSystemClusters::fillData(MutableColumns & res_columns, ContextPtr co
{
if (const auto * replicated = typeid_cast<const DatabaseReplicated *>(name_and_database.second.get()))
{
// A quick fix for stateless tests with DatabaseReplicated. Its ZK
// node can be destroyed at any time. If another test lists
// system.clusters to get client command line suggestions, it will
// get an error when trying to get the info about DB from ZK.
// Just ignore these inaccessible databases. A good example of a
// failing test is `01526_client_start_and_exit`.
try
{
writeCluster(res_columns, {name_and_database.first, replicated->getCluster()});
}
catch (...)
{
tryLogCurrentException(__PRETTY_FUNCTION__);
}
if (auto database_cluster = replicated->tryGetCluster())
writeCluster(res_columns, {name_and_database.first, database_cluster});
}
}
}