Skip to content

Commit 4d3ebb5

Browse files
PS-11205 fix: When fs_buffer_directory is not set the temporary buffer directory is created in the current binary path rather than in /tmp (#135)
https://perconadev.atlassian.net/browse/PS-11205 * Default buffer directory for S3 storage backend is now a unique subdirectory under the OS temp directory (e.g. /tmp on Linux) if '<storage.fs_buffer_directory>' configuration parameter is not set. * Auto-created temp directory is removed on storage backend destruction; user-provided directories are never deleted. * Updated README to document new behavior.
1 parent 4cefd16 commit 4d3ebb5

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ If this section is present, then the utility will not split binlog events the sa
412412
- `file` - local filesystem
413413
- `s3` - `AWS S3` or `S3`-compatible server (MinIO, etc.)
414414
- `<storage.uri>` - specifies the location (either local or remote) where the received binary logs should be stored
415-
- `<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.
415+
- `<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.
416416
- `<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\]?/:
417417
- 'no suffix' (e.g. "42") means no multiplier, the size will be interpreted in bytes ('42 * 1' bytes)
418418
- 'K' (e.g. "42K") means '2^10' multiplier ('42 * 1024' bytes)

src/binsrv/s3_storage_backend.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,15 @@ s3_storage_backend::s3_storage_backend(const storage_config &config)
490490
if (opt_fs_buffer_directory.has_value()) {
491491
tmp_file_directory_ = *opt_fs_buffer_directory;
492492
} else {
493-
tmp_file_directory_ = boost::uuids::to_string(uuid_generator_());
493+
std::error_code fs_error{};
494+
const auto tmp_directory{std::filesystem::temp_directory_path(fs_error)};
495+
if (fs_error) {
496+
util::exception_location().raise<std::invalid_argument>(
497+
"unable to resolve default OS temporary directory");
498+
}
499+
tmp_file_directory_ =
500+
tmp_directory / boost::uuids::to_string(uuid_generator_());
501+
owns_tmp_file_directory_ = true;
494502
}
495503

496504
const auto tmp_file_directory_status{
@@ -560,12 +568,15 @@ s3_storage_backend::s3_storage_backend(const storage_config &config)
560568
}
561569

562570
s3_storage_backend::~s3_storage_backend() {
563-
if (!tmp_fstream_.is_open()) {
564-
return;
565-
}
566571
// bugprone-empty-catch should not be that strict in destructors
567572
try {
568-
close_stream_internal();
573+
if (tmp_fstream_.is_open()) {
574+
close_stream_internal();
575+
}
576+
if (owns_tmp_file_directory_) {
577+
std::error_code remove_ec;
578+
std::filesystem::remove_all(tmp_file_directory_, remove_ec);
579+
}
569580
} catch (...) { // NOLINT(bugprone-empty-catch)
570581
}
571582
}

src/binsrv/s3_storage_backend.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class [[nodiscard]] s3_storage_backend final : public basic_storage_backend {
5757
std::string current_name_;
5858
boost::uuids::random_generator uuid_generator_;
5959
std::filesystem::path tmp_file_directory_;
60+
bool owns_tmp_file_directory_{false};
6061
std::filesystem::path current_tmp_file_path_;
6162
std::fstream tmp_fstream_;
6263

0 commit comments

Comments
 (0)