diff --git a/src/Storages/StorageReplicatedMergeTree.cpp b/src/Storages/StorageReplicatedMergeTree.cpp index a04ec5c6532..ee4abb38c10 100644 --- a/src/Storages/StorageReplicatedMergeTree.cpp +++ b/src/Storages/StorageReplicatedMergeTree.cpp @@ -7428,14 +7428,18 @@ bool StorageReplicatedMergeTree::createEmptyPartInsteadOfLost(zkutil::ZooKeeperP new_data_part->setColumns(columns); new_data_part->rows_count = block.rows(); - auto parts_in_partition = getDataPartsPartitionRange(new_part_info.partition_id); - if (parts_in_partition.empty()) { - LOG_WARNING(log, "Empty part {} is not created instead of lost part because there are no parts in partition {} (it's empty), resolve this manually using DROP PARTITION.", lost_part_name, new_part_info.partition_id); - return false; + auto lock = lockParts(); + auto parts_in_partition = getDataPartsPartitionRange(new_part_info.partition_id); + if (parts_in_partition.empty()) + { + LOG_WARNING(log, "Empty part {} is not created instead of lost part because there are no parts in partition {} (it's empty), resolve this manually using DROP PARTITION.", lost_part_name, new_part_info.partition_id); + return false; + } + + new_data_part->partition = (*parts_in_partition.begin())->partition; } - new_data_part->partition = (*parts_in_partition.begin())->partition; new_data_part->minmax_idx = std::move(minmax_idx); new_data_part->is_temp = true;