Skip to content

Commit a225dfc

Browse files
Backport #60373 to 24.1: Detect io_uring in tests
1 parent bba8b3b commit a225dfc

2 files changed

Lines changed: 42 additions & 6 deletions

File tree

src/Storages/StorageFile.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
#include <IO/WriteBufferFromFile.h>
2525
#include <IO/WriteHelpers.h>
2626
#include <IO/Archives/createArchiveReader.h>
27-
#include <IO/Archives/IArchiveReader.h>
27+
#include <IO/AsynchronousReadBufferFromFile.h>
28+
#include <Disks/IO/IOUringReader.h>
29+
2830

2931
#include <Formats/FormatFactory.h>
3032
#include <Formats/ReadSchemaUtils.h>
@@ -90,6 +92,7 @@ namespace ErrorCodes
9092
extern const int CANNOT_APPEND_TO_FILE;
9193
extern const int CANNOT_EXTRACT_TABLE_STRUCTURE;
9294
extern const int CANNOT_COMPILE_REGEXP;
95+
extern const int UNSUPPORTED_METHOD;
9396
}
9497

9598
namespace
@@ -274,6 +277,22 @@ std::unique_ptr<ReadBuffer> selectReadBuffer(
274277

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

tests/clickhouse-test

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import itertools
1212
import sys
1313
import os
1414
import os.path
15-
import platform
1615
import signal
1716
import re
1817
import copy
@@ -563,6 +562,27 @@ def get_localzone():
563562
return os.getenv("TZ", "/".join(os.readlink("/etc/localtime").split("/")[-2:]))
564563

565564

565+
def supports_io_uring():
566+
return not subprocess.call(
567+
[
568+
args.binary,
569+
"-q",
570+
"select * from file('/dev/null', 'LineAsString')",
571+
"--storage_file_read_method",
572+
"io_uring",
573+
],
574+
stdout=subprocess.DEVNULL,
575+
stderr=subprocess.DEVNULL,
576+
)
577+
578+
579+
def get_local_filesystem_methods():
580+
methods = ["read", "pread", "mmap", "pread_threadpool"]
581+
if supports_io_uring():
582+
methods.append("io_uring")
583+
return methods
584+
585+
566586
class SettingsRandomizer:
567587
settings = {
568588
"max_insert_threads": lambda: 0
@@ -603,10 +623,7 @@ class SettingsRandomizer:
603623
0.2, 0.5, 1, 10 * 1024 * 1024 * 1024
604624
),
605625
"local_filesystem_read_method": lambda: random.choice(
606-
# Allow to use uring only when running on Linux
607-
["read", "pread", "mmap", "pread_threadpool", "io_uring"]
608-
if platform.system().lower() == "linux"
609-
else ["read", "pread", "mmap", "pread_threadpool"]
626+
get_local_filesystem_methods()
610627
),
611628
"remote_filesystem_read_method": lambda: random.choice(["read", "threadpool"]),
612629
"local_filesystem_read_prefetch": lambda: random.randint(0, 1),

0 commit comments

Comments
 (0)