diff --git a/utilities/backup/backup_engine.cc b/utilities/backup/backup_engine.cc index 8f9667ee554f..3fd2a8d5bcb2 100644 --- a/utilities/backup/backup_engine.cc +++ b/utilities/backup/backup_engine.cc @@ -2215,6 +2215,8 @@ IOStatus BackupEngineImpl::CopyOrCreateFile( } size_t buf_size = CalculateIOBufferSize(rate_limiter); + TEST_SYNC_POINT_CALLBACK( + "BackupEngineImpl::CopyOrCreateFile:CalculateIOBufferSize", &buf_size); // TODO: pass in Histograms if the destination file is sst or blob std::unique_ptr dest_writer( @@ -2599,6 +2601,7 @@ IOStatus BackupEngineImpl::ReadFileAndComputeChecksum( } size_t buf_size = CalculateIOBufferSize(nullptr); + std::unique_ptr buf(new char[buf_size]); Slice data; diff --git a/utilities/backup/backup_engine_test.cc b/utilities/backup/backup_engine_test.cc index 62dda66fcdf2..f9db3a0f2a62 100644 --- a/utilities/backup/backup_engine_test.cc +++ b/utilities/backup/backup_engine_test.cc @@ -4494,6 +4494,59 @@ TEST_F(BackupEngineTest, ExcludeFiles) { delete alt_backup_engine; } +TEST_F(BackupEngineTest, IOBufferSize) { + size_t expected_buffer_size = 5 * 1024 * 1024; + bool io_buffer_size_calculated = false; + SyncPoint::GetInstance()->SetCallBack( + "BackupEngineImpl::CopyOrCreateFile:CalculateIOBufferSize", + [&](void* data) { + if (data != nullptr) { + EXPECT_EQ(expected_buffer_size, *static_cast(data)); + } + io_buffer_size_calculated = true; + }); + ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing(); + + const int keys_iteration = 5000; + Random rnd(6); + // With no overrides, fall back to the default buffer size of 5 MB + OpenDBAndBackupEngine(true /* destroy_old_data */); + FillDB(db_.get(), 0, keys_iteration); + ASSERT_OK(backup_engine_->CreateNewBackup(db_.get(), false)); + ASSERT_TRUE(io_buffer_size_calculated); + CloseDBAndBackupEngine(); + + // Override the default buffer size with 64 MB through BackupEngineOptions + expected_buffer_size = 64 * 1024 * 1024; + engine_options_->io_buffer_size = expected_buffer_size; + io_buffer_size_calculated = false; + OpenDBAndBackupEngine(true /* destroy_old_data */); + FillDB(db_.get(), 0, keys_iteration); + ASSERT_OK(backup_engine_->CreateNewBackup(db_.get(), false)); + ASSERT_TRUE(io_buffer_size_calculated); + CloseDBAndBackupEngine(); + engine_options_->io_buffer_size = 0; + + // Without io_buffer_size specified, the rate limiter burst bytes value will + // be used (16 MB in this example) + expected_buffer_size = 16 * 1024 * 1024; + std::shared_ptr backup_rate_limiter(NewGenericRateLimiter( + 5 * 1024 * 1024 /* rate_bytes_per_sec */, + 100 * 1000 /* refill_period_us */, 10 /* fairness */, + RateLimiter::Mode::kWritesOnly /* mode */, false /* auto_tuned */, + expected_buffer_size /* single_burst_bytes */)); + engine_options_->backup_rate_limiter = backup_rate_limiter; + io_buffer_size_calculated = false; + OpenDBAndBackupEngine(true /* destroy_old_data */); + FillDB(db_.get(), 0, keys_iteration); + ASSERT_OK(backup_engine_->CreateNewBackup(db_.get(), false)); + ASSERT_TRUE(io_buffer_size_calculated); + CloseDBAndBackupEngine(); + + ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing(); + ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks(); +} + } // namespace } // namespace ROCKSDB_NAMESPACE