mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 19:42:00 +00:00
a6f89c0546
* Added suggestions for mistyped names for db and tables with different scenarios commented * fixed bugs * fixed style check * fixed errors * fixed errors * fixed error with exceptions * fixed exceptions * fixed exceptions * fixed exceptions * added test and fixed bugs * fixed style check * fixed style check * fixed style check * fixed check black * Update test.py * Fixed server crash * Fixed server crash and style check * Fixed style check * Fixed style check * Fixed style check * Fixed bugs with drop_db * fixed fast test * added tests * fixed style check * fixed style check * fixed bug with lock_db * fixed bug with lock_db and fixed reviews * fixed bug with lock_db and fixed reviews * fixed style check * fixed fast test * fixed fast test * revert tofd582a2
* revert tofd582a2
* Removed unused parameters Co-authored-by: Yakov Olkhovskiy <99031427+yakov-olkhovskiy@users.noreply.github.com> * Remove unused parameters Co-authored-by: Yakov Olkhovskiy <99031427+yakov-olkhovskiy@users.noreply.github.com> * resolved arguments issue in assertDatabaseExists * fixing fast test * fixed fast test * fixed stateless test for default db * Update src/Interpreters/DatabaseCatalog.cpp Co-authored-by: Yakov Olkhovskiy <99031427+yakov-olkhovskiy@users.noreply.github.com> * Update src/Interpreters/DatabaseCatalog.cpp Co-authored-by: Yakov Olkhovskiy <99031427+yakov-olkhovskiy@users.noreply.github.com> * Update src/Interpreters/DatabaseCatalog.cpp Co-authored-by: Yakov Olkhovskiy <99031427+yakov-olkhovskiy@users.noreply.github.com> * Fixing tests. * resolved problem with mutex * Fixed mutex in assertDatabaseExists * changes about assertDatabaseExists * fixed bugs with file types * fixed string types * fixed fast test * fixed mutex * fixed mutex * fixed style check * Update src/Interpreters/DatabaseCatalog.cpp Co-authored-by: Yakov Olkhovskiy <99031427+yakov-olkhovskiy@users.noreply.github.com> * Update src/Interpreters/DatabaseCatalog.cpp Co-authored-by: Yakov Olkhovskiy <99031427+yakov-olkhovskiy@users.noreply.github.com> * Update src/Interpreters/DatabaseCatalog.cpp Co-authored-by: Yakov Olkhovskiy <99031427+yakov-olkhovskiy@users.noreply.github.com> * Update src/Interpreters/DatabaseCatalog.cpp Co-authored-by: Yakov Olkhovskiy <99031427+yakov-olkhovskiy@users.noreply.github.com> * Update src/Interpreters/DatabaseCatalog.cpp Co-authored-by: Yakov Olkhovskiy <99031427+yakov-olkhovskiy@users.noreply.github.com> * Update src/Interpreters/DatabaseCatalog.cpp Co-authored-by: Yakov Olkhovskiy <99031427+yakov-olkhovskiy@users.noreply.github.com> * fixed build * added -unlocked versions of functions * Revert "fixed build" This reverts commit8ce961be21
. * Revert "fixed build" This reverts commit8ce961be21
. * changed usage of assertDatabaseExistsUnlocked() * fixed style check * style check * style check * Revert "style check" This reverts commit28a9ee85a0
. * Merge branch 'master' into hints-for-wrong-db-or-table-name * Changed AssertDatabaseExists and unified exception output * resolved proposed changes and modified tests * Revert "resolved proposed changes and modified tests" This reverts commitd45337d65c
. * resolved requested changes * fixed tests * fixed tests * fixed check black * Update include brackets Co-authored-by: Yakov Olkhovskiy <99031427+yakov-olkhovskiy@users.noreply.github.com> * Update suggested changes * Update suggested changes * Fixed style check * Added test to analyzer_integration_broken * Update DatabaseCatalog.cpp * Update test.py * fixed test * Revert "fixed test" This reverts commitca6d4c17c8
. * fixed test * Revert "fixed test" This reverts commitfe6d0d9c86
, reversing changes made to22f4496704
. * Update test.py * fixed black check * Update test.py * fixed long_log_tinylog_deadlock_race * Update DatabaseCatalog.cpp * Update test.py * style * Update DatabaseCatalog.cpp * Fixed test * implemented for IDatabase * Style check * removed const_cast * Update DatabaseCatalog.h * Update DatabaseCatalog.h * Update DatabaseCatalog.cpp * Update DatabaseCatalog.cpp * Added db name to hints * Update 00002_log_and_exception_messages_formatting.sql * Update 00002_log_and_exception_messages_formatting.sql --------- Co-authored-by: Yakov Olkhovskiy <99031427+yakov-olkhovskiy@users.noreply.github.com>
223 lines
5.4 KiB
Python
223 lines
5.4 KiB
Python
import time
|
|
import pytest
|
|
import logging
|
|
from contextlib import contextmanager
|
|
from helpers.cluster import ClickHouseCluster
|
|
from helpers.test_tools import assert_eq_with_retry
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
logger.setLevel(logging.DEBUG)
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
node = cluster.add_instance(
|
|
"node",
|
|
stay_alive=True,
|
|
with_zookeeper=False,
|
|
main_configs=[
|
|
"configs/keeper.xml",
|
|
"configs/transactions.xml",
|
|
],
|
|
)
|
|
|
|
|
|
@pytest.fixture(scope="module", autouse=True)
|
|
def start_cluster():
|
|
try:
|
|
cluster.start()
|
|
yield cluster
|
|
finally:
|
|
cluster.shutdown()
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def test_name(request):
|
|
return request.node.name
|
|
|
|
|
|
@pytest.fixture(scope="function")
|
|
def exclusive_table(test_name):
|
|
normalized = (
|
|
test_name.replace("[", "_")
|
|
.replace("]", "_")
|
|
.replace(" ", "_")
|
|
.replace("-", "_")
|
|
)
|
|
return "table_" + normalized
|
|
|
|
|
|
def get_event_select_count():
|
|
return int(
|
|
node.query(
|
|
"""
|
|
SELECT value FROM system.events WHERE event = 'SelectQuery';
|
|
"""
|
|
)
|
|
)
|
|
|
|
|
|
def get_query_processes_count(query_id):
|
|
q = f"""
|
|
SELECT count() FROM system.processes WHERE query_id = '{query_id}';
|
|
"""
|
|
return q
|
|
|
|
|
|
def is_query_running(query_id):
|
|
return 1 == int(node.query(get_query_processes_count(query_id)))
|
|
|
|
|
|
def wait_select_start(query_id):
|
|
assert_eq_with_retry(
|
|
node,
|
|
get_query_processes_count(query_id),
|
|
"1\n",
|
|
)
|
|
|
|
|
|
LOCK_FREE_QUERIES = {
|
|
"detach table": "DETACH TABLE {table};",
|
|
"drop part": "ALTER TABLE {table} DROP PART 'all_1_1_0';",
|
|
"detach part": "ALTER TABLE {table} DETACH PART 'all_1_1_0';",
|
|
"truncate": "TRUNCATE TABLE {table};",
|
|
}
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"lock_free_query", LOCK_FREE_QUERIES.values(), ids=LOCK_FREE_QUERIES.keys()
|
|
)
|
|
def test_query_is_lock_free(lock_free_query, exclusive_table):
|
|
node.query(
|
|
f"""
|
|
CREATE TABLE {exclusive_table}
|
|
(a Int64)
|
|
Engine=MergeTree ORDER BY a;
|
|
"""
|
|
)
|
|
node.query(
|
|
f"""
|
|
INSERT INTO {exclusive_table} SELECT number FROM numbers(50);
|
|
"""
|
|
)
|
|
|
|
query_id = "select-" + exclusive_table
|
|
|
|
select_handler = node.get_query_request(
|
|
f"""
|
|
SELECT sleepEachRow(3) FROM {exclusive_table} SETTINGS function_sleep_max_microseconds_per_block = 0;
|
|
""",
|
|
query_id=query_id,
|
|
)
|
|
wait_select_start(query_id)
|
|
|
|
for _ in [1, 2, 3, 4, 5]:
|
|
assert is_query_running(query_id)
|
|
assert select_handler.process.poll() is None
|
|
time.sleep(1)
|
|
|
|
node.query(lock_free_query.format(table=exclusive_table))
|
|
|
|
assert is_query_running(query_id)
|
|
|
|
if "DETACH TABLE" in lock_free_query:
|
|
result = node.query_and_get_error(
|
|
f"""
|
|
SELECT count() FROM {exclusive_table};
|
|
"""
|
|
)
|
|
assert f"Table default.{exclusive_table} does not exist" in result
|
|
else:
|
|
assert 0 == int(
|
|
node.query(
|
|
f"""
|
|
SELECT count() FROM {exclusive_table};
|
|
"""
|
|
)
|
|
)
|
|
|
|
|
|
PERMANENT_QUERIES = {
|
|
"truncate": ("TRUNCATE TABLE {table};", 0),
|
|
"detach-partition-all": ("ALTER TABLE {table} DETACH PARTITION ALL;", 0),
|
|
"detach-part": ("ALTER TABLE {table} DETACH PARTITION '20221001';", 49),
|
|
"drop-part": ("ALTER TABLE {table} DROP PART '20220901_1_1_0';", 49),
|
|
}
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"transaction", ["NoTx", "TxCommit", "TxRollback", "TxNotFinished"]
|
|
)
|
|
@pytest.mark.parametrize(
|
|
"permanent", PERMANENT_QUERIES.values(), ids=PERMANENT_QUERIES.keys()
|
|
)
|
|
def test_query_is_permanent(transaction, permanent, exclusive_table):
|
|
node.query(
|
|
f"""
|
|
CREATE TABLE {exclusive_table}
|
|
(
|
|
a Int64,
|
|
date Date
|
|
)
|
|
Engine=MergeTree
|
|
PARTITION BY date
|
|
ORDER BY a;
|
|
"""
|
|
)
|
|
node.query(
|
|
f"""
|
|
INSERT INTO {exclusive_table} SELECT number, toDate('2022-09-01') + INTERVAL number DAY FROM numbers(50);
|
|
"""
|
|
)
|
|
|
|
query_id = "select-" + exclusive_table
|
|
|
|
select_handler = node.get_query_request(
|
|
f"""
|
|
SELECT sleepEachRow(3) FROM {exclusive_table} SETTINGS function_sleep_max_microseconds_per_block = 0;
|
|
""",
|
|
query_id=query_id,
|
|
)
|
|
wait_select_start(query_id)
|
|
|
|
for _ in [1, 2, 3, 4, 5]:
|
|
assert is_query_running(query_id)
|
|
assert select_handler.process.poll() is None
|
|
time.sleep(1)
|
|
|
|
permanent_query = permanent[0]
|
|
result = permanent[1]
|
|
statement = permanent_query.format(table=exclusive_table)
|
|
if transaction == "TxCommit":
|
|
query = f"""
|
|
BEGIN TRANSACTION;
|
|
{statement}
|
|
COMMIT;
|
|
"""
|
|
elif transaction == "TxRollback":
|
|
query = f"""
|
|
BEGIN TRANSACTION;
|
|
{statement}
|
|
ROLLBACK;
|
|
"""
|
|
result = 50
|
|
elif transaction == "TxNotFinished":
|
|
query = f"""
|
|
BEGIN TRANSACTION;
|
|
{statement}
|
|
"""
|
|
result = 50
|
|
else:
|
|
query = statement
|
|
|
|
node.query(query)
|
|
|
|
node.restart_clickhouse(kill=True)
|
|
|
|
assert result == int(
|
|
node.query(
|
|
f"""
|
|
SELECT count() FROM {exclusive_table};
|
|
"""
|
|
)
|
|
)
|