Skip to content

Commit 648e6ec

Browse files
Merge pull request ClickHouse#60373 from azat/tests/detect-io_uring
Detect io_uring in tests
2 parents 273b483 + 554d993 commit 648e6ec

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

src/Storages/StorageFile.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <IO/Archives/createArchiveReader.h>
2727
#include <IO/Archives/IArchiveReader.h>
2828
#include <IO/PeekableReadBuffer.h>
29+
#include <IO/AsynchronousReadBufferFromFile.h>
30+
#include <Disks/IO/IOUringReader.h>
2931

3032
#include <Formats/FormatFactory.h>
3133
#include <Formats/ReadSchemaUtils.h>
@@ -92,6 +94,7 @@ namespace ErrorCodes
9294
extern const int CANNOT_EXTRACT_TABLE_STRUCTURE;
9395
extern const int CANNOT_DETECT_FORMAT;
9496
extern const int CANNOT_COMPILE_REGEXP;
97+
extern const int UNSUPPORTED_METHOD;
9598
}
9699

97100
namespace
@@ -276,6 +279,22 @@ std::unique_ptr<ReadBuffer> selectReadBuffer(
276279

277280
ProfileEvents::increment(ProfileEvents::CreatedReadBufferOrdinary);
278281
}
282+
else if (read_method == LocalFSReadMethod::io_uring && !use_table_fd)
283+
{
284+
#if USE_LIBURING
285+
auto & reader = context->getIOURingReader();
286+
if (!reader.isSupported())
287+
throw Exception(ErrorCodes::UNSUPPORTED_METHOD, "io_uring is not supported by this system");
288+
289+
res = std::make_unique<AsynchronousReadBufferFromFileWithDescriptorsCache>(
290+
reader,
291+
Priority{},
292+
current_path,
293+
context->getSettingsRef().max_read_buffer_size);
294+
#else
295+
throw Exception(ErrorCodes::UNSUPPORTED_METHOD, "Read method io_uring is only supported in Linux");
296+
#endif
297+
}
279298
else
280299
{
281300
if (use_table_fd)

tests/clickhouse-test

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import sys
1313
import os
1414
import os.path
1515
import glob
16-
import platform
1716
import signal
1817
import re
1918
import copy
@@ -574,6 +573,27 @@ def get_localzone():
574573
return os.getenv("TZ", "/".join(os.readlink("/etc/localtime").split("/")[-2:]))
575574

576575

576+
def supports_io_uring():
577+
return not subprocess.call(
578+
[
579+
args.binary,
580+
"-q",
581+
"select * from file('/dev/null', 'LineAsString')",
582+
"--storage_file_read_method",
583+
"io_uring",
584+
],
585+
stdout=subprocess.DEVNULL,
586+
stderr=subprocess.DEVNULL,
587+
)
588+
589+
590+
def get_local_filesystem_methods():
591+
methods = ["read", "pread", "mmap", "pread_threadpool"]
592+
if supports_io_uring():
593+
methods.append("io_uring")
594+
return methods
595+
596+
577597
class SettingsRandomizer:
578598
settings = {
579599
"max_insert_threads": lambda: 0
@@ -614,10 +634,7 @@ class SettingsRandomizer:
614634
0.2, 0.5, 1, 10 * 1024 * 1024 * 1024
615635
),
616636
"local_filesystem_read_method": lambda: random.choice(
617-
# Allow to use uring only when running on Linux
618-
["read", "pread", "mmap", "pread_threadpool", "io_uring"]
619-
if platform.system().lower() == "linux"
620-
else ["read", "pread", "mmap", "pread_threadpool"]
637+
get_local_filesystem_methods()
621638
),
622639
"remote_filesystem_read_method": lambda: random.choice(["read", "threadpool"]),
623640
"local_filesystem_read_prefetch": lambda: random.randint(0, 1),

0 commit comments

Comments
 (0)