ClickHouse/tests/integration/test_keeper_reconfig_remove/test.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

130 lines
3.7 KiB
Python
Raw Normal View History

2023-04-20 13:26:02 +00:00
#!/usr/bin/env python3
2024-09-27 10:19:39 +00:00
import os
import subprocess
2024-09-27 10:19:39 +00:00
import typing as tp
2023-04-20 13:26:02 +00:00
import pytest
2024-09-27 10:19:39 +00:00
2023-04-20 13:26:02 +00:00
import helpers.keeper_utils as ku
2024-09-27 10:19:39 +00:00
from helpers.cluster import ClickHouseCluster, ClickHouseInstance
2023-04-20 13:26:02 +00:00
cluster = ClickHouseCluster(__file__)
CONFIG_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "configs")
node1 = cluster.add_instance("node1", main_configs=["configs/keeper1.xml"])
node2 = cluster.add_instance("node2", main_configs=["configs/keeper2.xml"])
node3 = cluster.add_instance("node3", main_configs=["configs/keeper3.xml"])
log_msg_removed = "has been removed from the cluster"
zk1, zk2, zk3 = None, None, None
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
conn: tp.Optional[ku.KeeperClient]
2023-04-20 13:26:02 +00:00
for conn in [zk1, zk2, zk3]:
if conn:
conn.stop()
cluster.shutdown()
def create_client(node: ClickHouseInstance):
2023-09-07 00:44:54 +00:00
return ku.KeeperClient(
cluster.server_bin_path, cluster.get_instance_ip(node.name), 9181
)
2023-04-20 13:26:02 +00:00
def test_reconfig_remove_followers_from_3(started_cluster):
"""
Remove 1 follower node from cluster of 3.
Then remove another follower from two left nodes.
Check that remaining node is in standalone mode.
"""
global zk1, zk2, zk3
zk1 = create_client(node1)
config = zk1.get("/keeper/config")
2023-04-20 13:26:02 +00:00
print("Initial config", config)
assert len(config.split("\n")) == 3
assert "node1" in config
assert "node2" in config
assert "node3" in config
with pytest.raises(ValueError):
2023-04-20 13:26:02 +00:00
zk1.reconfig(joining=None, leaving=None, new_members=None)
with pytest.raises(ku.KeeperException):
2023-04-20 13:26:02 +00:00
# bulk reconfiguration is not supported
zk1.reconfig(joining=None, leaving=None, new_members="3")
with pytest.raises(ValueError):
2023-04-20 13:26:02 +00:00
zk1.reconfig(joining="1", leaving="1", new_members="3")
with pytest.raises(ku.KeeperException):
2023-04-20 13:26:02 +00:00
# at least one node must be left
zk1.reconfig(joining=None, leaving="1,2,3", new_members=None)
for i in range(100):
zk1.create(f"/test_two_{i}", "somedata")
2023-04-20 13:26:02 +00:00
zk2 = create_client(node2)
2023-04-20 13:26:02 +00:00
zk2.sync("/test_two_0")
ku.wait_configs_equal(config, zk2)
2023-04-20 13:26:02 +00:00
zk3 = create_client(node3)
2023-04-20 13:26:02 +00:00
zk3.sync("/test_two_0")
ku.wait_configs_equal(config, zk3)
2023-04-20 13:26:02 +00:00
for i in range(100):
assert zk2.exists(f"test_two_{i}")
assert zk3.exists(f"test_two_{i}")
2023-04-20 13:26:02 +00:00
config = zk1.reconfig(joining=None, leaving="3", new_members=None)
2023-04-20 13:26:02 +00:00
print("After removing 3", config)
assert len(config.split("\n")) == 2
assert "node1" in config
assert "node2" in config
assert "node3" not in config
zk2.stop()
zk2 = create_client(node2)
ku.wait_configs_equal(config, zk2)
2023-04-20 13:26:02 +00:00
for i in range(100):
assert zk2.exists(f"test_two_{i}")
zk2.create(f"/test_two_{100 + i}", "otherdata")
2023-04-20 13:26:02 +00:00
zk1.stop()
zk1 = create_client(node1)
2023-04-20 13:26:02 +00:00
zk1.sync("/test_two_0")
for i in range(200):
assert zk1.exists(f"test_two_{i}")
2023-04-20 13:26:02 +00:00
assert node3.contains_in_log(log_msg_removed)
for i in range(100):
zk2.create(f"/test_two_{200 + i}", "otherdata")
2023-04-20 13:26:02 +00:00
config = zk1.reconfig(joining=None, leaving="2", new_members=None)
2023-04-20 13:26:02 +00:00
print("After removing 2", config)
assert len(config.split("\n")) == 1
assert "node1" in config
assert "node2" not in config
assert "node3" not in config
zk1.stop()
zk1 = create_client(node1)
2023-04-20 13:26:02 +00:00
zk1.sync("/test_two_0")
for i in range(300):
assert zk1.exists(f"test_two_{i}")
2023-04-20 13:26:02 +00:00
assert not node1.contains_in_log(log_msg_removed)
assert node2.contains_in_log(log_msg_removed)
2023-09-07 00:44:54 +00:00
assert "Mode: standalone" in zk1.execute_query("stat")