2023-03-13 13:59:00 +00:00
|
|
|
import fnmatch
|
2019-11-04 17:13:49 +00:00
|
|
|
|
2024-09-27 10:19:39 +00:00
|
|
|
import pytest
|
|
|
|
|
2019-11-04 17:13:49 +00:00
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
2021-08-13 13:25:27 +00:00
|
|
|
node1 = cluster.add_instance(
|
|
|
|
"node1", main_configs=["configs/config_without_standard_part_log.xml"]
|
|
|
|
)
|
2019-11-04 17:13:49 +00:00
|
|
|
node2 = cluster.add_instance(
|
|
|
|
"node2", main_configs=["configs/config_with_standard_part_log.xml"]
|
|
|
|
)
|
|
|
|
node3 = cluster.add_instance(
|
|
|
|
"node3", main_configs=["configs/config_with_non_standard_part_log.xml"]
|
|
|
|
)
|
2022-03-10 15:44:19 +00:00
|
|
|
node4 = cluster.add_instance(
|
|
|
|
"node4", main_configs=["configs/config_disk_name_test.xml"]
|
|
|
|
)
|
2019-11-04 17:13:49 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2019-11-04 17:13:49 +00:00
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def start_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
yield cluster
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2019-11-04 17:13:49 +00:00
|
|
|
def test_config_without_part_log(start_cluster):
|
2023-03-13 13:59:00 +00:00
|
|
|
resp = node1.query_and_get_error("SELECT * FROM system.part_log")
|
|
|
|
assert fnmatch.fnmatch(resp, "*DB::Exception:*system.part_log*UNKNOWN_TABLE*"), resp
|
|
|
|
|
2019-11-04 17:13:49 +00:00
|
|
|
node1.query(
|
|
|
|
"CREATE TABLE test_table(word String, value UInt64) ENGINE=MergeTree() ORDER BY value"
|
|
|
|
)
|
2023-03-13 13:59:00 +00:00
|
|
|
resp = node1.query_and_get_error("SELECT * FROM system.part_log")
|
|
|
|
assert fnmatch.fnmatch(resp, "*DB::Exception:*system.part_log*UNKNOWN_TABLE*"), resp
|
|
|
|
|
2019-11-04 17:13:49 +00:00
|
|
|
node1.query("INSERT INTO test_table VALUES ('name', 1)")
|
2020-05-30 18:43:14 +00:00
|
|
|
node1.query("SYSTEM FLUSH LOGS")
|
2023-03-13 13:59:00 +00:00
|
|
|
|
|
|
|
resp = node1.query_and_get_error("SELECT * FROM system.part_log")
|
|
|
|
assert fnmatch.fnmatch(resp, "*DB::Exception:*system.part_log*UNKNOWN_TABLE*"), resp
|
2019-11-04 17:13:49 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2020-05-31 15:10:52 +00:00
|
|
|
# Note: if part_log is defined, we cannot say when the table will be created - because of metric_log, trace_log, text_log, query_log...
|
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2019-11-04 17:13:49 +00:00
|
|
|
def test_config_with_standard_part_log(start_cluster):
|
|
|
|
node2.query(
|
|
|
|
"CREATE TABLE test_table(word String, value UInt64) ENGINE=MergeTree() Order by value"
|
|
|
|
)
|
|
|
|
node2.query("INSERT INTO test_table VALUES ('name', 1)")
|
2020-06-01 09:12:52 +00:00
|
|
|
node2.query("SYSTEM FLUSH LOGS")
|
2020-05-30 18:42:19 +00:00
|
|
|
assert node2.query("SELECT * FROM system.part_log") != ""
|
2019-11-04 17:13:49 +00:00
|
|
|
|
2020-09-16 04:26:10 +00:00
|
|
|
|
2023-06-20 05:17:07 +00:00
|
|
|
def test_part_log_contains_partition(start_cluster):
|
|
|
|
node2.query(
|
2023-06-20 05:31:05 +00:00
|
|
|
"CREATE TABLE test_partition_table (date Date, word String, value UInt64) ENGINE=MergeTree() "
|
|
|
|
+ "PARTITION BY toYYYYMM(date) Order by value"
|
2023-06-20 05:17:07 +00:00
|
|
|
)
|
2023-06-20 07:26:46 +00:00
|
|
|
node2.query(
|
|
|
|
"INSERT INTO test_partition_table VALUES "
|
2023-06-20 05:31:05 +00:00
|
|
|
+ "('2023-06-20', 'a', 10), ('2023-06-21', 'b', 11),"
|
|
|
|
+ "('2023-05-20', 'cc', 14),('2023-05-21', 'd1', 15);"
|
2023-06-20 05:17:07 +00:00
|
|
|
)
|
|
|
|
node2.query("SYSTEM FLUSH LOGS")
|
2023-06-20 05:31:05 +00:00
|
|
|
resp = node2.query(
|
|
|
|
"SELECT partition from system.part_log where table = 'test_partition_table'"
|
|
|
|
)
|
2023-06-20 07:26:46 +00:00
|
|
|
assert resp == "202306\n202305\n"
|
2023-06-20 05:17:07 +00:00
|
|
|
|
|
|
|
|
2019-11-04 17:13:49 +00:00
|
|
|
def test_config_with_non_standard_part_log(start_cluster):
|
2020-03-05 10:49:25 +00:00
|
|
|
node3.query(
|
|
|
|
"CREATE TABLE test_table(word String, value UInt64) ENGINE=MergeTree() Order by value"
|
|
|
|
)
|
2019-11-04 17:13:49 +00:00
|
|
|
node3.query("INSERT INTO test_table VALUES ('name', 1)")
|
2020-06-01 09:12:52 +00:00
|
|
|
node3.query("SYSTEM FLUSH LOGS")
|
|
|
|
assert node3.query("SELECT * FROM system.own_part_log") != ""
|
2022-03-10 15:44:19 +00:00
|
|
|
|
2022-03-22 16:39:58 +00:00
|
|
|
|
2022-03-10 15:44:19 +00:00
|
|
|
def test_config_disk_name_test(start_cluster):
|
|
|
|
node4.query(
|
|
|
|
"CREATE TABLE test_table1(word String, value UInt64) ENGINE = MergeTree() ORDER BY word SETTINGS storage_policy = 'test1'"
|
|
|
|
)
|
|
|
|
node4.query("INSERT INTO test_table1(*) VALUES ('test1', 2)")
|
|
|
|
node4.query(
|
|
|
|
"CREATE TABLE test_table2(word String, value UInt64) ENGINE = MergeTree() ORDER BY word SETTINGS storage_policy = 'test2'"
|
|
|
|
)
|
|
|
|
node4.query("INSERT INTO test_table2(*) VALUES ('test2', 3)")
|
|
|
|
node4.query("SYSTEM FLUSH LOGS")
|
|
|
|
assert (
|
|
|
|
node4.query("SELECT DISTINCT disk_name FROM system.part_log ORDER by disk_name")
|
|
|
|
== "test1\ntest2\n"
|
2022-03-22 16:39:58 +00:00
|
|
|
)
|