Skip to content

Commit

Permalink
Add test to BackupEngineTest
Browse files Browse the repository at this point in the history
  • Loading branch information
archang19 committed Dec 20, 2024
1 parent 8ba43bd commit 1316c31
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
3 changes: 3 additions & 0 deletions utilities/backup/backup_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<WritableFileWriter> dest_writer(
Expand Down Expand Up @@ -2599,6 +2601,7 @@ IOStatus BackupEngineImpl::ReadFileAndComputeChecksum(
}

size_t buf_size = CalculateIOBufferSize(nullptr);

std::unique_ptr<char[]> buf(new char[buf_size]);
Slice data;

Expand Down
53 changes: 53 additions & 0 deletions utilities/backup/backup_engine_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t*>(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<RateLimiter> 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
Expand Down

0 comments on commit 1316c31

Please sign in to comment.