Skip to content

Commit 8ba43bd

Browse files
committed
Add io_buffer_size to BackupEngineOptions
1 parent 19e4aba commit 8ba43bd

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

include/rocksdb/utilities/backup_engine.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ struct BackupEngineOptions {
7777
// Default: true
7878
bool backup_log_files;
7979

80+
// Size of the buffer used for reading files.
81+
// Enables optimally configuring the IO size based on the storage backend.
82+
// If specified, takes precendence over the rate limiter burst size (if
83+
// specified) as well as kDefaultCopyFileBufferSize.
84+
// Default: 0
85+
uint64_t io_buffer_size;
86+
8087
// Max bytes that can be transferred in a second during backup.
8188
// If 0, go as fast as you can
8289
// This limit only applies to writes. To also limit reads,
@@ -228,8 +235,9 @@ struct BackupEngineOptions {
228235
const std::string& _backup_dir, Env* _backup_env = nullptr,
229236
bool _share_table_files = true, Logger* _info_log = nullptr,
230237
bool _sync = true, bool _destroy_old_data = false,
231-
bool _backup_log_files = true, uint64_t _backup_rate_limit = 0,
232-
uint64_t _restore_rate_limit = 0, int _max_background_operations = 1,
238+
bool _backup_log_files = true, uint64_t _io_buffer_size = 0,
239+
uint64_t _backup_rate_limit = 0, uint64_t _restore_rate_limit = 0,
240+
int _max_background_operations = 1,
233241
uint64_t _callback_trigger_interval_size = 4 * 1024 * 1024,
234242
int _max_valid_backups_to_open = INT_MAX,
235243
ShareFilesNaming _share_files_with_checksum_naming =
@@ -241,6 +249,7 @@ struct BackupEngineOptions {
241249
sync(_sync),
242250
destroy_old_data(_destroy_old_data),
243251
backup_log_files(_backup_log_files),
252+
io_buffer_size(_io_buffer_size),
244253
backup_rate_limit(_backup_rate_limit),
245254
restore_rate_limit(_restore_rate_limit),
246255
share_files_with_checksum(true),

utilities/backup/backup_engine.cc

+14-4
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@ class BackupEngineImpl {
581581
uint64_t* bytes_toward_next_callback,
582582
uint64_t* size, std::string* checksum_hex);
583583

584+
uint64_t CalculateIOBufferSize(RateLimiter* rate_limiter) const;
585+
584586
IOStatus ReadFileAndComputeChecksum(const std::string& src,
585587
const std::shared_ptr<FileSystem>& src_fs,
586588
const EnvOptions& src_env_options,
@@ -2212,9 +2214,7 @@ IOStatus BackupEngineImpl::CopyOrCreateFile(
22122214
return io_s;
22132215
}
22142216

2215-
size_t buf_size =
2216-
rate_limiter ? static_cast<size_t>(rate_limiter->GetSingleBurstBytes())
2217-
: kDefaultCopyFileBufferSize;
2217+
size_t buf_size = CalculateIOBufferSize(rate_limiter);
22182218

22192219
// TODO: pass in Histograms if the destination file is sst or blob
22202220
std::unique_ptr<WritableFileWriter> dest_writer(
@@ -2307,6 +2307,16 @@ IOStatus BackupEngineImpl::CopyOrCreateFile(
23072307
return io_s;
23082308
}
23092309

2310+
uint64_t BackupEngineImpl::CalculateIOBufferSize(
2311+
RateLimiter* rate_limiter) const {
2312+
if (options_.io_buffer_size > 0) {
2313+
return options_.io_buffer_size;
2314+
}
2315+
return rate_limiter != nullptr
2316+
? static_cast<size_t>(rate_limiter->GetSingleBurstBytes())
2317+
: kDefaultCopyFileBufferSize;
2318+
}
2319+
23102320
// fname will always start with "/"
23112321
IOStatus BackupEngineImpl::AddBackupFileWorkItem(
23122322
std::unordered_set<std::string>& live_dst_paths,
@@ -2588,7 +2598,7 @@ IOStatus BackupEngineImpl::ReadFileAndComputeChecksum(
25882598
return io_s;
25892599
}
25902600

2591-
size_t buf_size = kDefaultCopyFileBufferSize;
2601+
size_t buf_size = CalculateIOBufferSize(nullptr);
25922602
std::unique_ptr<char[]> buf(new char[buf_size]);
25932603
Slice data;
25942604

0 commit comments

Comments
 (0)