mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-16 03:12:43 +00:00
basic implementation
This commit is contained in:
parent
e6fb5a21cb
commit
fd51839b97
@ -7568,6 +7568,7 @@ void StorageReplicatedMergeTree::replacePartitionFrom(
|
||||
|
||||
String drop_range_fake_part_name = getPartNamePossiblyFake(format_version, drop_range);
|
||||
|
||||
std::set<String> replaced_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
|
||||
@ -7580,13 +7581,15 @@ void StorageReplicatedMergeTree::replacePartitionFrom(
|
||||
"' has inconsistent granularity with table", partition_id, src_part->name);
|
||||
|
||||
String hash_hex = src_part->checksums.getTotalChecksumHex();
|
||||
const bool is_duplicated_part = replaced_parts.contains(hash_hex);
|
||||
replaced_parts.insert(hash_hex);
|
||||
|
||||
if (replace)
|
||||
LOG_INFO(log, "Trying to replace {} with hash_hex {}", src_part->name, hash_hex);
|
||||
else
|
||||
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);
|
||||
if (!lock)
|
||||
|
@ -9,6 +9,9 @@ REPLACE simple
|
||||
REPLACE empty
|
||||
2 4
|
||||
2 4
|
||||
REPLACE empty partition with duplicated parts
|
||||
6 12
|
||||
6 12
|
||||
REPLACE recursive
|
||||
4 8
|
||||
4 8
|
||||
|
@ -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_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';"
|
||||
query_with_retry "ALTER TABLE dst_r1 DROP PARTITION 1;"
|
||||
|
Loading…
Reference in New Issue
Block a user