fix another bug in mutations

This commit is contained in:
Alexander Tokmakov 2020-10-05 22:16:28 +03:00
parent 30a18f7567
commit 418766e92b
3 changed files with 28 additions and 2 deletions

View File

@ -715,6 +715,16 @@ void ReplicatedMergeTreeQueue::updateMutations(zkutil::ZooKeeperPtr zookeeper, C
for (const String & produced_part_name : queue_entry->getVirtualPartNames())
{
auto part_info = MergeTreePartInfo::fromPartName(produced_part_name, format_version);
/// Oddly enough, getVirtualPartNames() may return _virtual_ part name.
/// Such parts do not exist and will never appear, so we should not add virtual parts to parts_to_do list.
/// Fortunately, it's easy to distinguish virtual parts from normal parts by part level.
/// See StorageReplicatedMergeTree::getFakePartCoveringAllPartsInPartition(...)
auto max_level = MergeTreePartInfo::MAX_LEVEL; /// DROP/DETACH PARTITION
auto another_max_level = std::numeric_limits<decltype(part_info.level)>::max(); /// REPLACE/MOVE PARTITION
if (part_info.level == max_level || part_info.level == another_max_level)
continue;
auto it = entry->block_numbers.find(part_info.partition_id);
if (it != entry->block_numbers.end() && it->second > part_info.getDataVersion())
mutation.parts_to_do.add(produced_part_name);

View File

@ -4092,9 +4092,12 @@ bool StorageReplicatedMergeTree::getFakePartCoveringAllPartsInPartition(const St
mutation_version = queue.getCurrentMutationVersion(partition_id, right);
}
/// REPLACE PARTITION does not decrement max_block of DROP_RANGE for unknown (probably historical) reason.
/// REPLACE PARTITION uses different max level and does not decrement max_block of DROP_RANGE for unknown (probably historical) reason.
auto max_level = std::numeric_limits<decltype(part_info.level)>::max();
if (!for_replace_partition)
{
max_level = MergeTreePartInfo::MAX_LEVEL;
/// Empty partition.
if (right == 0)
return false;
@ -4103,7 +4106,7 @@ bool StorageReplicatedMergeTree::getFakePartCoveringAllPartsInPartition(const St
}
/// Artificial high level is chosen, to make this part "covering" all parts inside.
part_info = MergeTreePartInfo(partition_id, left, right, MergeTreePartInfo::MAX_LEVEL, mutation_version);
part_info = MergeTreePartInfo(partition_id, left, right, max_level, mutation_version);
return true;
}
@ -5393,6 +5396,7 @@ void StorageReplicatedMergeTree::replacePartitionFrom(
}
/// We are almost ready to commit changes, remove fetches and merges from drop range
/// FIXME it's unsafe to remove queue entries before we actually commit REPLACE_RANGE to replication log
queue.removePartProducingOpsInRange(zookeeper, drop_range, entry);
/// Remove deduplication block_ids of replacing parts

View File

@ -22,5 +22,17 @@ alter table rmt drop column s;
select mutation_id, command, parts_to_do_names, parts_to_do, is_done from system.mutations where database=currentDatabase() and table='rmt';
select * from rmt;
drop table rmt sync;
set replication_alter_partitions_sync=0;
create table rmt (n UInt64, s String) engine = ReplicatedMergeTree('/clickhouse/test_01149/rmt', 'r1') partition by intDiv(n, 10) order by n;
insert into rmt values (1,'1'), (2, '2');
alter table rmt update s = 's'||toString(n) where 1;
alter table rmt drop partition '0';
set replication_alter_partitions_sync=1;
alter table rmt drop column s;
drop table mt;
drop table rmt sync;