mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 23:52:03 +00:00
Merge pull request #61319 from ClickHouse/fix-false-positive-assertion-in-cache
Fix false positive assertion in cache
This commit is contained in:
commit
a84f2ea078
@ -7,4 +7,8 @@
|
||||
</hdd_blob>
|
||||
</disks>
|
||||
</storage_configuration>
|
||||
<filesystem_cache_log>
|
||||
<database>system</database>
|
||||
<table>filesystem_cache_log</table>
|
||||
</filesystem_cache_log>
|
||||
</clickhouse>
|
||||
|
@ -426,3 +426,78 @@ def test_force_filesystem_cache_on_merges(cluster):
|
||||
test(node, True)
|
||||
node = cluster.instances["node"]
|
||||
test(node, False)
|
||||
|
||||
|
||||
def test_system_sync_filesystem_cache(cluster):
|
||||
node = cluster.instances["node"]
|
||||
node.query(
|
||||
"""
|
||||
DROP TABLE IF EXISTS test;
|
||||
|
||||
CREATE TABLE test (a Int32, b String)
|
||||
ENGINE = MergeTree() ORDER BY tuple()
|
||||
SETTINGS disk = disk(type = cache,
|
||||
max_size = '100Ki',
|
||||
path = "test_system_sync_filesystem_cache",
|
||||
delayed_cleanup_interval_ms = 10000000, disk = hdd_blob),
|
||||
min_bytes_for_wide_part = 10485760;
|
||||
|
||||
INSERT INTO test SELECT 1, 'test';
|
||||
"""
|
||||
)
|
||||
|
||||
query_id = "system_sync_filesystem_cache_1"
|
||||
node.query(
|
||||
"SELECT * FROM test FORMAT Null SETTINGS enable_filesystem_cache_log = 1",
|
||||
query_id=query_id,
|
||||
)
|
||||
|
||||
key, offset = (
|
||||
node.query(
|
||||
f"""
|
||||
SYSTEM FLUSH LOGS;
|
||||
SELECT key, offset FROM system.filesystem_cache_log WHERE query_id = '{query_id}' ORDER BY size DESC LIMIT 1;
|
||||
"""
|
||||
)
|
||||
.strip()
|
||||
.split("\t")
|
||||
)
|
||||
|
||||
cache_path = node.query(
|
||||
f"SELECT cache_path FROM system.filesystem_cache WHERE key = '{key}' and file_segment_range_begin = {offset}"
|
||||
)
|
||||
|
||||
node.exec_in_container(["bash", "-c", f"rm {cache_path}"])
|
||||
|
||||
assert key in node.query("SYSTEM SYNC FILESYSTEM CACHE")
|
||||
|
||||
node.query("SELECT * FROM test FORMAT Null")
|
||||
assert key not in node.query("SYSTEM SYNC FILESYSTEM CACHE")
|
||||
|
||||
query_id = "system_sync_filesystem_cache_2"
|
||||
node.query(
|
||||
"SELECT * FROM test FORMAT Null SETTINGS enable_filesystem_cache_log = 1",
|
||||
query_id=query_id,
|
||||
)
|
||||
|
||||
key, offset = (
|
||||
node.query(
|
||||
f"""
|
||||
SYSTEM FLUSH LOGS;
|
||||
SELECT key, offset FROM system.filesystem_cache_log WHERE query_id = '{query_id}' ORDER BY size DESC LIMIT 1;
|
||||
"""
|
||||
)
|
||||
.strip()
|
||||
.split("\t")
|
||||
)
|
||||
cache_path = node.query(
|
||||
f"SELECT cache_path FROM system.filesystem_cache WHERE key = '{key}' and file_segment_range_begin = {offset}"
|
||||
)
|
||||
|
||||
node.exec_in_container(["bash", "-c", f"echo -n 'fff' > {cache_path}"])
|
||||
|
||||
assert key in node.query("SYSTEM SYNC FILESYSTEM CACHE")
|
||||
|
||||
node.query("SELECT * FROM test FORMAT Null")
|
||||
|
||||
assert key not in node.query("SYSTEM SYNC FILESYSTEM CACHE")
|
||||
|
@ -1,3 +0,0 @@
|
||||
ok
|
||||
ok
|
||||
ok
|
@ -1,69 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Tags: no-fasttest, no-parallel, no-s3-storage, no-random-settings
|
||||
|
||||
# set -x
|
||||
|
||||
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
# shellcheck source=../shell_config.sh
|
||||
. "$CUR_DIR"/../shell_config.sh
|
||||
|
||||
|
||||
$CLICKHOUSE_CLIENT -nm --query """
|
||||
DROP TABLE IF EXISTS test;
|
||||
|
||||
CREATE TABLE test (a Int32, b String)
|
||||
ENGINE = MergeTree() ORDER BY tuple()
|
||||
SETTINGS disk = disk(type = cache, max_size = '100Ki', path = ${CLICKHOUSE_TEST_UNIQUE_NAME}, delayed_cleanup_interval_ms = 10000000, disk = s3_disk), min_bytes_for_wide_part = 10485760;
|
||||
|
||||
INSERT INTO test SELECT 1, 'test';
|
||||
"""
|
||||
|
||||
query_id=$RANDOM
|
||||
|
||||
$CLICKHOUSE_CLIENT --query_id "$query_id" --query "SELECT * FROM test FORMAT Null SETTINGS enable_filesystem_cache_log = 1"
|
||||
|
||||
${CLICKHOUSE_CLIENT} -q "system flush logs"
|
||||
|
||||
key=$($CLICKHOUSE_CLIENT -nm --query """
|
||||
SELECT key FROM system.filesystem_cache_log WHERE query_id = '$query_id' ORDER BY size DESC LIMIT 1;
|
||||
""")
|
||||
|
||||
offset=$($CLICKHOUSE_CLIENT -nm --query """
|
||||
SELECT offset FROM system.filesystem_cache_log WHERE query_id = '$query_id' ORDER BY size DESC LIMIT 1;
|
||||
""")
|
||||
|
||||
path=$($CLICKHOUSE_CLIENT -nm --query """
|
||||
SELECT cache_path FROM system.filesystem_cache WHERE key = '$key' AND file_segment_range_begin = $offset;
|
||||
""")
|
||||
|
||||
rm $path
|
||||
|
||||
$CLICKHOUSE_CLIENT --query "SELECT * FROM test FORMAT Null SETTINGS enable_filesystem_cache_log = 1" 2>&1 | grep -F -e "No such file or directory" > /dev/null && echo "ok" || echo "fail"
|
||||
|
||||
CLICKHOUSE_CLIENT=$(echo ${CLICKHOUSE_CLIENT} | sed 's/'"--send_logs_level=${CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL}"'/--send_logs_level=fatal/g')
|
||||
|
||||
$CLICKHOUSE_CLIENT --query "SYSTEM SYNC FILESYSTEM CACHE" 2>&1 | grep -q "$key" && echo 'ok' || echo 'fail'
|
||||
|
||||
$CLICKHOUSE_CLIENT --query "SELECT * FROM test FORMAT Null"
|
||||
|
||||
key=$($CLICKHOUSE_CLIENT -nm --query """
|
||||
SELECT key FROM system.filesystem_cache_log WHERE query_id = '$query_id' ORDER BY size DESC LIMIT 1;
|
||||
""")
|
||||
|
||||
offset=$($CLICKHOUSE_CLIENT -nm --query """
|
||||
SELECT offset FROM system.filesystem_cache_log WHERE query_id = '$query_id' ORDER BY size DESC LIMIT 1;
|
||||
""")
|
||||
|
||||
path=$($CLICKHOUSE_CLIENT -nm --query """
|
||||
SELECT cache_path FROM system.filesystem_cache WHERE key = '$key' AND file_segment_range_begin = $offset;
|
||||
""")
|
||||
|
||||
echo -n 'fff' > $path
|
||||
|
||||
#cat $path
|
||||
|
||||
$CLICKHOUSE_CLIENT --query "SYSTEM SYNC FILESYSTEM CACHE" 2>&1 | grep -q "$key" && echo 'ok' || echo 'fail'
|
||||
|
||||
$CLICKHOUSE_CLIENT --query "SELECT * FROM test FORMAT Null"
|
||||
|
||||
$CLICKHOUSE_CLIENT --query "SYSTEM SYNC FILESYSTEM CACHE"
|
Loading…
Reference in New Issue
Block a user