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 da39170
Show file tree
Hide file tree
Showing 2 changed files with 40 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
37 changes: 37 additions & 0 deletions utilities/backup/backup_engine_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4494,6 +4494,43 @@ 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);
// Will use 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
expected_buffer_size = 64 * 1024 * 1024;
engine_options_->io_buffer_size = 64 * 1024 * 1024;
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;
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks();
}

} // namespace

} // namespace ROCKSDB_NAMESPACE
Expand Down

0 comments on commit da39170

Please sign in to comment.