Skip to content

Commit 5086c64

Browse files
Backport #60373 to 23.8: Detect io_uring in tests
1 parent a278225 commit 5086c64

2 files changed

Lines changed: 41 additions & 5 deletions

File tree

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/WriteHelpers.h>
2727
#include <IO/Archives/createArchiveReader.h>
2828
#include <IO/Archives/IArchiveReader.h>
29+
#include <IO/AsynchronousReadBufferFromFile.h>
30+
#include <Disks/IO/IOUringReader.h>
2931

3032
#include <DataTypes/DataTypeLowCardinality.h>
3133
#include <DataTypes/DataTypeString.h>
@@ -94,6 +96,7 @@ namespace ErrorCodes
9496
extern const int CANNOT_APPEND_TO_FILE;
9597
extern const int CANNOT_EXTRACT_TABLE_STRUCTURE;
9698
extern const int CANNOT_COMPILE_REGEXP;
99+
extern const int UNSUPPORTED_METHOD;
97100
}
98101

99102
namespace
@@ -347,6 +350,22 @@ std::unique_ptr<ReadBuffer> selectReadBuffer(
347350

348351
ProfileEvents::increment(ProfileEvents::CreatedReadBufferOrdinary);
349352
}
353+
else if (read_method == LocalFSReadMethod::io_uring && !use_table_fd)
354+
{
355+
#if USE_LIBURING
356+
auto & reader = context->getIOURingReader();
357+
if (!reader.isSupported())
358+
throw Exception(ErrorCodes::UNSUPPORTED_METHOD, "io_uring is not supported by this system");
359+
360+
res = std::make_unique<AsynchronousReadBufferFromFileWithDescriptorsCache>(
361+
reader,
362+
Priority{},
363+
current_path,
364+
context->getSettingsRef().max_read_buffer_size);
365+
#else
366+
throw Exception(ErrorCodes::UNSUPPORTED_METHOD, "Read method io_uring is only supported in Linux");
367+
#endif
368+
}
350369
else
351370
{
352371
if (use_table_fd)

tests/clickhouse-test

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import shutil
1111
import sys
1212
import os
1313
import os.path
14-
import platform
1514
import signal
1615
import re
1716
import copy
@@ -534,6 +533,27 @@ def get_localzone():
534533
return os.getenv("TZ", "/".join(os.readlink("/etc/localtime").split("/")[-2:]))
535534

536535

536+
def supports_io_uring():
537+
return not subprocess.call(
538+
[
539+
args.binary,
540+
"-q",
541+
"select * from file('/dev/null', 'LineAsString')",
542+
"--storage_file_read_method",
543+
"io_uring",
544+
],
545+
stdout=subprocess.DEVNULL,
546+
stderr=subprocess.DEVNULL,
547+
)
548+
549+
550+
def get_local_filesystem_methods():
551+
methods = ["read", "pread", "mmap", "pread_threadpool"]
552+
if supports_io_uring():
553+
methods.append("io_uring")
554+
return methods
555+
556+
537557
class SettingsRandomizer:
538558
settings = {
539559
"max_insert_threads": lambda: 0
@@ -570,10 +590,7 @@ class SettingsRandomizer:
570590
0.2, 0.5, 1, 10 * 1024 * 1024 * 1024
571591
),
572592
"local_filesystem_read_method": lambda: random.choice(
573-
# Allow to use uring only when running on Linux
574-
["read", "pread", "mmap", "pread_threadpool", "io_uring"]
575-
if platform.system().lower() == "linux"
576-
else ["read", "pread", "mmap", "pread_threadpool"]
593+
get_local_filesystem_methods()
577594
),
578595
"remote_filesystem_read_method": lambda: random.choice(["read", "threadpool"]),
579596
"local_filesystem_read_prefetch": lambda: random.randint(0, 1),

0 commit comments

Comments
 (0)