2020-06-01 17:16:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
2020-12-10 09:19:42 +00:00
|
|
|
#include <optional>
|
2020-09-15 09:55:57 +00:00
|
|
|
#include <vector>
|
2021-10-02 07:13:14 +00:00
|
|
|
#include <base/types.h>
|
2022-04-03 22:33:59 +00:00
|
|
|
#include <Interpreters/Context_fwd.h>
|
2022-11-17 16:35:04 +00:00
|
|
|
#include <Common/Throttler_fwd.h>
|
2022-09-13 13:07:43 +00:00
|
|
|
#include <Storages/HeaderCollection.h>
|
2020-06-01 17:16:09 +00:00
|
|
|
|
2022-09-15 07:45:28 +00:00
|
|
|
#include <IO/S3Common.h>
|
|
|
|
|
2020-06-01 17:16:09 +00:00
|
|
|
namespace Poco::Util
|
|
|
|
{
|
|
|
|
class AbstractConfiguration;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2022-04-03 22:33:59 +00:00
|
|
|
struct Settings;
|
|
|
|
|
|
|
|
struct S3Settings
|
2020-06-01 17:16:09 +00:00
|
|
|
{
|
2022-11-17 16:35:04 +00:00
|
|
|
struct RequestSettings
|
2021-03-04 15:56:55 +00:00
|
|
|
{
|
2022-04-03 22:33:59 +00:00
|
|
|
size_t max_single_read_retries = 0;
|
|
|
|
size_t min_upload_part_size = 0;
|
2022-11-02 16:53:54 +00:00
|
|
|
size_t max_upload_part_size = 0;
|
2022-04-03 22:33:59 +00:00
|
|
|
size_t upload_part_size_multiply_factor = 0;
|
|
|
|
size_t upload_part_size_multiply_parts_count_threshold = 0;
|
2022-12-09 01:17:45 +00:00
|
|
|
size_t max_part_number = 0;
|
2022-04-03 22:33:59 +00:00
|
|
|
size_t max_single_part_upload_size = 0;
|
2022-10-31 23:01:27 +00:00
|
|
|
size_t max_single_operation_copy_size = 0;
|
2022-04-03 22:33:59 +00:00
|
|
|
size_t max_connections = 0;
|
2022-08-23 13:12:09 +00:00
|
|
|
bool check_objects_after_upload = false;
|
2022-09-16 12:43:43 +00:00
|
|
|
size_t max_unexpected_write_error_retries = 0;
|
2022-11-17 16:35:04 +00:00
|
|
|
ThrottlerPtr get_request_throttler;
|
|
|
|
ThrottlerPtr put_request_throttler;
|
2022-04-06 20:27:38 +00:00
|
|
|
|
2022-11-17 16:35:04 +00:00
|
|
|
RequestSettings() = default;
|
|
|
|
explicit RequestSettings(const Settings & settings);
|
2022-04-06 20:27:38 +00:00
|
|
|
|
2022-11-17 16:35:04 +00:00
|
|
|
inline bool operator==(const RequestSettings & other) const
|
2022-04-06 20:27:38 +00:00
|
|
|
{
|
|
|
|
return max_single_read_retries == other.max_single_read_retries
|
|
|
|
&& min_upload_part_size == other.min_upload_part_size
|
2022-11-02 16:53:54 +00:00
|
|
|
&& max_upload_part_size == other.max_upload_part_size
|
2022-04-06 20:27:38 +00:00
|
|
|
&& upload_part_size_multiply_factor == other.upload_part_size_multiply_factor
|
|
|
|
&& upload_part_size_multiply_parts_count_threshold == other.upload_part_size_multiply_parts_count_threshold
|
2022-12-09 01:17:45 +00:00
|
|
|
&& max_part_number == other.max_part_number
|
2022-04-06 20:27:38 +00:00
|
|
|
&& max_single_part_upload_size == other.max_single_part_upload_size
|
2022-10-31 23:01:27 +00:00
|
|
|
&& max_single_operation_copy_size == other.max_single_operation_copy_size
|
2022-08-23 13:12:09 +00:00
|
|
|
&& max_connections == other.max_connections
|
2022-09-16 12:43:43 +00:00
|
|
|
&& check_objects_after_upload == other.check_objects_after_upload
|
2022-11-17 16:35:04 +00:00
|
|
|
&& max_unexpected_write_error_retries == other.max_unexpected_write_error_retries
|
|
|
|
&& get_request_throttler == other.get_request_throttler
|
|
|
|
&& put_request_throttler == other.put_request_throttler;
|
2022-04-06 20:27:38 +00:00
|
|
|
}
|
|
|
|
|
2022-12-09 15:21:23 +00:00
|
|
|
static const constexpr UInt64 DEFAULT_SINGLE_READ_RETRIES = 4;
|
|
|
|
static const constexpr UInt64 DEFAULT_MIN_UPLOAD_PART_SIZE = 16 * 1024 * 1024;
|
|
|
|
static const constexpr UInt64 DEFAULT_MAX_UPLOAD_PART_SIZE = 5ULL * 1024 * 1024 * 1024;
|
|
|
|
static const constexpr UInt64 DEFAULT_UPLOAD_PART_SIZE_MULTIPLY_FACTOR = 2;
|
|
|
|
static const constexpr UInt64 DEFAULT_UPLOAD_PART_SIZE_MULTIPLY_PARTS_COUNT_THRESHOLD = 500;
|
|
|
|
static const constexpr UInt64 DEFAULT_MAX_PART_NUMBER = 10000;
|
|
|
|
static const constexpr UInt64 DEFAULT_MAX_SINGLE_PART_UPLOAD_SIZE = 32 * 1024 * 1024;
|
|
|
|
static const constexpr UInt64 DEFAULT_MAX_SINGLE_OPERATION_COPY_SIZE = 5ULL * 1024 * 1024 * 1024;
|
|
|
|
static const constexpr UInt64 DEFAULT_MAX_CONNECTIONS = 1024;
|
|
|
|
static const constexpr UInt64 DEFAULT_MAX_UNEXPECTED_WRITE_ERRORS_RETRIES = 4;
|
|
|
|
|
|
|
|
void setEmptyFieldsByDefault();
|
2022-04-06 20:27:38 +00:00
|
|
|
void updateFromSettingsIfEmpty(const Settings & settings);
|
2022-04-03 22:33:59 +00:00
|
|
|
};
|
|
|
|
|
2022-09-15 07:45:28 +00:00
|
|
|
S3::AuthSettings auth_settings;
|
2022-11-17 16:35:04 +00:00
|
|
|
RequestSettings request_settings;
|
2022-04-06 20:27:38 +00:00
|
|
|
|
|
|
|
inline bool operator==(const S3Settings & other) const
|
|
|
|
{
|
2022-11-17 16:35:04 +00:00
|
|
|
return auth_settings == other.auth_settings && request_settings == other.request_settings;
|
2022-04-06 20:27:38 +00:00
|
|
|
}
|
2020-06-01 17:16:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Settings for the StorageS3.
|
|
|
|
class StorageS3Settings
|
|
|
|
{
|
|
|
|
public:
|
2022-04-03 22:33:59 +00:00
|
|
|
void loadFromConfig(const String & config_elem, const Poco::Util::AbstractConfiguration & config, const Settings & settings);
|
2020-06-01 17:16:09 +00:00
|
|
|
|
2022-04-03 22:33:59 +00:00
|
|
|
S3Settings getSettings(const String & endpoint) const;
|
2020-06-01 17:16:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
mutable std::mutex mutex;
|
2022-04-03 22:33:59 +00:00
|
|
|
std::map<const String, const S3Settings> s3_settings;
|
2020-06-01 17:16:09 +00:00
|
|
|
};
|
|
|
|
|
2022-12-09 15:21:23 +00:00
|
|
|
inline void S3Settings::RequestSettings::setEmptyFieldsByDefault()
|
|
|
|
{
|
|
|
|
if (!max_single_read_retries)
|
|
|
|
max_single_read_retries = DEFAULT_SINGLE_READ_RETRIES;
|
|
|
|
if (!min_upload_part_size)
|
|
|
|
min_upload_part_size = DEFAULT_MIN_UPLOAD_PART_SIZE;
|
|
|
|
if (!max_upload_part_size)
|
|
|
|
max_upload_part_size = DEFAULT_MAX_UPLOAD_PART_SIZE;
|
|
|
|
if (!upload_part_size_multiply_factor)
|
|
|
|
upload_part_size_multiply_factor = DEFAULT_UPLOAD_PART_SIZE_MULTIPLY_FACTOR;
|
|
|
|
if (!upload_part_size_multiply_parts_count_threshold)
|
|
|
|
upload_part_size_multiply_parts_count_threshold = DEFAULT_UPLOAD_PART_SIZE_MULTIPLY_PARTS_COUNT_THRESHOLD;
|
|
|
|
if (!max_part_number)
|
|
|
|
max_part_number = DEFAULT_MAX_PART_NUMBER;
|
|
|
|
if (!max_single_part_upload_size)
|
|
|
|
max_single_part_upload_size = DEFAULT_MAX_SINGLE_PART_UPLOAD_SIZE;
|
|
|
|
if (!max_single_operation_copy_size)
|
|
|
|
max_single_operation_copy_size = DEFAULT_MAX_SINGLE_OPERATION_COPY_SIZE;
|
|
|
|
if (!max_connections)
|
|
|
|
max_connections = DEFAULT_MAX_CONNECTIONS;
|
|
|
|
if (!max_unexpected_write_error_retries)
|
|
|
|
max_unexpected_write_error_retries = DEFAULT_MAX_UNEXPECTED_WRITE_ERRORS_RETRIES;
|
|
|
|
}
|
|
|
|
|
2020-06-01 17:16:09 +00:00
|
|
|
}
|