#include "db/blob/blob_index.h"
#include "db/blob/blob_log_format.h"
#include "db/blob/blob_log_sequential_reader.h"
-#include "env/composite_env_wrapper.h"
#include "env/mock_env.h"
#include "file/filename.h"
#include "file/random_access_file_reader.h"
class BlobFileBuilderTest : public testing::Test {
protected:
- BlobFileBuilderTest() : mock_env_(Env::Default()), fs_(&mock_env_) {}
+ BlobFileBuilderTest() {
+ mock_env_.reset(MockEnv::Create(Env::Default()));
+ fs_ = mock_env_->GetFileSystem().get();
+ clock_ = mock_env_->GetSystemClock().get();
+ }
void VerifyBlobFile(uint64_t blob_file_number,
const std::string& blob_file_path,
std::unique_ptr<FSRandomAccessFile> file;
constexpr IODebugContext* dbg = nullptr;
ASSERT_OK(
- fs_.NewRandomAccessFile(blob_file_path, file_options_, &file, dbg));
+ fs_->NewRandomAccessFile(blob_file_path, file_options_, &file, dbg));
std::unique_ptr<RandomAccessFileReader> file_reader(
- new RandomAccessFileReader(std::move(file), blob_file_path,
- &mock_env_));
+ new RandomAccessFileReader(std::move(file), blob_file_path, clock_));
constexpr Statistics* statistics = nullptr;
- BlobLogSequentialReader blob_log_reader(std::move(file_reader), &mock_env_,
+ BlobLogSequentialReader blob_log_reader(std::move(file_reader), clock_,
statistics);
BlobLogHeader header;
ASSERT_EQ(footer.expiration_range, ExpirationRange());
}
- MockEnv mock_env_;
- LegacyFileSystemWrapper fs_;
+ std::unique_ptr<Env> mock_env_;
+ FileSystem* fs_;
+ SystemClock* clock_;
FileOptions file_options_;
};
Options options;
options.cf_paths.emplace_back(
- test::PerThreadDBPath(&mock_env_,
+ test::PerThreadDBPath(mock_env_.get(),
"BlobFileBuilderTest_BuildAndCheckOneFile"),
0);
options.enable_blob_files = true;
+ options.env = mock_env_.get();
- ImmutableCFOptions immutable_cf_options(options);
+ ImmutableOptions immutable_options(options);
MutableCFOptions mutable_cf_options(options);
constexpr int job_id = 1;
std::vector<std::string> blob_file_paths;
std::vector<BlobFileAddition> blob_file_additions;
- BlobFileBuilder builder(TestFileNumberGenerator(), &mock_env_, &fs_,
- &immutable_cf_options, &mutable_cf_options,
- &file_options_, job_id, column_family_id,
- column_family_name, io_priority, write_hint,
- &blob_file_paths, &blob_file_additions);
+ BlobFileBuilder builder(
+ TestFileNumberGenerator(), fs_, &immutable_options, &mutable_cf_options,
+ &file_options_, "" /*db_id*/, "" /*db_session_id*/, job_id,
+ column_family_id, column_family_name, io_priority, write_hint,
+ nullptr /*IOTracer*/, nullptr /*BlobFileCompletionCallback*/,
+ BlobFileCreationReason::kFlush, &blob_file_paths, &blob_file_additions);
std::vector<std::pair<std::string, std::string>> expected_key_value_pairs(
number_of_blobs);
const std::string& blob_file_path = blob_file_paths[0];
- ASSERT_EQ(blob_file_path,
- BlobFileName(immutable_cf_options.cf_paths.front().path,
- blob_file_number));
+ ASSERT_EQ(
+ blob_file_path,
+ BlobFileName(immutable_options.cf_paths.front().path, blob_file_number));
ASSERT_EQ(blob_file_additions.size(), 1);
Options options;
options.cf_paths.emplace_back(
- test::PerThreadDBPath(&mock_env_,
+ test::PerThreadDBPath(mock_env_.get(),
"BlobFileBuilderTest_BuildAndCheckMultipleFiles"),
0);
options.enable_blob_files = true;
options.blob_file_size = value_size;
+ options.env = mock_env_.get();
- ImmutableCFOptions immutable_cf_options(options);
+ ImmutableOptions immutable_options(options);
MutableCFOptions mutable_cf_options(options);
constexpr int job_id = 1;
std::vector<std::string> blob_file_paths;
std::vector<BlobFileAddition> blob_file_additions;
- BlobFileBuilder builder(TestFileNumberGenerator(), &mock_env_, &fs_,
- &immutable_cf_options, &mutable_cf_options,
- &file_options_, job_id, column_family_id,
- column_family_name, io_priority, write_hint,
- &blob_file_paths, &blob_file_additions);
+ BlobFileBuilder builder(
+ TestFileNumberGenerator(), fs_, &immutable_options, &mutable_cf_options,
+ &file_options_, "" /*db_id*/, "" /*db_session_id*/, job_id,
+ column_family_id, column_family_name, io_priority, write_hint,
+ nullptr /*IOTracer*/, nullptr /*BlobFileCompletionCallback*/,
+ BlobFileCreationReason::kFlush, &blob_file_paths, &blob_file_additions);
std::vector<std::pair<std::string, std::string>> expected_key_value_pairs(
number_of_blobs);
const uint64_t blob_file_number = i + 2;
ASSERT_EQ(blob_file_paths[i],
- BlobFileName(immutable_cf_options.cf_paths.front().path,
+ BlobFileName(immutable_options.cf_paths.front().path,
blob_file_number));
const auto& blob_file_addition = blob_file_additions[i];
Options options;
options.cf_paths.emplace_back(
- test::PerThreadDBPath(&mock_env_, "BlobFileBuilderTest_InlinedValues"),
+ test::PerThreadDBPath(mock_env_.get(),
+ "BlobFileBuilderTest_InlinedValues"),
0);
options.enable_blob_files = true;
options.min_blob_size = 1024;
+ options.env = mock_env_.get();
- ImmutableCFOptions immutable_cf_options(options);
+ ImmutableOptions immutable_options(options);
MutableCFOptions mutable_cf_options(options);
constexpr int job_id = 1;
std::vector<std::string> blob_file_paths;
std::vector<BlobFileAddition> blob_file_additions;
- BlobFileBuilder builder(TestFileNumberGenerator(), &mock_env_, &fs_,
- &immutable_cf_options, &mutable_cf_options,
- &file_options_, job_id, column_family_id,
- column_family_name, io_priority, write_hint,
- &blob_file_paths, &blob_file_additions);
+ BlobFileBuilder builder(
+ TestFileNumberGenerator(), fs_, &immutable_options, &mutable_cf_options,
+ &file_options_, "" /*db_id*/, "" /*db_session_id*/, job_id,
+ column_family_id, column_family_name, io_priority, write_hint,
+ nullptr /*IOTracer*/, nullptr /*BlobFileCompletionCallback*/,
+ BlobFileCreationReason::kFlush, &blob_file_paths, &blob_file_additions);
for (size_t i = 0; i < number_of_blobs; ++i) {
const std::string key = std::to_string(i);
Options options;
options.cf_paths.emplace_back(
- test::PerThreadDBPath(&mock_env_, "BlobFileBuilderTest_Compression"), 0);
+ test::PerThreadDBPath(mock_env_.get(), "BlobFileBuilderTest_Compression"),
+ 0);
options.enable_blob_files = true;
options.blob_compression_type = kSnappyCompression;
+ options.env = mock_env_.get();
- ImmutableCFOptions immutable_cf_options(options);
+ ImmutableOptions immutable_options(options);
MutableCFOptions mutable_cf_options(options);
constexpr int job_id = 1;
std::vector<std::string> blob_file_paths;
std::vector<BlobFileAddition> blob_file_additions;
- BlobFileBuilder builder(TestFileNumberGenerator(), &mock_env_, &fs_,
- &immutable_cf_options, &mutable_cf_options,
- &file_options_, job_id, column_family_id,
- column_family_name, io_priority, write_hint,
- &blob_file_paths, &blob_file_additions);
+ BlobFileBuilder builder(
+ TestFileNumberGenerator(), fs_, &immutable_options, &mutable_cf_options,
+ &file_options_, "" /*db_id*/, "" /*db_session_id*/, job_id,
+ column_family_id, column_family_name, io_priority, write_hint,
+ nullptr /*IOTracer*/, nullptr /*BlobFileCompletionCallback*/,
+ BlobFileCreationReason::kFlush, &blob_file_paths, &blob_file_additions);
const std::string key("1");
const std::string uncompressed_value(value_size, 'x');
const std::string& blob_file_path = blob_file_paths[0];
- ASSERT_EQ(blob_file_path,
- BlobFileName(immutable_cf_options.cf_paths.front().path,
- blob_file_number));
+ ASSERT_EQ(
+ blob_file_path,
+ BlobFileName(immutable_options.cf_paths.front().path, blob_file_number));
ASSERT_EQ(blob_file_additions.size(), 1);
Options options;
options.cf_paths.emplace_back(
- test::PerThreadDBPath(&mock_env_, "BlobFileBuilderTest_CompressionError"),
+ test::PerThreadDBPath(mock_env_.get(),
+ "BlobFileBuilderTest_CompressionError"),
0);
options.enable_blob_files = true;
options.blob_compression_type = kSnappyCompression;
-
- ImmutableCFOptions immutable_cf_options(options);
+ options.env = mock_env_.get();
+ ImmutableOptions immutable_options(options);
MutableCFOptions mutable_cf_options(options);
constexpr int job_id = 1;
std::vector<std::string> blob_file_paths;
std::vector<BlobFileAddition> blob_file_additions;
- BlobFileBuilder builder(TestFileNumberGenerator(), &mock_env_, &fs_,
- &immutable_cf_options, &mutable_cf_options,
- &file_options_, job_id, column_family_id,
- column_family_name, io_priority, write_hint,
- &blob_file_paths, &blob_file_additions);
+ BlobFileBuilder builder(
+ TestFileNumberGenerator(), fs_, &immutable_options, &mutable_cf_options,
+ &file_options_, "" /*db_id*/, "" /*db_session_id*/, job_id,
+ column_family_id, column_family_name, io_priority, write_hint,
+ nullptr /*IOTracer*/, nullptr /*BlobFileCompletionCallback*/,
+ BlobFileCreationReason::kFlush, &blob_file_paths, &blob_file_additions);
SyncPoint::GetInstance()->SetCallBack("CompressData:TamperWithReturnValue",
[](void* arg) {
constexpr uint64_t blob_file_number = 2;
ASSERT_EQ(blob_file_paths.size(), 1);
- ASSERT_EQ(blob_file_paths[0],
- BlobFileName(immutable_cf_options.cf_paths.front().path,
- blob_file_number));
+ ASSERT_EQ(
+ blob_file_paths[0],
+ BlobFileName(immutable_options.cf_paths.front().path, blob_file_number));
ASSERT_TRUE(blob_file_additions.empty());
}
Options options;
options.cf_paths.emplace_back(
- test::PerThreadDBPath(&mock_env_, "BlobFileBuilderTest_Checksum"), 0);
+ test::PerThreadDBPath(mock_env_.get(), "BlobFileBuilderTest_Checksum"),
+ 0);
options.enable_blob_files = true;
options.file_checksum_gen_factory =
std::make_shared<DummyFileChecksumGenFactory>();
+ options.env = mock_env_.get();
- ImmutableCFOptions immutable_cf_options(options);
+ ImmutableOptions immutable_options(options);
MutableCFOptions mutable_cf_options(options);
constexpr int job_id = 1;
std::vector<std::string> blob_file_paths;
std::vector<BlobFileAddition> blob_file_additions;
- BlobFileBuilder builder(TestFileNumberGenerator(), &mock_env_, &fs_,
- &immutable_cf_options, &mutable_cf_options,
- &file_options_, job_id, column_family_id,
- column_family_name, io_priority, write_hint,
- &blob_file_paths, &blob_file_additions);
+ BlobFileBuilder builder(
+ TestFileNumberGenerator(), fs_, &immutable_options, &mutable_cf_options,
+ &file_options_, "" /*db_id*/, "" /*db_session_id*/, job_id,
+ column_family_id, column_family_name, io_priority, write_hint,
+ nullptr /*IOTracer*/, nullptr /*BlobFileCompletionCallback*/,
+ BlobFileCreationReason::kFlush, &blob_file_paths, &blob_file_additions);
const std::string key("1");
const std::string value("deadbeef");
const std::string& blob_file_path = blob_file_paths[0];
- ASSERT_EQ(blob_file_path,
- BlobFileName(immutable_cf_options.cf_paths.front().path,
- blob_file_number));
+ ASSERT_EQ(
+ blob_file_path,
+ BlobFileName(immutable_options.cf_paths.front().path, blob_file_number));
ASSERT_EQ(blob_file_additions.size(), 1);
: public testing::Test,
public testing::WithParamInterface<std::string> {
protected:
- BlobFileBuilderIOErrorTest()
- : mock_env_(Env::Default()),
- fault_injection_env_(&mock_env_),
- fs_(&fault_injection_env_),
- sync_point_(GetParam()) {}
-
- MockEnv mock_env_;
- FaultInjectionTestEnv fault_injection_env_;
- LegacyFileSystemWrapper fs_;
+ BlobFileBuilderIOErrorTest() : sync_point_(GetParam()) {
+ mock_env_.reset(MockEnv::Create(Env::Default()));
+ fs_ = mock_env_->GetFileSystem().get();
+ }
+
+ std::unique_ptr<Env> mock_env_;
+ FileSystem* fs_;
FileOptions file_options_;
std::string sync_point_;
};
Options options;
options.cf_paths.emplace_back(
- test::PerThreadDBPath(&fault_injection_env_,
+ test::PerThreadDBPath(mock_env_.get(),
"BlobFileBuilderIOErrorTest_IOError"),
0);
options.enable_blob_files = true;
options.blob_file_size = value_size;
+ options.env = mock_env_.get();
- ImmutableCFOptions immutable_cf_options(options);
+ ImmutableOptions immutable_options(options);
MutableCFOptions mutable_cf_options(options);
constexpr int job_id = 1;
std::vector<std::string> blob_file_paths;
std::vector<BlobFileAddition> blob_file_additions;
- BlobFileBuilder builder(TestFileNumberGenerator(), &fault_injection_env_,
- &fs_, &immutable_cf_options, &mutable_cf_options,
- &file_options_, job_id, column_family_id,
- column_family_name, io_priority, write_hint,
- &blob_file_paths, &blob_file_additions);
+ BlobFileBuilder builder(
+ TestFileNumberGenerator(), fs_, &immutable_options, &mutable_cf_options,
+ &file_options_, "" /*db_id*/, "" /*db_session_id*/, job_id,
+ column_family_id, column_family_name, io_priority, write_hint,
+ nullptr /*IOTracer*/, nullptr /*BlobFileCompletionCallback*/,
+ BlobFileCreationReason::kFlush, &blob_file_paths, &blob_file_additions);
+
+ SyncPoint::GetInstance()->SetCallBack(sync_point_, [this](void* arg) {
+ Status* const s = static_cast<Status*>(arg);
+ assert(s);
- SyncPoint::GetInstance()->SetCallBack(sync_point_, [this](void* /* arg */) {
- fault_injection_env_.SetFilesystemActive(false,
- Status::IOError(sync_point_));
+ (*s) = Status::IOError(sync_point_);
});
SyncPoint::GetInstance()->EnableProcessing();
ASSERT_EQ(blob_file_paths.size(), 1);
ASSERT_EQ(blob_file_paths[0],
- BlobFileName(immutable_cf_options.cf_paths.front().path,
+ BlobFileName(immutable_options.cf_paths.front().path,
blob_file_number));
}
} // namespace ROCKSDB_NAMESPACE
int main(int argc, char** argv) {
+ ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}