2021-08-16 00:00:32 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstddef>
|
2021-08-27 00:35:04 +00:00
|
|
|
#include <string>
|
2021-08-16 00:00:32 +00:00
|
|
|
#include <Core/Defines.h>
|
2022-01-13 11:57:56 +00:00
|
|
|
#include <Common/FileCache_fwd.h>
|
2022-07-11 12:59:39 +00:00
|
|
|
#include <Common/Throttler_fwd.h>
|
2021-08-16 00:00:32 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2021-09-20 13:59:44 +00:00
|
|
|
enum class LocalFSReadMethod
|
2021-08-16 00:00:32 +00:00
|
|
|
{
|
2021-09-06 15:59:46 +00:00
|
|
|
/**
|
|
|
|
* Simple synchronous reads with 'read'.
|
|
|
|
* Can use direct IO after specified size.
|
|
|
|
* Can use prefetch by asking OS to perform readahead.
|
|
|
|
*/
|
|
|
|
read,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Simple synchronous reads with 'pread'.
|
|
|
|
* In contrast to 'read', shares single file descriptor from multiple threads.
|
|
|
|
* Can use direct IO after specified size.
|
|
|
|
* Can use prefetch by asking OS to perform readahead.
|
|
|
|
*/
|
|
|
|
pread,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use mmap after specified size or simple synchronous reads with 'pread'.
|
|
|
|
* Can use prefetch by asking OS to perform readahead.
|
|
|
|
*/
|
|
|
|
mmap,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if data is in page cache with 'preadv2' on modern Linux kernels.
|
|
|
|
* If data is in page cache, read from the same thread.
|
|
|
|
* If not, offload IO to separate threadpool.
|
|
|
|
* Can do prefetch with double buffering.
|
|
|
|
* Can use specified priorities and limit the number of concurrent reads.
|
|
|
|
*/
|
|
|
|
pread_threadpool,
|
|
|
|
|
|
|
|
/// Use asynchronous reader with fake backend that in fact synchronous.
|
|
|
|
/// @attention Use only for testing purposes.
|
|
|
|
pread_fake_async
|
2021-08-16 00:00:32 +00:00
|
|
|
};
|
|
|
|
|
2021-09-20 13:59:44 +00:00
|
|
|
enum class RemoteFSReadMethod
|
|
|
|
{
|
|
|
|
read,
|
2021-11-10 07:46:18 +00:00
|
|
|
threadpool,
|
2021-09-20 13:59:44 +00:00
|
|
|
};
|
|
|
|
|
2021-08-16 00:00:32 +00:00
|
|
|
class MMappedFileCache;
|
|
|
|
|
|
|
|
struct ReadSettings
|
|
|
|
{
|
|
|
|
/// Method to use reading from local filesystem.
|
2021-09-20 13:59:44 +00:00
|
|
|
LocalFSReadMethod local_fs_method = LocalFSReadMethod::pread;
|
|
|
|
/// Method to use reading from remote filesystem.
|
2022-05-11 16:32:31 +00:00
|
|
|
RemoteFSReadMethod remote_fs_method = RemoteFSReadMethod::threadpool;
|
2021-08-16 00:00:32 +00:00
|
|
|
|
|
|
|
size_t local_fs_buffer_size = DBMS_DEFAULT_BUFFER_SIZE;
|
|
|
|
size_t remote_fs_buffer_size = DBMS_DEFAULT_BUFFER_SIZE;
|
|
|
|
|
|
|
|
bool local_fs_prefetch = false;
|
|
|
|
bool remote_fs_prefetch = false;
|
|
|
|
|
|
|
|
/// For 'read', 'pread' and 'pread_threadpool' methods.
|
|
|
|
size_t direct_io_threshold = 0;
|
|
|
|
|
|
|
|
/// For 'mmap' method.
|
|
|
|
size_t mmap_threshold = 0;
|
|
|
|
MMappedFileCache * mmap_cache = nullptr;
|
|
|
|
|
|
|
|
/// For 'pread_threadpool' method. Lower is more priority.
|
|
|
|
size_t priority = 0;
|
2021-08-24 21:45:58 +00:00
|
|
|
|
2021-10-07 13:39:54 +00:00
|
|
|
size_t remote_fs_read_max_backoff_ms = 10000;
|
|
|
|
size_t remote_fs_read_backoff_max_tries = 4;
|
2022-03-30 11:47:44 +00:00
|
|
|
bool enable_filesystem_cache = true;
|
|
|
|
size_t filesystem_cache_max_wait_sec = 1;
|
|
|
|
bool read_from_filesystem_cache_if_exists_otherwise_bypass_cache = false;
|
2022-05-03 16:16:50 +00:00
|
|
|
bool enable_filesystem_cache_log = false;
|
2022-06-05 18:36:23 +00:00
|
|
|
|
|
|
|
size_t max_query_cache_size = (128UL * 1024 * 1024 * 1024);
|
|
|
|
bool skip_download_if_exceeds_query_cache = true;
|
2021-10-07 13:39:54 +00:00
|
|
|
|
2021-10-31 19:53:24 +00:00
|
|
|
size_t remote_read_min_bytes_for_seek = DBMS_DEFAULT_BUFFER_SIZE;
|
|
|
|
|
2022-01-13 11:57:56 +00:00
|
|
|
FileCachePtr remote_fs_cache;
|
|
|
|
|
2022-07-11 12:59:39 +00:00
|
|
|
/// Bandwidth throttler to use during reading
|
2022-07-14 15:33:22 +00:00
|
|
|
ThrottlerPtr remote_throttler;
|
2022-07-11 12:59:39 +00:00
|
|
|
|
2021-10-31 14:53:08 +00:00
|
|
|
size_t http_max_tries = 1;
|
|
|
|
size_t http_retry_initial_backoff_ms = 100;
|
|
|
|
size_t http_retry_max_backoff_ms = 1600;
|
2022-02-07 19:40:47 +00:00
|
|
|
bool http_skip_not_found_url_for_globs = true;
|
2021-10-31 14:53:08 +00:00
|
|
|
|
2021-08-24 21:45:58 +00:00
|
|
|
ReadSettings adjustBufferSize(size_t file_size) const
|
|
|
|
{
|
|
|
|
ReadSettings res = *this;
|
|
|
|
res.local_fs_buffer_size = std::min(file_size, local_fs_buffer_size);
|
|
|
|
res.remote_fs_buffer_size = std::min(file_size, remote_fs_buffer_size);
|
|
|
|
return res;
|
|
|
|
}
|
2021-08-16 00:00:32 +00:00
|
|
|
};
|
2021-09-10 21:28:43 +00:00
|
|
|
|
2021-08-16 00:00:32 +00:00
|
|
|
}
|