public:
explicit EnvCounter(Env* base)
: SpecialEnv(base), num_new_writable_file_(0) {}
- int GetNumberOfNewWritableFileCalls() {
- return num_new_writable_file_;
- }
+ int GetNumberOfNewWritableFileCalls() { return num_new_writable_file_; }
Status NewWritableFile(const std::string& f, std::unique_ptr<WritableFile>* r,
const EnvOptions& soptions) override {
++num_new_writable_file_;
public:
explicit ColumnFamilyTestBase(uint32_t format) : rnd_(139), format_(format) {
Env* base_env = Env::Default();
-#ifndef ROCKSDB_LITE
- const char* test_env_uri = getenv("TEST_ENV_URI");
- if (test_env_uri) {
- Env* test_env = nullptr;
- Status s = Env::LoadEnv(test_env_uri, &test_env, &env_guard_);
- base_env = test_env;
- EXPECT_OK(s);
- EXPECT_NE(Env::Default(), base_env);
- }
-#endif // !ROCKSDB_LITE
+ EXPECT_OK(
+ test::CreateEnvFromSystem(ConfigOptions(), &base_env, &env_guard_));
EXPECT_NE(nullptr, base_env);
env_ = new EnvCounter(base_env);
env_->skip_fsync_ = true;
db_options_.create_if_missing = true;
db_options_.fail_if_options_file_error = true;
db_options_.env = env_;
- DestroyDB(dbname_, Options(db_options_, column_family_options_));
+ EXPECT_OK(DestroyDB(dbname_, Options(db_options_, column_family_options_)));
}
~ColumnFamilyTestBase() override {
std::vector<ColumnFamilyDescriptor> column_families;
names_.clear();
for (size_t i = 0; i < cf.size(); ++i) {
- column_families.push_back(ColumnFamilyDescriptor(
- cf[i], options.size() == 0 ? column_family_options_ : options[i]));
+ column_families.emplace_back(
+ cf[i], options.size() == 0 ? column_family_options_ : options[i]);
names_.push_back(cf[i]);
}
return DB::Open(db_options_, dbname_, column_families, &handles_, &db_);
}
Status OpenReadOnly(std::vector<std::string> cf,
- std::vector<ColumnFamilyOptions> options = {}) {
+ std::vector<ColumnFamilyOptions> options = {}) {
std::vector<ColumnFamilyDescriptor> column_families;
names_.clear();
for (size_t i = 0; i < cf.size(); ++i) {
- column_families.push_back(ColumnFamilyDescriptor(
- cf[i], options.size() == 0 ? column_family_options_ : options[i]));
+ column_families.emplace_back(
+ cf[i], options.size() == 0 ? column_family_options_ : options[i]);
names_.push_back(cf[i]);
}
return DB::OpenForReadOnly(db_options_, dbname_, column_families, &handles_,
#ifndef ROCKSDB_LITE // ReadOnlyDB is not supported
void AssertOpenReadOnly(std::vector<std::string> cf,
- std::vector<ColumnFamilyOptions> options = {}) {
+ std::vector<ColumnFamilyOptions> options = {}) {
ASSERT_OK(OpenReadOnly(cf, options));
}
#endif // !ROCKSDB_LITE
-
void Open(std::vector<std::string> cf,
std::vector<ColumnFamilyOptions> options = {}) {
ASSERT_OK(TryOpen(cf, options));
}
- void Open() {
- Open({"default"});
- }
+ void Open() { Open({"default"}); }
DBImpl* dbfull() { return static_cast_with_check<DBImpl>(db_); }
}
void Destroy(const std::vector<ColumnFamilyDescriptor>& column_families =
- std::vector<ColumnFamilyDescriptor>()) {
+ std::vector<ColumnFamilyDescriptor>()) {
Close();
ASSERT_OK(DestroyDB(dbname_, Options(db_options_, column_family_options_),
column_families));
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable(handles_[cf]));
}
- void WaitForCompaction() {
- ASSERT_OK(dbfull()->TEST_WaitForCompact());
- }
+ void WaitForCompaction() { ASSERT_OK(dbfull()->TEST_WaitForCompact()); }
uint64_t MaxTotalInMemoryState() {
return dbfull()->TEST_MaxTotalInMemoryState();
Status Merge(int cf, const std::string& key, const std::string& value) {
return db_->Merge(WriteOptions(), handles_[cf], Slice(key), Slice(value));
}
- Status Flush(int cf) {
- return db_->Flush(FlushOptions(), handles_[cf]);
- }
+ Status Flush(int cf) { return db_->Flush(FlushOptions(), handles_[cf]); }
std::string Get(int cf, const std::string& key) {
ReadOptions options;
int NumTableFilesAtLevel(int level, int cf) {
return GetProperty(cf,
- "rocksdb.num-files-at-level" + ToString(level));
+ "rocksdb.num-files-at-level" + std::to_string(level));
}
#ifndef ROCKSDB_LITE
#ifndef ROCKSDB_LITE
ASSERT_EQ(value, FilesPerLevel(cf));
#else
- (void) value;
- (void) cf;
+ (void)value;
+ (void)cf;
#endif
}
#ifndef ROCKSDB_LITE
ASSERT_EQ(expected_value, CountLiveFiles());
#else
- (void) expected_value;
+ (void)expected_value;
#endif
}
#ifndef ROCKSDB_LITE // GetSortedWalFiles is not supported
ASSERT_EQ(value, CountLiveLogFiles());
#else
- (void) value;
+ (void)value;
#endif // !ROCKSDB_LITE
}
return static_cast<int>(files.size());
}
- void RecalculateWriteStallConditions(ColumnFamilyData* cfd,
- const MutableCFOptions& mutable_cf_options) {
+ void RecalculateWriteStallConditions(
+ ColumnFamilyData* cfd, const MutableCFOptions& mutable_cf_options) {
// add lock to avoid race condition between
// `RecalculateWriteStallConditions` which writes to CFStats and
// background `DBImpl::DumpStats()` threads which read CFStats
dbfull()->TEST_LockMutex();
cfd->RecalculateWriteStallConditions(mutable_cf_options);
- dbfull()-> TEST_UnlockMutex();
+ dbfull()->TEST_UnlockMutex();
}
std::vector<ColumnFamilyHandle*> handles_;
INSTANTIATE_TEST_CASE_P(FormatDef, ColumnFamilyTest,
testing::Values(test::kDefaultFormatVersion));
INSTANTIATE_TEST_CASE_P(FormatLatest, ColumnFamilyTest,
- testing::Values(test::kLatestFormatVersion));
+ testing::Values(kLatestFormatVersion));
TEST_P(ColumnFamilyTest, DontReuseColumnFamilyID) {
for (int iter = 0; iter < 3; ++iter) {
// after flushing file B is deleted. At the same time, the min log number of
// default CF is not written to manifest. Log file A still remains.
// Flushed to SST file Y.
- Flush(1);
- Flush(0);
+ ASSERT_OK(Flush(1));
+ ASSERT_OK(Flush(0));
ASSERT_OK(Put(1, "bar", "v3")); // seqID 4
ASSERT_OK(Put(1, "foo", "v4")); // seqID 5
ASSERT_OK(db_->FlushWAL(/*sync=*/false));
// and is set to current. Both CFs' min log number is set to file C so after
// flushing file B is deleted. Log file A still remains.
// Flushed to SST file Y.
- Flush(1);
+ ASSERT_OK(Flush(1));
ASSERT_OK(Put(0, "bar", "v2")); // seqID 4
ASSERT_OK(Put(2, "bar", "v2")); // seqID 5
ASSERT_OK(Put(1, "bar", "v3")); // seqID 6
// Flushing all column families. This forces all CFs' min log to current. This
// is written to the manifest file. Log file C is cleared.
- Flush(0);
- Flush(1);
- Flush(2);
+ ASSERT_OK(Flush(0));
+ ASSERT_OK(Flush(1));
+ ASSERT_OK(Flush(2));
// Write to log file D
ASSERT_OK(Put(1, "bar", "v4")); // seqID 7
ASSERT_OK(Put(1, "bar", "v5")); // seqID 8
std::make_tuple(test::kDefaultFormatVersion, false)));
INSTANTIATE_TEST_CASE_P(
FormatLatest, FlushEmptyCFTestWithParam,
- testing::Values(std::make_tuple(test::kLatestFormatVersion, true),
- std::make_tuple(test::kLatestFormatVersion, false)));
+ testing::Values(std::make_tuple(kLatestFormatVersion, true),
+ std::make_tuple(kLatestFormatVersion, false)));
TEST_P(ColumnFamilyTest, AddDrop) {
Open();
std::vector<std::string> cf_names;
std::vector<ColumnFamilyHandle*> cf_handles;
for (int i = 1; i <= kNumCF; i++) {
- cf_names.push_back("cf1-" + ToString(i));
+ cf_names.push_back("cf1-" + std::to_string(i));
}
ASSERT_OK(db_->CreateColumnFamilies(cf_options, cf_names, &cf_handles));
for (int i = 1; i <= kNumCF; i++) {
}
cf_handles.clear();
for (int i = 1; i <= kNumCF; i++) {
- cf_descriptors.emplace_back("cf2-" + ToString(i), ColumnFamilyOptions());
+ cf_descriptors.emplace_back("cf2-" + std::to_string(i),
+ ColumnFamilyOptions());
}
ASSERT_OK(db_->CreateColumnFamilies(cf_descriptors, &cf_handles));
for (int i = 1; i <= kNumCF; i++) {
Open({"default"});
CreateColumnFamiliesAndReopen({"pikachu"});
for (int i = 0; i < 100; ++i) {
- ASSERT_OK(Put(1, ToString(i), "bar" + ToString(i)));
+ ASSERT_OK(Put(1, std::to_string(i), "bar" + std::to_string(i)));
}
ASSERT_OK(Flush(1));
std::vector<std::string> old_files;
ASSERT_OK(env_->GetChildren(backup_logs, &old_files));
for (auto& file : old_files) {
- if (file != "." && file != "..") {
- ASSERT_OK(env_->DeleteFile(backup_logs + "/" + file));
- }
+ ASSERT_OK(env_->DeleteFile(backup_logs + "/" + file));
}
column_family_options_.merge_operator =
std::vector<std::string> logs;
ASSERT_OK(env_->GetChildren(db_options_.wal_dir, &logs));
for (auto& log : logs) {
- if (log != ".." && log != ".") {
- CopyFile(db_options_.wal_dir + "/" + log, backup_logs + "/" + log);
- }
+ CopyFile(db_options_.wal_dir + "/" + log, backup_logs + "/" + log);
}
// recover the DB
if (iter == 0) {
// copy the logs from backup back to wal dir
for (auto& log : logs) {
- if (log != ".." && log != ".") {
- CopyFile(backup_logs + "/" + log, db_options_.wal_dir + "/" + log);
- }
+ CopyFile(backup_logs + "/" + log, db_options_.wal_dir + "/" + log);
}
}
}
}
for (int i = 0; i < 3; ++i) {
- uint64_t max_total_in_memory_state =
- MaxTotalInMemoryState();
- Flush(i);
+ uint64_t max_total_in_memory_state = MaxTotalInMemoryState();
+ ASSERT_OK(Flush(i));
AssertMaxTotalInMemoryState(max_total_in_memory_state);
}
ASSERT_OK(Put(1, "foofoo", "bar"));
ASSERT_OK(batch.Put(handles_[0], Slice("foo"), Slice("bar")));
ASSERT_OK(batch.Put(handles_[1], Slice("foo"), Slice("bar")));
ASSERT_OK(db_->Write(WriteOptions(), &batch));
- Flush(0);
+ ASSERT_OK(Flush(0));
fault_env->SetFilesystemActive(false);
std::vector<std::string> names;
}
}
Close();
- fault_env->DropUnsyncedFileData();
+ ASSERT_OK(fault_env->DropUnsyncedFileData());
fault_env->ResetState();
Open(names, {});
CreateColumnFamilies({"one", "two", "three"});
ColumnFamilyOptions default_cf, one, two, three;
// setup options. all column families have max_write_buffer_number setup to 10
- // "default" -> 100KB memtable, start flushing immediatelly
+ // "default" -> 100KB memtable, start flushing immediately
// "one" -> 200KB memtable, start flushing with two immutable memtables
// "two" -> 1MB memtable, start flushing with three immutable memtables
// "three" -> 90KB memtable, start flushing with four immutable memtables
WaitForFlush(2);
AssertNumberOfImmutableMemtables({0, 0, 0, 0});
AssertCountLiveLogFiles(12);
- PutRandomData(1, 2*200, 1000);
+ PutRandomData(1, 2 * 200, 1000);
WaitForFlush(1);
AssertNumberOfImmutableMemtables({0, 0, 0, 0});
AssertCountLiveLogFiles(7);
PutRandomData(1, 10, 12000);
PutRandomData(1, 1, 10);
WaitForFlush(1);
- AssertFilesPerLevel(ToString(i + 1), 1);
+ AssertFilesPerLevel(std::to_string(i + 1), 1);
}
// SETUP column family "two" -- level style with 4 levels
PutRandomData(2, 10, 12000);
PutRandomData(2, 1, 10);
WaitForFlush(2);
- AssertFilesPerLevel(ToString(i + 1), 2);
+ AssertFilesPerLevel(std::to_string(i + 1), 2);
}
// TRIGGER compaction "one"
PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true);
WaitForFlush(1);
- AssertFilesPerLevel(ToString(i + 1), 1);
+ AssertFilesPerLevel(std::to_string(i + 1), 1);
}
- bool cf_1_1 = true;
+ std::atomic_bool cf_1_1{true};
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->LoadDependency(
{{"ColumnFamilyTest::MultiManual:4", "ColumnFamilyTest::MultiManual:1"},
{"ColumnFamilyTest::MultiManual:2", "ColumnFamilyTest::MultiManual:5"},
{"ColumnFamilyTest::MultiManual:2", "ColumnFamilyTest::MultiManual:3"}});
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
"DBImpl::BackgroundCompaction:NonTrivial:AfterRun", [&](void* /*arg*/) {
- if (cf_1_1) {
+ if (cf_1_1.exchange(false)) {
TEST_SYNC_POINT("ColumnFamilyTest::MultiManual:4");
- cf_1_1 = false;
TEST_SYNC_POINT("ColumnFamilyTest::MultiManual:3");
}
});
PutRandomData(2, 10, 12000);
PutRandomData(2, 1, 10);
WaitForFlush(2);
- AssertFilesPerLevel(ToString(i + 1), 2);
+ AssertFilesPerLevel(std::to_string(i + 1), 2);
}
threads.emplace_back([&] {
TEST_SYNC_POINT("ColumnFamilyTest::MultiManual:1");
auto stop_token =
dbfull()->TEST_write_controler().GetCompactionPressureToken();
- bool cf_1_1 = true;
+ std::atomic_bool cf_1_1{true};
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->LoadDependency(
{{"ColumnFamilyTest::AutoManual:4", "ColumnFamilyTest::AutoManual:1"},
{"ColumnFamilyTest::AutoManual:2", "ColumnFamilyTest::AutoManual:5"},
{"ColumnFamilyTest::AutoManual:2", "ColumnFamilyTest::AutoManual:3"}});
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
"DBImpl::BackgroundCompaction:NonTrivial:AfterRun", [&](void* /*arg*/) {
- if (cf_1_1) {
- cf_1_1 = false;
+ if (cf_1_1.exchange(false)) {
TEST_SYNC_POINT("ColumnFamilyTest::AutoManual:4");
TEST_SYNC_POINT("ColumnFamilyTest::AutoManual:3");
}
PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true);
WaitForFlush(1);
- AssertFilesPerLevel(ToString(i + 1), 1);
+ AssertFilesPerLevel(std::to_string(i + 1), 1);
}
TEST_SYNC_POINT("ColumnFamilyTest::AutoManual:1");
PutRandomData(2, 10, 12000);
PutRandomData(2, 1, 10);
WaitForFlush(2);
- AssertFilesPerLevel(ToString(i + 1), 2);
+ AssertFilesPerLevel(std::to_string(i + 1), 2);
}
ROCKSDB_NAMESPACE::port::Thread threads([&] {
CompactRangeOptions compact_options;
PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true);
WaitForFlush(1);
- AssertFilesPerLevel(ToString(i + 1), 1);
+ AssertFilesPerLevel(std::to_string(i + 1), 1);
}
- bool cf_1_1 = true;
- bool cf_1_2 = true;
+ std::atomic_bool cf_1_1{true};
+ std::atomic_bool cf_1_2{true};
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->LoadDependency(
{{"ColumnFamilyTest::ManualAuto:4", "ColumnFamilyTest::ManualAuto:1"},
{"ColumnFamilyTest::ManualAuto:5", "ColumnFamilyTest::ManualAuto:2"},
{"ColumnFamilyTest::ManualAuto:2", "ColumnFamilyTest::ManualAuto:3"}});
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
"DBImpl::BackgroundCompaction:NonTrivial:AfterRun", [&](void* /*arg*/) {
- if (cf_1_1) {
+ if (cf_1_1.exchange(false)) {
TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:4");
- cf_1_1 = false;
TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:3");
- } else if (cf_1_2) {
+ } else if (cf_1_2.exchange(false)) {
TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:2");
- cf_1_2 = false;
}
});
PutRandomData(2, 10, 12000);
PutRandomData(2, 1, 10);
WaitForFlush(2);
- AssertFilesPerLevel(ToString(i + 1), 2);
+ AssertFilesPerLevel(std::to_string(i + 1), 2);
}
TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:5");
threads.join();
PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true);
WaitForFlush(1);
- AssertFilesPerLevel(ToString(i + 1), 1);
+ AssertFilesPerLevel(std::to_string(i + 1), 1);
}
- bool cf_1_1 = true;
- bool cf_1_2 = true;
+ std::atomic_bool cf_1_1{true};
+ std::atomic_bool cf_1_2{true};
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->LoadDependency(
{{"ColumnFamilyTest::ManualManual:4", "ColumnFamilyTest::ManualManual:2"},
{"ColumnFamilyTest::ManualManual:4", "ColumnFamilyTest::ManualManual:5"},
"ColumnFamilyTest::ManualManual:3"}});
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
"DBImpl::BackgroundCompaction:NonTrivial:AfterRun", [&](void* /*arg*/) {
- if (cf_1_1) {
+ if (cf_1_1.exchange(false)) {
TEST_SYNC_POINT("ColumnFamilyTest::ManualManual:4");
- cf_1_1 = false;
TEST_SYNC_POINT("ColumnFamilyTest::ManualManual:3");
- } else if (cf_1_2) {
+ } else if (cf_1_2.exchange(false)) {
TEST_SYNC_POINT("ColumnFamilyTest::ManualManual:2");
- cf_1_2 = false;
}
});
PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true);
WaitForFlush(1);
- AssertFilesPerLevel(ToString(one.level0_file_num_compaction_trigger + i),
- 1);
+ AssertFilesPerLevel(
+ std::to_string(one.level0_file_num_compaction_trigger + i), 1);
}
ROCKSDB_NAMESPACE::port::Thread threads1([&] {
PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true);
WaitForFlush(1);
- AssertFilesPerLevel(ToString(i + 1), 1);
+ AssertFilesPerLevel(std::to_string(i + 1), 1);
}
- bool cf_1_1 = true;
- bool cf_1_2 = true;
+ std::atomic_bool cf_1_1{true};
+ std::atomic_bool cf_1_2{true};
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->LoadDependency(
{{"ColumnFamilyTest::ManualAuto:4", "ColumnFamilyTest::ManualAuto:2"},
{"ColumnFamilyTest::ManualAuto:4", "ColumnFamilyTest::ManualAuto:5"},
{"ColumnFamilyTest::ManualAuto:1", "ColumnFamilyTest::ManualAuto:3"}});
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
"DBImpl::BackgroundCompaction:NonTrivial:AfterRun", [&](void* /*arg*/) {
- if (cf_1_1) {
+ if (cf_1_1.exchange(false)) {
TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:4");
- cf_1_1 = false;
TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:3");
- } else if (cf_1_2) {
+ } else if (cf_1_2.exchange(false)) {
TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:2");
- cf_1_2 = false;
}
});
PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true);
WaitForFlush(1);
- AssertFilesPerLevel(ToString(one.level0_file_num_compaction_trigger + i),
- 1);
+ AssertFilesPerLevel(
+ std::to_string(one.level0_file_num_compaction_trigger + i), 1);
}
TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:1");
PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true);
WaitForFlush(1);
- AssertFilesPerLevel(ToString(i + 1), 1);
+ AssertFilesPerLevel(std::to_string(i + 1), 1);
}
- bool cf_1_1 = true;
- bool cf_1_2 = true;
+ std::atomic_bool cf_1_1{true};
+ std::atomic_bool cf_1_2{true};
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->LoadDependency(
{{"ColumnFamilyTest::ManualAuto:4", "ColumnFamilyTest::ManualAuto:2"},
{"ColumnFamilyTest::ManualAuto:4", "ColumnFamilyTest::ManualAuto:5"},
{"ColumnFamilyTest::ManualAuto:1", "ColumnFamilyTest::ManualAuto:3"}});
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
"DBImpl::BackgroundCompaction:NonTrivial:AfterRun", [&](void* /*arg*/) {
- if (cf_1_1) {
+ if (cf_1_1.exchange(false)) {
TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:4");
- cf_1_1 = false;
TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:3");
- } else if (cf_1_2) {
+ } else if (cf_1_2.exchange(false)) {
TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:2");
- cf_1_2 = false;
}
});
PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true);
WaitForFlush(1);
- AssertFilesPerLevel(ToString(one.level0_file_num_compaction_trigger + i),
- 1);
+ AssertFilesPerLevel(
+ std::to_string(one.level0_file_num_compaction_trigger + i), 1);
}
TEST_SYNC_POINT("ColumnFamilyTest::ManualAuto:1");
auto stop_token =
dbfull()->TEST_write_controler().GetCompactionPressureToken();
- bool cf_1_1 = true;
- bool cf_1_2 = true;
+ std::atomic_bool cf_1_1{true};
+ std::atomic_bool cf_1_2{true};
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->LoadDependency(
{{"ColumnFamilyTest::AutoManual:4", "ColumnFamilyTest::AutoManual:2"},
{"ColumnFamilyTest::AutoManual:4", "ColumnFamilyTest::AutoManual:5"},
"ColumnFamilyTest::AutoManual:3"}});
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
"DBImpl::BackgroundCompaction:NonTrivial:AfterRun", [&](void* /*arg*/) {
- if (cf_1_1) {
+ if (cf_1_1.exchange(false)) {
TEST_SYNC_POINT("ColumnFamilyTest::AutoManual:4");
- cf_1_1 = false;
TEST_SYNC_POINT("ColumnFamilyTest::AutoManual:3");
- } else if (cf_1_2) {
+ } else if (cf_1_2.exchange(false)) {
TEST_SYNC_POINT("ColumnFamilyTest::AutoManual:2");
- cf_1_2 = false;
}
});
PutRandomData(1, 10, 12000, true);
PutRandomData(1, 1, 10, true);
WaitForFlush(1);
- AssertFilesPerLevel(ToString(i + 1), 1);
+ AssertFilesPerLevel(std::to_string(i + 1), 1);
}
TEST_SYNC_POINT("ColumnFamilyTest::AutoManual:5");
ASSERT_EQ("bla", Get(1, "foo"));
ASSERT_EQ("blablablabla", Get(2, "foo"));
-
// test newiterators
{
std::vector<Iterator*> iterators;
PutRandomData(0, 100, 1000); // flush
WaitForFlush(0);
WaitForFlush(2);
- // 3 files for default column families, 1 file for column family [two], zero
- // files for column family [one], because it's empty
- AssertCountLiveFiles(4);
+ // at least 3 files for default column families, 1 file for column family
+ // [two], zero files for column family [one], because it's empty
+ std::vector<LiveFileMetaData> metadata;
+ db_->GetLiveFilesMetaData(&metadata);
+ ASSERT_GE(metadata.size(), 4);
+ bool has_cf1_sst = false;
+ bool has_cf2_sst = false;
+ for (const auto& file : metadata) {
+ if (file.column_family_name == "one") {
+ has_cf1_sst = true;
+ } else if (file.column_family_name == "two") {
+ has_cf2_sst = true;
+ }
+ }
+ ASSERT_FALSE(has_cf1_sst);
+ ASSERT_TRUE(has_cf2_sst);
- Flush(0);
+ ASSERT_OK(Flush(0));
ASSERT_EQ(0, dbfull()->TEST_total_log_size());
Close();
}
// not a multiple of 4k, round up 4k
expected_arena_block_size += 4 * 1024;
}
+ expected_arena_block_size =
+ std::min(size_t{1024 * 1024}, expected_arena_block_size);
ASSERT_EQ(expected_arena_block_size, result.arena_block_size);
}
}
}
test_stage = kChildThreadFinishDroppingColumnFamily;
}
-} // namespace
+} // anonymous namespace
TEST_P(ColumnFamilyTest, CreateAndDropRace) {
const int kCfCount = 5;
ASSERT_EQ(1, dbfull()->TEST_BGCompactionsAllowed());
}
-TEST_P(ColumnFamilyTest, CreateAndDestoryOptions) {
+TEST_P(ColumnFamilyTest, CreateAndDestroyOptions) {
std::unique_ptr<ColumnFamilyOptions> cfo(new ColumnFamilyOptions());
ColumnFamilyHandle* cfh;
Open();
SpecialEnv env(Env::Default());
db_options_.env = &env;
db_options_.max_background_flushes = 1;
- column_family_options_.memtable_factory.reset(new SpecialSkipListFactory(2));
+ column_family_options_.memtable_factory.reset(
+ test::NewSpecialSkipListFactory(2));
Open();
CreateColumnFamilies({"one"});
ASSERT_OK(Put(1, "fodor", "mirko"));
SpecialEnv env(Env::Default());
db_options_.env = &env;
db_options_.max_background_flushes = 1;
- column_family_options_.memtable_factory.reset(new SpecialSkipListFactory(2));
+ column_family_options_.memtable_factory.reset(
+ test::NewSpecialSkipListFactory(2));
Open();
CreateColumnFamilies({"one"});
ASSERT_OK(Put(1, "fodor", "mirko"));
Iterator* it = db_->NewIterator(ReadOptions(), handles_[1]);
ASSERT_OK(it->status());
// A flush will make `it` hold the last reference of its super version.
- Flush(1);
+ ASSERT_OK(Flush(1));
ASSERT_OK(Put(1, "fodor", "mirko"));
ASSERT_OK(Put(0, "fodor", "mirko"));
env.SetBackgroundThreads(2, Env::HIGH);
db_options_.env = &env;
db_options_.max_background_flushes = 1;
- column_family_options_.memtable_factory.reset(new SpecialSkipListFactory(2));
+ column_family_options_.memtable_factory.reset(
+ test::NewSpecialSkipListFactory(2));
Open();
CreateColumnFamilies({"one"});
ASSERT_OK(Put(1, "fodor", "mirko"));
Iterator* it = db_->NewIterator(ro, handles_[1]);
ASSERT_OK(it->status());
// A flush will make `it` hold the last reference of its super version.
- Flush(1);
+ ASSERT_OK(Flush(1));
ASSERT_OK(Put(1, "fodor", "mirko"));
ASSERT_OK(Put(0, "fodor", "mirko"));
env.SetBackgroundThreads(2, Env::HIGH);
db_options_.env = &env;
db_options_.max_background_flushes = 1;
- column_family_options_.memtable_factory.reset(new SpecialSkipListFactory(3));
+ column_family_options_.memtable_factory.reset(
+ test::NewSpecialSkipListFactory(3));
column_family_options_.level0_file_num_compaction_trigger = 2;
Open();
CreateColumnFamilies({"one"});
ASSERT_OK(Put(1, "fodor", "mirko"));
ASSERT_OK(Put(1, "fodar2", "mirko"));
- Flush(1);
+ ASSERT_OK(Flush(1));
// Create an iterator holding the current super version, as well as
// the SST file just flushed.
ASSERT_OK(Put(1, "fodor", "mirko"));
ASSERT_OK(Put(1, "fodar2", "mirko"));
- Flush(1);
+ ASSERT_OK(Flush(1));
WaitForCompaction();
ROCKSDB_NAMESPACE::port::Thread thread([&] { ASSERT_OK(db_->SyncWAL()); });
TEST_SYNC_POINT("ColumnFamilyTest::LogSyncConflictFlush:1");
- Flush(1);
+ ASSERT_OK(Flush(1));
ASSERT_OK(Put(1, "foo", "bar"));
- Flush(1);
+ ASSERT_OK(Flush(1));
TEST_SYNC_POINT("ColumnFamilyTest::LogSyncConflictFlush:2");
Build(0, 100);
// Flush the 0th column family to force a roll of the wal log
- Flush(0);
+ ASSERT_OK(Flush(0));
// Add some more entries
Build(100, 100);
// Fill Column family 1.
PutRandomData(1, 100, 100);
- Flush(1);
+ ASSERT_OK(Flush(1));
ASSERT_EQ(1, GetSstFileCount(cf_opt1.cf_paths[0].path));
ASSERT_EQ(0, GetSstFileCount(dbname_));
// Fill column family 2
PutRandomData(2, 100, 100);
- Flush(2);
+ ASSERT_OK(Flush(2));
// SST from Column family 2 should be generated in
// db_paths which is dbname_ in this case.
Reopen({ColumnFamilyOptions(), cf_opt1, cf_opt2});
PutRandomData(1, 100, 100, true /* save */);
- Flush(1);
+ ASSERT_OK(Flush(1));
// Check that files are generated in appropriate paths.
ASSERT_EQ(1, GetSstFileCount(cf_opt1.cf_paths[0].path));
ASSERT_EQ(0, GetSstFileCount(dbname_));
PutRandomData(2, 100, 100, true /* save */);
- Flush(2);
+ ASSERT_OK(Flush(2));
ASSERT_EQ(1, GetSstFileCount(cf_opt2.cf_paths[0].path));
ASSERT_EQ(0, GetSstFileCount(dbname_));
}
}
-} // namespace ROCKSDB_NAMESPACE
+TEST(ColumnFamilyTest, ValidateBlobGCCutoff) {
+ DBOptions db_options;
+
+ ColumnFamilyOptions cf_options;
+ cf_options.enable_blob_garbage_collection = true;
+
+ cf_options.blob_garbage_collection_age_cutoff = -0.5;
+ ASSERT_TRUE(ColumnFamilyData::ValidateOptions(db_options, cf_options)
+ .IsInvalidArgument());
+
+ cf_options.blob_garbage_collection_age_cutoff = 0.0;
+ ASSERT_OK(ColumnFamilyData::ValidateOptions(db_options, cf_options));
+
+ cf_options.blob_garbage_collection_age_cutoff = 0.5;
+ ASSERT_OK(ColumnFamilyData::ValidateOptions(db_options, cf_options));
-#ifdef ROCKSDB_UNITTESTS_WITH_CUSTOM_OBJECTS_FROM_STATIC_LIBS
-extern "C" {
-void RegisterCustomObjects(int argc, char** argv);
+ cf_options.blob_garbage_collection_age_cutoff = 1.0;
+ ASSERT_OK(ColumnFamilyData::ValidateOptions(db_options, cf_options));
+
+ cf_options.blob_garbage_collection_age_cutoff = 1.5;
+ ASSERT_TRUE(ColumnFamilyData::ValidateOptions(db_options, cf_options)
+ .IsInvalidArgument());
}
-#else
-void RegisterCustomObjects(int /*argc*/, char** /*argv*/) {}
-#endif // !ROCKSDB_UNITTESTS_WITH_CUSTOM_OBJECTS_FROM_STATIC_LIBS
+
+TEST(ColumnFamilyTest, ValidateBlobGCForceThreshold) {
+ DBOptions db_options;
+
+ ColumnFamilyOptions cf_options;
+ cf_options.enable_blob_garbage_collection = true;
+
+ cf_options.blob_garbage_collection_force_threshold = -0.5;
+ ASSERT_TRUE(ColumnFamilyData::ValidateOptions(db_options, cf_options)
+ .IsInvalidArgument());
+
+ cf_options.blob_garbage_collection_force_threshold = 0.0;
+ ASSERT_OK(ColumnFamilyData::ValidateOptions(db_options, cf_options));
+
+ cf_options.blob_garbage_collection_force_threshold = 0.5;
+ ASSERT_OK(ColumnFamilyData::ValidateOptions(db_options, cf_options));
+
+ cf_options.blob_garbage_collection_force_threshold = 1.0;
+ ASSERT_OK(ColumnFamilyData::ValidateOptions(db_options, cf_options));
+
+ cf_options.blob_garbage_collection_force_threshold = 1.5;
+ ASSERT_TRUE(ColumnFamilyData::ValidateOptions(db_options, cf_options)
+ .IsInvalidArgument());
+}
+
+TEST(ColumnFamilyTest, ValidateMemtableKVChecksumOption) {
+ DBOptions db_options;
+
+ ColumnFamilyOptions cf_options;
+ ASSERT_OK(ColumnFamilyData::ValidateOptions(db_options, cf_options));
+
+ cf_options.memtable_protection_bytes_per_key = 5;
+ ASSERT_TRUE(ColumnFamilyData::ValidateOptions(db_options, cf_options)
+ .IsNotSupported());
+
+ cf_options.memtable_protection_bytes_per_key = 1;
+ ASSERT_OK(ColumnFamilyData::ValidateOptions(db_options, cf_options));
+
+ cf_options.memtable_protection_bytes_per_key = 16;
+ ASSERT_TRUE(ColumnFamilyData::ValidateOptions(db_options, cf_options)
+ .IsNotSupported());
+
+ cf_options.memtable_protection_bytes_per_key = 0;
+ ASSERT_OK(ColumnFamilyData::ValidateOptions(db_options, cf_options));
+}
+
+} // namespace ROCKSDB_NAMESPACE
int main(int argc, char** argv) {
ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();