Merge pull request #60883 from ClickHouse/uuid

Fix race in refreshable materialized views causing SELECT to fail sometimes
This commit is contained in:
Alexey Milovidov 2024-05-20 06:02:46 +02:00 committed by GitHub
commit 6c51b771c5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 2 deletions

View File

@ -193,6 +193,7 @@ StorageMaterializedView::StorageMaterializedView(
if (query.refresh_strategy)
{
fixed_uuid = false;
refresher = RefreshTask::create(
*this,
getContext(),
@ -687,10 +688,14 @@ void StorageMaterializedView::onActionLockRemove(StorageActionBlockType action_t
refresher->start();
}
DB::StorageID StorageMaterializedView::getTargetTableId() const
StorageID StorageMaterializedView::getTargetTableId() const
{
std::lock_guard guard(target_table_id_mutex);
return target_table_id;
auto id = target_table_id;
/// TODO: Avoid putting uuid into target_table_id in the first place, instead of clearing it here.
if (!fixed_uuid)
id.uuid = UUIDHelpers::Nil;
return id;
}
void StorageMaterializedView::setTargetTableId(DB::StorageID id)

View File

@ -110,6 +110,10 @@ private:
bool has_inner_table = false;
/// If false, inner table is replaced on each refresh. In that case, target_table_id doesn't
/// have UUID, and we do inner table lookup by name instead.
bool fixed_uuid = true;
friend class RefreshTask;
void checkStatementCanBeForwarded() const;