mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-19 16:20:50 +00:00
Merge pull request #67362 from ClickHouse/vdimir/test_cache_evicted_by_temporary_data
Trying to fix test_cache_evicted_by_temporary_data and print debug info
This commit is contained in:
commit
7af5340e6e
@ -10,9 +10,9 @@
|
||||
<type>cache</type>
|
||||
<disk>local_disk</disk>
|
||||
<path>/tiny_local_cache/</path>
|
||||
<max_size>10M</max_size>
|
||||
<max_file_segment_size>1M</max_file_segment_size>
|
||||
<boundary_alignment>1M</boundary_alignment>
|
||||
<max_size>12M</max_size>
|
||||
<max_file_segment_size>100K</max_file_segment_size>
|
||||
<boundary_alignment>100K</boundary_alignment>
|
||||
<cache_on_write_operations>1</cache_on_write_operations>
|
||||
</tiny_local_cache>
|
||||
|
||||
|
@ -7,6 +7,9 @@ import fnmatch
|
||||
from helpers.cluster import ClickHouseCluster
|
||||
from helpers.client import QueryRuntimeException
|
||||
|
||||
|
||||
MB = 1024 * 1024
|
||||
|
||||
cluster = ClickHouseCluster(__file__)
|
||||
|
||||
node = cluster.add_instance(
|
||||
@ -36,15 +39,30 @@ def test_cache_evicted_by_temporary_data(start_cluster):
|
||||
q("SELECT sum(size) FROM system.filesystem_cache").strip()
|
||||
)
|
||||
|
||||
assert get_cache_size() == 0
|
||||
dump_debug_info = lambda: "\n".join(
|
||||
[
|
||||
">>> filesystem_cache <<<",
|
||||
q("SELECT * FROM system.filesystem_cache FORMAT Vertical"),
|
||||
">>> remote_data_paths <<<",
|
||||
q("SELECT * FROM system.remote_data_paths FORMAT Vertical"),
|
||||
">>> tiny_local_cache_local_disk <<<",
|
||||
q(
|
||||
"SELECT * FROM system.disks WHERE name = 'tiny_local_cache_local_disk' FORMAT Vertical"
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
assert get_free_space() > 8 * 1024 * 1024
|
||||
q("SYSTEM DROP FILESYSTEM CACHE")
|
||||
q("DROP TABLE IF EXISTS t1 SYNC")
|
||||
|
||||
assert get_cache_size() == 0, dump_debug_info()
|
||||
assert get_free_space() > 8 * MB, dump_debug_info()
|
||||
|
||||
# Codec is NONE to make cache size predictable
|
||||
q(
|
||||
"CREATE TABLE t1 (x UInt64 CODEC(NONE), y UInt64 CODEC(NONE)) ENGINE = MergeTree ORDER BY x SETTINGS storage_policy = 'tiny_local_cache'"
|
||||
"CREATE TABLE t1 (x UInt64 CODEC(NONE)) ENGINE = MergeTree ORDER BY x SETTINGS storage_policy = 'tiny_local_cache'"
|
||||
)
|
||||
q("INSERT INTO t1 SELECT number, number FROM numbers(1024 * 1024)")
|
||||
q("INSERT INTO t1 SELECT number FROM numbers(1024 * 1024)")
|
||||
|
||||
# To be sure that nothing is reading the cache and entries for t1 can be evited
|
||||
q("OPTIMIZE TABLE t1 FINAL")
|
||||
@ -54,11 +72,11 @@ def test_cache_evicted_by_temporary_data(start_cluster):
|
||||
q("SELECT sum(x) FROM t1")
|
||||
|
||||
cache_size_with_t1 = get_cache_size()
|
||||
assert cache_size_with_t1 > 8 * 1024 * 1024
|
||||
assert cache_size_with_t1 > 8 * MB, dump_debug_info()
|
||||
|
||||
# Almost all disk space is occupied by t1 cache
|
||||
free_space_with_t1 = get_free_space()
|
||||
assert free_space_with_t1 < 4 * 1024 * 1024
|
||||
assert free_space_with_t1 < 4 * MB, dump_debug_info()
|
||||
|
||||
# Try to sort the table, but fail because of lack of disk space
|
||||
with pytest.raises(QueryRuntimeException) as exc:
|
||||
@ -76,31 +94,27 @@ def test_cache_evicted_by_temporary_data(start_cluster):
|
||||
|
||||
# Some data evicted from cache by temporary data
|
||||
cache_size_after_eviction = get_cache_size()
|
||||
assert cache_size_after_eviction < cache_size_with_t1
|
||||
assert cache_size_after_eviction < cache_size_with_t1, dump_debug_info()
|
||||
|
||||
# Disk space freed, at least 3 MB, because temporary data tried to write 4 MB
|
||||
assert get_free_space() > free_space_with_t1 + 3 * 1024 * 1024
|
||||
assert get_free_space() > free_space_with_t1 + 3 * MB, dump_debug_info()
|
||||
|
||||
# Read some data to fill the cache again
|
||||
q("SELECT avg(y) FROM t1")
|
||||
q("SELECT avg(x) FROM t1")
|
||||
|
||||
cache_size_with_t1 = get_cache_size()
|
||||
assert cache_size_with_t1 > 8 * 1024 * 1024, q(
|
||||
"SELECT * FROM system.filesystem_cache FORMAT Vertical"
|
||||
)
|
||||
assert cache_size_with_t1 > 8 * MB, dump_debug_info()
|
||||
|
||||
# Almost all disk space is occupied by t1 cache
|
||||
free_space_with_t1 = get_free_space()
|
||||
assert free_space_with_t1 < 4 * 1024 * 1024, q(
|
||||
"SELECT * FROM system.disks WHERE name = 'tiny_local_cache_local_disk' FORMAT Vertical"
|
||||
)
|
||||
assert free_space_with_t1 < 4 * MB, dump_debug_info()
|
||||
|
||||
node.http_query(
|
||||
"SELECT randomPrintableASCII(1024) FROM numbers(8 * 1024) FORMAT TSV",
|
||||
params={"buffer_size": 0, "wait_end_of_query": 1},
|
||||
)
|
||||
|
||||
assert get_free_space() > free_space_with_t1 + 3 * 1024 * 1024
|
||||
assert get_free_space() > free_space_with_t1 + 3 * MB, dump_debug_info()
|
||||
|
||||
# not enough space for buffering 32 MB
|
||||
with pytest.raises(Exception) as exc:
|
||||
@ -112,4 +126,4 @@ def test_cache_evicted_by_temporary_data(start_cluster):
|
||||
str(exc.value), "*Failed to reserve * for temporary file*"
|
||||
), exc.value
|
||||
|
||||
q("DROP TABLE IF EXISTS t1")
|
||||
q("DROP TABLE IF EXISTS t1 SYNC")
|
||||
|
Loading…
Reference in New Issue
Block a user