mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-19 16:20:50 +00:00
Added integration testing for newly implemented settings.
This commit is contained in:
parent
ddc506a677
commit
5cc12ca9ee
@ -562,7 +562,7 @@ MergeTreeDataWriter::TemporaryPart MergeTreeDataWriter::writeTempPartImpl(
|
||||
|
||||
const auto disk = data_part_volume->getDisk();
|
||||
const UInt64 total_disk_bytes = *disk->getTotalSpace();
|
||||
const UInt64 free_disk_bytes = *disk->getUnreservedSpace();
|
||||
const UInt64 free_disk_bytes = *disk->getAvailableSpace();
|
||||
|
||||
const UInt64 min_bytes_from_ratio = static_cast<UInt64>(min_ratio * total_disk_bytes);
|
||||
const UInt64 needed_free_bytes = std::max(min_bytes, min_bytes_from_ratio);
|
||||
@ -571,9 +571,10 @@ MergeTreeDataWriter::TemporaryPart MergeTreeDataWriter::writeTempPartImpl(
|
||||
{
|
||||
throw Exception(
|
||||
ErrorCodes::NOT_ENOUGH_SPACE,
|
||||
"Could not perform insert: less than {} free bytes in disk space. "
|
||||
"Could not perform insert: less than {} free bytes in disk space ({}). "
|
||||
"Configure this limit with user settings {} or {}",
|
||||
needed_free_bytes,
|
||||
free_disk_bytes,
|
||||
"min_free_disk_bytes_to_throw_insert",
|
||||
"min_free_disk_ratio_to_throw_insert");
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
<clickhouse>
|
||||
<storage_configuration>
|
||||
<disks>
|
||||
<disk1>
|
||||
<type>local</type>
|
||||
<path>/disk1/</path>
|
||||
</disk1>
|
||||
</disks>
|
||||
<policies>
|
||||
<only_disk1>
|
||||
<volumes>
|
||||
<main>
|
||||
<disk>disk1</disk>
|
||||
</main>
|
||||
</volumes>
|
||||
</only_disk1>
|
||||
</policies>
|
||||
</storage_configuration>
|
||||
</clickhouse>
|
@ -0,0 +1,51 @@
|
||||
import pytest
|
||||
from helpers.cluster import ClickHouseCluster, ClickHouseInstance
|
||||
from helpers.client import QueryRuntimeException
|
||||
|
||||
cluster = ClickHouseCluster(__file__)
|
||||
|
||||
node = cluster.add_instance(
|
||||
"node",
|
||||
main_configs=["configs/config.d/storage_configuration.xml"],
|
||||
tmpfs=["/disk1:size=100M"],
|
||||
macros={"shard": 0, "replica": 1},
|
||||
)
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def start_cluster():
|
||||
try:
|
||||
cluster.start()
|
||||
yield cluster
|
||||
finally:
|
||||
cluster.shutdown()
|
||||
|
||||
def test_insert_stops_when_disk_full(start_cluster):
|
||||
min_free_bytes = 3 * 1024 * 1024 # 3 MiB
|
||||
|
||||
node.query(f"""
|
||||
CREATE TABLE test_table (
|
||||
id UInt32,
|
||||
data String
|
||||
) ENGINE = MergeTree()
|
||||
ORDER BY id
|
||||
SETTINGS storage_policy = 'only_disk1', min_free_disk_bytes_to_throw_insert = {min_free_bytes}
|
||||
""")
|
||||
|
||||
count = 0
|
||||
|
||||
# Insert data to fill up disk
|
||||
try:
|
||||
for _ in range(100000):
|
||||
node.query("INSERT INTO test_table SELECT number, repeat('a', 1000 * 1000) FROM numbers(1)")
|
||||
count += 1
|
||||
except QueryRuntimeException as e:
|
||||
assert "Could not perform insert" in str(e)
|
||||
assert "free bytes in disk space" in str(e)
|
||||
|
||||
free_space = int(node.query("SELECT free_space FROM system.disks WHERE name = 'disk1'").strip())
|
||||
assert free_space <= min_free_bytes, f"Free space ({free_space}) is less than min_free_bytes ({min_free_bytes})"
|
||||
|
||||
rows = int(node.query("SELECT count() from test_table").strip())
|
||||
assert rows == count
|
||||
|
||||
node.query("DROP TABLE test_table")
|
Loading…
Reference in New Issue
Block a user