basic implementation

This commit is contained in:
priera 2023-08-22 14:47:57 +02:00
parent e6fb5a21cb
commit fd51839b97
3 changed files with 19 additions and 1 deletions

View File

@ -7568,6 +7568,7 @@ void StorageReplicatedMergeTree::replacePartitionFrom(
String drop_range_fake_part_name = getPartNamePossiblyFake(format_version, drop_range); String drop_range_fake_part_name = getPartNamePossiblyFake(format_version, drop_range);
std::set<String> replaced_parts;
for (const auto & src_part : src_all_parts) for (const auto & src_part : src_all_parts)
{ {
/// We also make some kind of deduplication to avoid duplicated parts in case of ATTACH PARTITION /// We also make some kind of deduplication to avoid duplicated parts in case of ATTACH PARTITION
@ -7580,13 +7581,15 @@ void StorageReplicatedMergeTree::replacePartitionFrom(
"' has inconsistent granularity with table", partition_id, src_part->name); "' has inconsistent granularity with table", partition_id, src_part->name);
String hash_hex = src_part->checksums.getTotalChecksumHex(); String hash_hex = src_part->checksums.getTotalChecksumHex();
const bool is_duplicated_part = replaced_parts.contains(hash_hex);
replaced_parts.insert(hash_hex);
if (replace) if (replace)
LOG_INFO(log, "Trying to replace {} with hash_hex {}", src_part->name, hash_hex); LOG_INFO(log, "Trying to replace {} with hash_hex {}", src_part->name, hash_hex);
else else
LOG_INFO(log, "Trying to attach {} with hash_hex {}", src_part->name, hash_hex); LOG_INFO(log, "Trying to attach {} with hash_hex {}", src_part->name, hash_hex);
String block_id_path = replace ? "" : (fs::path(zookeeper_path) / "blocks" / (partition_id + "_replace_from_" + hash_hex)); String block_id_path = (replace || is_duplicated_part) ? "" : (fs::path(zookeeper_path) / "blocks" / (partition_id + "_replace_from_" + hash_hex));
auto lock = allocateBlockNumber(partition_id, zookeeper, block_id_path); auto lock = allocateBlockNumber(partition_id, zookeeper, block_id_path);
if (!lock) if (!lock)

View File

@ -9,6 +9,9 @@ REPLACE simple
REPLACE empty REPLACE empty
2 4 2 4
2 4 2 4
REPLACE empty partition with duplicated parts
6 12
6 12
REPLACE recursive REPLACE recursive
4 8 4 8
4 8 4 8

View File

@ -57,6 +57,18 @@ $CLICKHOUSE_CLIENT --query="SYSTEM SYNC REPLICA dst_r2;"
$CLICKHOUSE_CLIENT --query="SELECT count(), sum(d) FROM dst_r1;" $CLICKHOUSE_CLIENT --query="SELECT count(), sum(d) FROM dst_r1;"
$CLICKHOUSE_CLIENT --query="SELECT count(), sum(d) FROM dst_r2;" $CLICKHOUSE_CLIENT --query="SELECT count(), sum(d) FROM dst_r2;"
$CLICKHOUSE_CLIENT --query="SELECT 'REPLACE empty partition with duplicated parts';"
$CLICKHOUSE_CLIENT --query="INSERT INTO src VALUES (3, '0', 1), (3, '0', 3);"
$CLICKHOUSE_CLIENT --query="INSERT INTO src VALUES (3, '0', 1), (3, '0', 3);"
query_with_retry "ALTER TABLE dst_r1 REPLACE PARTITION 3 FROM src;"
$CLICKHOUSE_CLIENT --query="SYSTEM SYNC REPLICA dst_r2;"
$CLICKHOUSE_CLIENT --query="SELECT count(), sum(d) FROM dst_r1;"
$CLICKHOUSE_CLIENT --query="SELECT count(), sum(d) FROM dst_r2;"
query_with_retry "ALTER TABLE src DROP PARTITION 3;"
query_with_retry "ALTER TABLE dst_r1 REPLACE PARTITION 3 FROM src;"
$CLICKHOUSE_CLIENT --query="SYSTEM SYNC REPLICA dst_r2;"
$CLICKHOUSE_CLIENT --query="SELECT 'REPLACE recursive';" $CLICKHOUSE_CLIENT --query="SELECT 'REPLACE recursive';"
query_with_retry "ALTER TABLE dst_r1 DROP PARTITION 1;" query_with_retry "ALTER TABLE dst_r1 DROP PARTITION 1;"