Merge pull request #18935 from fastio/bugfix_attach_partition_does_not_reset_mutation

Bugfix: attach partition should reset the mutation
This commit is contained in:
alesapin 2021-01-15 12:21:16 +03:00 committed by GitHub
commit d601faa669
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 0 deletions

View File

@ -254,6 +254,7 @@ void ReplicatedMergeTreeBlockOutputStream::commitPart(
part->info.min_block = block_number;
part->info.max_block = block_number;
part->info.level = 0;
part->info.mutation = 0;
part->name = part->getNewName(part->info);

View File

@ -0,0 +1,8 @@
<yandex>
<zookeeper>
<node index="1">
<host>zoo1</host>
<port>2181</port>
</node>
</zookeeper>
</yandex>

View File

@ -0,0 +1,60 @@
import pytest
from helpers.client import QueryRuntimeException
from helpers.cluster import ClickHouseCluster
from helpers.test_tools import TSV
cluster = ClickHouseCluster(__file__)
node = cluster.add_instance("node", main_configs=["configs/zookeeper_config.xml"], with_zookeeper=True)
@pytest.fixture(scope="module")
def start_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def test_part_should_reset_mutation(start_cluster):
node.query(
"CREATE TABLE test (i Int64, s String) ENGINE = ReplicatedMergeTree('/clickhouse/tables/test', 'node') ORDER BY i;"
)
node.query("INSERT INTO test SELECT 1, 'a'")
node.query("optimize table test final")
node.query("optimize table test final")
expected = TSV('''all_0_0_2\t1\ta''')
assert TSV(node.query('SELECT _part, * FROM test')) == expected
node.query("ALTER TABLE test UPDATE s='xxx' WHERE 1", settings={"mutations_sync": "2"})
node.query("ALTER TABLE test UPDATE s='xxx' WHERE 1", settings={"mutations_sync": "2"})
node.query("ALTER TABLE test UPDATE s='xxx' WHERE 1", settings={"mutations_sync": "2"})
node.query("ALTER TABLE test UPDATE s='xxx' WHERE 1", settings={"mutations_sync": "2"})
expected = TSV('''all_0_0_2_4\t1\txxx''')
assert TSV(node.query('SELECT _part, * FROM test')) == expected
node.query(
"CREATE TABLE restore (i Int64, s String) ENGINE = ReplicatedMergeTree('/clickhouse/tables/restore', 'node') ORDER BY i;"
)
node.query("ALTER TABLE restore FETCH PARTITION tuple() FROM '/clickhouse/tables/test/'")
node.query("ALTER TABLE restore ATTACH PART 'all_0_0_2_4'")
node.query("INSERT INTO restore select 2, 'a'")
print(TSV(node.query('SELECT _part, * FROM restore')))
expected = TSV('''all_0_0_0\t1\txxx\nall_1_1_0\t2\ta''')
assert TSV(node.query('SELECT _part, * FROM restore ORDER BY i')) == expected
node.query("ALTER TABLE restore UPDATE s='yyy' WHERE 1", settings={"mutations_sync": "2"})
expected = TSV('''all_0_0_0_2\t1\tyyy\nall_1_1_0_2\t2\tyyy''')
assert TSV(node.query('SELECT _part, * FROM restore ORDER BY i')) == expected
node.query("ALTER TABLE restore DELETE WHERE 1", settings={"mutations_sync": "2"})
assert node.query("SELECT count() FROM restore").strip() == "0"