mirror of
https://github.com/hanzoai/datastore.git
synced 2026-09-26 13:55:07 +00:00
Follow-up to #105171, which added `ruff` with a deliberately narrow, bug-class-only rule set and left the unused-name and star-import rules off pending a dedicated cleanup pass. This enables that second batch in `pyproject.toml` and fixes every violation across the tree (the bulk in integration tests): - `F401` unused-import and `F841` unused-variable: removed, preserving any side-effecting right-hand side (e.g. `result = node.query(...)` becomes `node.query(...)`). Two `try: import ...` feature probes are kept with `# noqa: F401`. - `F541` f-string-missing-placeholders: dropped the redundant `f` prefix. - `F403`/`F405` star imports: every `from module import *` is expanded into explicit imports of the names actually used, taken from each name's real origin, so stdlib/third-party names import from their real source rather than through a test "convenience bundle". The now-empty `tests/integration/helpers/kafka/common_direct.py` bundle is removed and its three remaining consumers import `_VarintBytes`/`KafkaAdminClient` directly. Eliminating the star imports surfaced a real bug the wildcard had masked from `F821`: `generate_presets.py` in `test_prometheus_protocols` called an undefined `execute_instant_query_with_http_api`; fixed to the existing `execute_query_via_http_api`. No `black`/`isort` reformatting was applied (neither is enforced in the style check), so the diff is limited to the lint fixes themselves. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
142 lines
4.5 KiB
Python
142 lines
4.5 KiB
Python
|
|
import pytest
|
|
|
|
from helpers.cluster import CLICKHOUSE_CI_MIN_TESTED_VERSION, ClickHouseCluster
|
|
from helpers.test_tools import assert_eq_with_retry, exec_query_with_retry
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
node1 = cluster.add_instance(
|
|
"node1",
|
|
with_zookeeper=True,
|
|
image="clickhouse/clickhouse-server",
|
|
tag=CLICKHOUSE_CI_MIN_TESTED_VERSION,
|
|
with_installed_binary=True,
|
|
stay_alive=True,
|
|
main_configs=[
|
|
"configs/compat.xml",
|
|
],
|
|
)
|
|
node2 = cluster.add_instance(
|
|
"node2",
|
|
with_zookeeper=True,
|
|
image="clickhouse/clickhouse-server",
|
|
tag=CLICKHOUSE_CI_MIN_TESTED_VERSION,
|
|
with_installed_binary=True,
|
|
stay_alive=True,
|
|
main_configs=[
|
|
"configs/compat.xml",
|
|
],
|
|
)
|
|
node3 = cluster.add_instance(
|
|
"node3",
|
|
with_zookeeper=True,
|
|
image="clickhouse/clickhouse-server",
|
|
tag=CLICKHOUSE_CI_MIN_TESTED_VERSION,
|
|
with_installed_binary=True,
|
|
stay_alive=True,
|
|
main_configs=[
|
|
"configs/compat.xml",
|
|
],
|
|
)
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def start_cluster():
|
|
try:
|
|
cluster.start()
|
|
|
|
yield cluster
|
|
finally:
|
|
cluster.shutdown()
|
|
|
|
|
|
def test_mutate_and_upgrade(start_cluster):
|
|
for node in [node1, node2]:
|
|
node.query("DROP TABLE IF EXISTS mt")
|
|
node.query(
|
|
"CREATE TABLE mt (EventDate Date, id UInt64) ENGINE ReplicatedMergeTree('/clickhouse/tables/t', '{}') ORDER BY tuple()".format(
|
|
node.name
|
|
)
|
|
)
|
|
|
|
node1.query("INSERT INTO mt VALUES ('2020-02-13', 1), ('2020-02-13', 2);")
|
|
|
|
node1.query("ALTER TABLE mt DELETE WHERE id = 2", settings={"mutations_sync": "2"})
|
|
node2.query("SYSTEM SYNC REPLICA mt", timeout=15)
|
|
|
|
node2.query("DETACH TABLE mt") # stop being leader
|
|
node1.query("DETACH TABLE mt") # stop being leader
|
|
node1.query("SYSTEM FLUSH LOGS")
|
|
node2.query("SYSTEM FLUSH LOGS")
|
|
node1.restart_with_latest_version(signal=9, fix_metadata=False)
|
|
node2.restart_with_latest_version(signal=9, fix_metadata=False)
|
|
|
|
# After hard restart table can be in readonly mode
|
|
exec_query_with_retry(
|
|
node2, "INSERT INTO mt VALUES ('2020-02-13', 3)", retry_count=60
|
|
)
|
|
exec_query_with_retry(node1, "SYSTEM SYNC REPLICA mt", retry_count=60)
|
|
|
|
assert node1.query("SELECT COUNT() FROM mt") == "2\n"
|
|
assert node2.query("SELECT COUNT() FROM mt") == "2\n"
|
|
|
|
node1.query("INSERT INTO mt VALUES ('2020-02-13', 4);")
|
|
|
|
node2.query("SYSTEM SYNC REPLICA mt", timeout=15)
|
|
|
|
assert node1.query("SELECT COUNT() FROM mt") == "3\n"
|
|
assert node2.query("SELECT COUNT() FROM mt") == "3\n"
|
|
|
|
node2.query("ALTER TABLE mt DELETE WHERE id = 3", settings={"mutations_sync": "2"})
|
|
|
|
node1.query("SYSTEM SYNC REPLICA mt", timeout=15)
|
|
|
|
assert node1.query("SELECT COUNT() FROM mt") == "2\n"
|
|
assert node2.query("SELECT COUNT() FROM mt") == "2\n"
|
|
|
|
node1.query(
|
|
"ALTER TABLE mt MODIFY COLUMN id Int32 DEFAULT 0",
|
|
settings={"replication_alter_partitions_sync": "2"},
|
|
)
|
|
|
|
node2.query("OPTIMIZE TABLE mt FINAL")
|
|
|
|
assert node1.query("SELECT id FROM mt ORDER BY id") == "1\n4\n"
|
|
assert node2.query("SELECT id FROM mt ORDER BY id") == "1\n4\n"
|
|
|
|
for node in [node1, node2]:
|
|
node.query("DROP TABLE mt")
|
|
|
|
|
|
def test_upgrade_while_mutation(start_cluster):
|
|
node3.query("DROP TABLE IF EXISTS mt1")
|
|
|
|
node3.query(
|
|
"CREATE TABLE mt1 (EventDate Date, id UInt64) ENGINE ReplicatedMergeTree('/clickhouse/tables/t1', 'node3') ORDER BY tuple()"
|
|
)
|
|
|
|
node3.query("INSERT INTO mt1 select '2020-02-13', number from numbers(100000)")
|
|
|
|
node3.query("SYSTEM STOP MERGES mt1")
|
|
node3.query("ALTER TABLE mt1 DELETE WHERE id % 2 == 0")
|
|
|
|
node3.query("DETACH TABLE mt1") # stop being leader
|
|
# Flush logs before restart to avoid trash from system tables which are on database ordindary
|
|
# (We could be in process of creating some system table, which will leave empty directory on restart,
|
|
# so when we start moving system tables from ordinary to atomic db, it will complain about some undeleted files)
|
|
node3.query("SYSTEM FLUSH LOGS")
|
|
node3.restart_with_latest_version(signal=9, fix_metadata=False)
|
|
|
|
# checks for readonly
|
|
exec_query_with_retry(node3, "OPTIMIZE TABLE mt1", sleep_time=5, retry_count=60)
|
|
|
|
node3.query(
|
|
"ALTER TABLE mt1 DELETE WHERE id > 100000", settings={"mutations_sync": "2"}
|
|
)
|
|
# will delete nothing, but previous async mutation will finish with this query
|
|
|
|
assert_eq_with_retry(node3, "SELECT COUNT() from mt1", "50000\n")
|
|
|
|
node3.query("DROP TABLE mt1")
|