Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ If this section is present, then the utility will not split binlog events the sa
- `file` - local filesystem
- `s3` - `AWS S3` or `S3`-compatible server (MinIO, etc.)
- `<storage.uri>` - specifies the location (either local or remote) where the received binary logs should be stored
- `<storage.fs_buffer_directory>` (optional) - specifies the location on the local filesystem where partially downloaded binlog files should be stored. If not specified, the value of the default OS temporary directory will be used (e.g. '/tmp' on Linux). Currently, this parameter is meaningful only for non-`file` storage backends.
- `<storage.fs_buffer_directory>` (optional) - specifies the location on the local filesystem where partially downloaded binlog files should be stored. If not specified, a unique subdirectory under the default OS temporary directory (e.g. `/tmp` on Linux) will be created and used. This auto-created directory is automatically removed when the server exits. If you set this parameter explicitly, the directory is never deleted automatically. This parameter is meaningful only for non-`file` storage backends.
- `<storage.checkpoint_size>` (optional) - specifies data portion size after receiving which backend storage should flush its internal buffers and write received binlog data permanently. If not set or set to zero, checkpointing by size will be disabled. The value is expected to be a string containing an integer followed by an optional suffix 'K' / 'M' / 'G' / 'T' / 'P', e.g. /\d+\[KMGTP\]?/:
- 'no suffix' (e.g. "42") means no multiplier, the size will be interpreted in bytes ('42 * 1' bytes)
- 'K' (e.g. "42K") means '2^10' multiplier ('42 * 1024' bytes)
Expand Down
21 changes: 16 additions & 5 deletions src/binsrv/s3_storage_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,15 @@ s3_storage_backend::s3_storage_backend(const storage_config &config)
if (opt_fs_buffer_directory.has_value()) {
tmp_file_directory_ = *opt_fs_buffer_directory;
} else {
tmp_file_directory_ = boost::uuids::to_string(uuid_generator_());
std::error_code fs_error{};
const auto tmp_directory{std::filesystem::temp_directory_path(fs_error)};
if (fs_error) {
util::exception_location().raise<std::invalid_argument>(
"unable to resolve default OS temporary directory");
}
tmp_file_directory_ =
tmp_directory / boost::uuids::to_string(uuid_generator_());
owns_tmp_file_directory_ = true;
}

const auto tmp_file_directory_status{
Expand Down Expand Up @@ -560,12 +568,15 @@ s3_storage_backend::s3_storage_backend(const storage_config &config)
}

s3_storage_backend::~s3_storage_backend() {
if (!tmp_fstream_.is_open()) {
return;
}
// bugprone-empty-catch should not be that strict in destructors
try {
close_stream_internal();
if (tmp_fstream_.is_open()) {
close_stream_internal();
}
if (owns_tmp_file_directory_) {
std::error_code remove_ec;
std::filesystem::remove_all(tmp_file_directory_, remove_ec);
}
} catch (...) { // NOLINT(bugprone-empty-catch)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/binsrv/s3_storage_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class [[nodiscard]] s3_storage_backend final : public basic_storage_backend {
std::string current_name_;
boost::uuids::random_generator uuid_generator_;
std::filesystem::path tmp_file_directory_;
bool owns_tmp_file_directory_{false};
std::filesystem::path current_tmp_file_path_;
std::fstream tmp_fstream_;

Expand Down
Loading