ClickHouse/tests/integration/test_keeper_map/test.py

134 lines
4.1 KiB
Python
Raw Normal View History

2022-08-30 13:41:36 +00:00
import pytest
from helpers.cluster import ClickHouseCluster
2023-07-04 09:31:15 +00:00
from helpers.network import PartitionManager, _NetworkManager
2022-08-30 13:41:36 +00:00
test_recover_staled_replica_run = 1
cluster = ClickHouseCluster(__file__)
node = cluster.add_instance(
"node",
2022-09-02 07:49:09 +00:00
main_configs=["configs/enable_keeper_map.xml"],
2024-08-01 08:30:50 +00:00
user_configs=["configs/keeper_retries.xml"],
2022-08-30 13:41:36 +00:00
with_zookeeper=True,
stay_alive=True,
)
@pytest.fixture(scope="module")
def started_cluster():
try:
cluster.start()
yield cluster
finally:
cluster.shutdown()
def get_genuine_zk():
return cluster.get_kazoo_client("zoo1")
def remove_children(client, path):
children = client.get_children(path)
for child in children:
child_path = f"{path}/{child}"
remove_children(client, child_path)
client.delete(child_path)
2023-07-04 09:31:15 +00:00
def print_iptables_rules():
print(f"iptables rules: {_NetworkManager.get().dump_rules()}")
def assert_keeper_exception_after_partition(query):
with PartitionManager() as pm:
pm.drop_instance_zk_connections(node)
try:
2024-07-30 14:26:19 +00:00
error = node.query_and_get_error_with_retry(
query,
sleep_time=1,
)
2022-08-30 13:41:36 +00:00
assert "Coordination::Exception" in error
2023-07-04 09:31:15 +00:00
except:
print_iptables_rules()
raise
2022-08-30 13:41:36 +00:00
2023-07-04 09:31:15 +00:00
def run_query(query):
try:
result = node.query_with_retry(query, sleep_time=1)
return result
except:
print_iptables_rules()
raise
def test_keeper_map_without_zk(started_cluster):
2024-07-31 12:09:07 +00:00
run_query("DROP TABLE IF EXISTS test_keeper_map_without_zk SYNC")
2022-08-30 13:41:36 +00:00
assert_keeper_exception_after_partition(
2023-07-04 09:31:15 +00:00
"CREATE TABLE test_keeper_map_without_zk (key UInt64, value UInt64) ENGINE = KeeperMap('/test_keeper_map_without_zk') PRIMARY KEY(key);"
2022-08-30 13:41:36 +00:00
)
2023-07-04 09:31:15 +00:00
run_query(
"CREATE TABLE test_keeper_map_without_zk (key UInt64, value UInt64) ENGINE = KeeperMap('/test_keeper_map_without_zk') PRIMARY KEY(key);"
2022-08-30 13:41:36 +00:00
)
assert_keeper_exception_after_partition(
2023-01-10 13:16:28 +00:00
"INSERT INTO test_keeper_map_without_zk VALUES (1, 11)"
2022-08-30 13:41:36 +00:00
)
2023-07-04 09:31:15 +00:00
run_query("INSERT INTO test_keeper_map_without_zk VALUES (1, 11)")
2022-08-30 13:41:36 +00:00
2023-01-10 13:16:28 +00:00
assert_keeper_exception_after_partition("SELECT * FROM test_keeper_map_without_zk")
2023-07-04 09:31:15 +00:00
assert run_query("SELECT * FROM test_keeper_map_without_zk") == "1\t11\n"
2022-08-30 13:41:36 +00:00
with PartitionManager() as pm:
pm.drop_instance_zk_connections(node)
node.restart_clickhouse(60)
2023-07-04 09:31:15 +00:00
try:
error = node.query_and_get_error_with_retry(
2024-07-30 14:26:19 +00:00
"SELECT * FROM test_keeper_map_without_zk",
sleep_time=1,
2023-07-04 09:31:15 +00:00
)
assert "Failed to activate table because of connection issues" in error
except:
print_iptables_rules()
raise
2022-08-30 13:41:36 +00:00
2023-07-04 09:31:15 +00:00
run_query("SELECT * FROM test_keeper_map_without_zk")
2022-08-30 13:41:36 +00:00
client = get_genuine_zk()
2023-07-04 09:31:15 +00:00
remove_children(client, "/test_keeper_map/test_keeper_map_without_zk")
2022-08-30 13:41:36 +00:00
node.restart_clickhouse(60)
2023-07-04 09:31:15 +00:00
error = node.query_and_get_error_with_retry(
"SELECT * FROM test_keeper_map_without_zk"
)
2022-08-30 13:41:36 +00:00
assert "Failed to activate table because of invalid metadata in ZooKeeper" in error
client.stop()
2024-07-22 19:53:22 +00:00
def test_keeper_map_with_failed_drop(started_cluster):
2024-07-31 12:09:07 +00:00
run_query("DROP TABLE IF EXISTS test_keeper_map_with_failed_drop SYNC")
run_query("DROP TABLE IF EXISTS test_keeper_map_with_failed_drop_another SYNC")
2024-07-22 19:53:22 +00:00
run_query(
"CREATE TABLE test_keeper_map_with_failed_drop (key UInt64, value UInt64) ENGINE = KeeperMap('/test_keeper_map_with_failed_drop') PRIMARY KEY(key);"
)
run_query("INSERT INTO test_keeper_map_with_failed_drop VALUES (1, 11)")
run_query("SYSTEM ENABLE FAILPOINT keepermap_fail_drop_data")
node.query("DROP TABLE test_keeper_map_with_failed_drop SYNC")
zk_client = get_genuine_zk()
assert (
zk_client.get("/test_keeper_map/test_keeper_map_with_failed_drop/data")
is not None
)
run_query("SYSTEM DISABLE FAILPOINT keepermap_fail_drop_data")
run_query(
"CREATE TABLE test_keeper_map_with_failed_drop_another (key UInt64, value UInt64) ENGINE = KeeperMap('/test_keeper_map_with_failed_drop') PRIMARY KEY(key);"
)