mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 09:02:00 +00:00
Merge pull request #10121 from ClickHouse/fix_adaptive_granularity_compatibility
Fix adaptive granularity compatibility
This commit is contained in:
commit
9a00eca1c5
@ -246,6 +246,11 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree(
|
|||||||
|
|
||||||
createTableIfNotExists();
|
createTableIfNotExists();
|
||||||
|
|
||||||
|
/// We have to check granularity on other replicas. If it's fixed we
|
||||||
|
/// must create our new replica with fixed granularity and store this
|
||||||
|
/// information in /replica/metadata.
|
||||||
|
other_replicas_fixed_granularity = checkFixedGranualrityInZookeeper();
|
||||||
|
|
||||||
checkTableStructure(zookeeper_path);
|
checkTableStructure(zookeeper_path);
|
||||||
|
|
||||||
Coordination::Stat metadata_stat;
|
Coordination::Stat metadata_stat;
|
||||||
@ -256,11 +261,14 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
/// In old tables this node may missing or be empty
|
/// In old tables this node may missing or be empty
|
||||||
String replica_metadata;
|
String replica_metadata;
|
||||||
bool replica_metadata_exists = current_zookeeper->tryGet(replica_path + "/metadata", replica_metadata);
|
bool replica_metadata_exists = current_zookeeper->tryGet(replica_path + "/metadata", replica_metadata);
|
||||||
if (!replica_metadata_exists || replica_metadata.empty())
|
if (!replica_metadata_exists || replica_metadata.empty())
|
||||||
{
|
{
|
||||||
|
/// We have to check shared node granularity before we create ours.
|
||||||
|
other_replicas_fixed_granularity = checkFixedGranualrityInZookeeper();
|
||||||
ReplicatedMergeTreeTableMetadata current_metadata(*this);
|
ReplicatedMergeTreeTableMetadata current_metadata(*this);
|
||||||
current_zookeeper->createOrUpdate(replica_path + "/metadata", current_metadata.toString(), zkutil::CreateMode::Persistent);
|
current_zookeeper->createOrUpdate(replica_path + "/metadata", current_metadata.toString(), zkutil::CreateMode::Persistent);
|
||||||
}
|
}
|
||||||
@ -291,7 +299,6 @@ StorageReplicatedMergeTree::StorageReplicatedMergeTree(
|
|||||||
createNewZooKeeperNodes();
|
createNewZooKeeperNodes();
|
||||||
|
|
||||||
|
|
||||||
other_replicas_fixed_granularity = checkFixedGranualrityInZookeeper();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
import pytest
|
||||||
|
from helpers.cluster import ClickHouseCluster
|
||||||
|
|
||||||
|
cluster = ClickHouseCluster(__file__)
|
||||||
|
|
||||||
|
node1 = cluster.add_instance('node1', with_zookeeper=True)
|
||||||
|
node2 = cluster.add_instance('node2', with_zookeeper=True)
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
|
def start_cluster():
|
||||||
|
try:
|
||||||
|
cluster.start()
|
||||||
|
|
||||||
|
yield cluster
|
||||||
|
finally:
|
||||||
|
cluster.shutdown()
|
||||||
|
|
||||||
|
|
||||||
|
def test_attach_detach(start_cluster):
|
||||||
|
|
||||||
|
node1.query("""
|
||||||
|
CREATE TABLE test (key UInt64)
|
||||||
|
ENGINE = ReplicatedMergeTree('/clickhouse/test', '1')
|
||||||
|
ORDER BY tuple()
|
||||||
|
SETTINGS index_granularity_bytes = 0""")
|
||||||
|
|
||||||
|
node1.query("INSERT INTO test VALUES (1), (2)")
|
||||||
|
|
||||||
|
node2.query("""
|
||||||
|
CREATE TABLE test (key UInt64)
|
||||||
|
ENGINE = ReplicatedMergeTree('/clickhouse/test', '2')
|
||||||
|
ORDER BY tuple()""")
|
||||||
|
|
||||||
|
node2.query("INSERT INTO test VALUES (3), (4)")
|
||||||
|
|
||||||
|
node1.query("SYSTEM SYNC REPLICA test")
|
||||||
|
node2.query("SYSTEM SYNC REPLICA test")
|
||||||
|
|
||||||
|
assert node1.query("SELECT COUNT() FROM test") == "4\n"
|
||||||
|
assert node2.query("SELECT COUNT() FROM test") == "4\n"
|
||||||
|
|
||||||
|
node1.query("DETACH TABLE test")
|
||||||
|
node2.query("DETACH TABLE test")
|
||||||
|
|
||||||
|
node1.query("ATTACH TABLE test")
|
||||||
|
node2.query("ATTACH TABLE test")
|
||||||
|
|
||||||
|
assert node1.query("SELECT COUNT() FROM test") == "4\n"
|
||||||
|
assert node2.query("SELECT COUNT() FROM test") == "4\n"
|
Loading…
Reference in New Issue
Block a user