ring buffer selection fixes
This commit is contained in:
parent
6886f7d392
commit
b41699af5c
@ -78,6 +78,10 @@ protected:
|
||||
}
|
||||
|
||||
public:
|
||||
[[nodiscard]] static auto can_handle_file(std::uint64_t file_size,
|
||||
std::size_t chunk_size,
|
||||
std::size_t ring_size) -> bool;
|
||||
|
||||
auto close() -> bool override;
|
||||
|
||||
void forward(std::size_t count);
|
||||
|
@ -404,8 +404,18 @@ auto file_manager::open(
|
||||
}
|
||||
|
||||
if (not closeable_file) {
|
||||
const auto get_download_type = [this,
|
||||
&fsi](download_type type) -> download_type {
|
||||
auto buffer_directory =
|
||||
utils::path::combine(config_.get_data_directory(), {"buffer"});
|
||||
auto chunk_size =
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size();
|
||||
auto ring_size =
|
||||
(static_cast<std::uint64_t>(config_.get_ring_buffer_file_size() *
|
||||
1024UL * 1024UL) /
|
||||
chunk_size);
|
||||
|
||||
const auto get_download_type =
|
||||
[this, &buffer_directory, &chunk_size, &fsi,
|
||||
&ring_size](download_type type) -> download_type {
|
||||
if (fsi.size == 0U) {
|
||||
return download_type::fallback;
|
||||
}
|
||||
@ -422,8 +432,12 @@ auto file_manager::open(
|
||||
}
|
||||
}
|
||||
|
||||
auto free_space = utils::file::get_free_drive_space(
|
||||
utils::path::combine(config_.get_data_directory(), {"buffer"}));
|
||||
if (not ring_buffer_open_file::can_handle_file(fsi.size, chunk_size,
|
||||
ring_size)) {
|
||||
return download_type::direct;
|
||||
}
|
||||
|
||||
auto free_space = utils::file::get_free_drive_space(buffer_directory);
|
||||
if (config_.get_ring_buffer_file_size() < free_space) {
|
||||
return download_type::ring_buffer;
|
||||
}
|
||||
@ -431,8 +445,6 @@ auto file_manager::open(
|
||||
return download_type::direct;
|
||||
};
|
||||
|
||||
auto chunk_size =
|
||||
utils::encryption::encrypting_reader::get_data_chunk_size();
|
||||
auto chunk_timeout = config_.get_enable_download_timeout()
|
||||
? config_.get_download_timeout_secs()
|
||||
: 0U;
|
||||
@ -444,8 +456,8 @@ auto file_manager::open(
|
||||
|
||||
case repertory::download_type::ring_buffer: {
|
||||
closeable_file = std::make_shared<ring_buffer_open_file>(
|
||||
utils::path::combine(config_.get_data_directory(), {"buffer"}),
|
||||
chunk_size, chunk_timeout, fsi, provider_);
|
||||
buffer_directory, chunk_size, chunk_timeout, fsi, provider_,
|
||||
ring_size);
|
||||
} break;
|
||||
|
||||
default: {
|
||||
@ -454,9 +466,9 @@ auto file_manager::open(
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
open_file_lookup_[api_path] = closeable_file;
|
||||
create_and_add_handle(closeable_file);
|
||||
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ ring_buffer_open_file::ring_buffer_open_file(std::string buffer_directory,
|
||||
throw std::runtime_error("ring size must be greater than or equal to 4");
|
||||
}
|
||||
|
||||
if (fsi.size < (ring_state_.size() * chunk_size)) {
|
||||
if (not can_handle_file(fsi.size, chunk_size, ring_size)) {
|
||||
throw std::runtime_error("file size is less than ring buffer size");
|
||||
}
|
||||
|
||||
@ -103,6 +103,12 @@ ring_buffer_open_file::~ring_buffer_open_file() {
|
||||
}
|
||||
}
|
||||
|
||||
auto ring_buffer_open_file::can_handle_file(std::uint64_t file_size,
|
||||
std::size_t chunk_size,
|
||||
std::size_t ring_size) -> bool {
|
||||
return file_size <= (ring_size * chunk_size);
|
||||
}
|
||||
|
||||
auto ring_buffer_open_file::close() -> bool {
|
||||
stop_requested_ = true;
|
||||
return open_file_base::close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user