Remove deprecated DB::Open raw pointer variants (and more) (#14335)

Summary:
and remove deprecated DB::MaxMemCompactionLevel(). In the process of pushing through a relatively clean refactoring of uses of the old functions, some other minor public APIs are also migrated from raw DB pointers to unique_ptr.

Claude did pretty much all the work, but requiring dozens of prompts to actually push through relatively clean phase out of raw DB pointers from what needed to be touched, and leaving that code in better shape. (Hundreds of `DB*` still remain all over the place even outside C and Java bindings.)

Pull Request resolved: https://github.com/facebook/rocksdb/pull/14335

Test Plan: existing tests; no functional changes intended

Reviewed By: xingbowang, mszeszko-meta

Differential Revision: D93523820

Pulled By: pdillinger

fbshipit-source-id: e4ca22ad81cd2cfe91122d7507d7ca34fe03d043
This commit is contained in:
Peter Dillinger
2026-02-17 23:33:39 -08:00
committed by meta-codesync[bot]
parent 1f9d8ee302
commit d3817f058d
114 changed files with 1299 additions and 1447 deletions
+11 -11
View File
@@ -2179,7 +2179,7 @@ TEST_P(DBSecondaryCacheTest, LRUCacheDumpLoadBasic) {
&cache_dumper);
ASSERT_OK(s);
std::vector<DB*> db_list;
db_list.push_back(db_);
db_list.push_back(db_.get());
s = cache_dumper->SetDumpFilter(db_list);
ASSERT_OK(s);
s = cache_dumper->DumpCacheEntriesToWriter();
@@ -2263,11 +2263,11 @@ TEST_P(DBSecondaryCacheTest, LRUCacheDumpLoadWithFilter) {
options.env = fault_env_.get();
std::string dbname1 = test::PerThreadDBPath("db_1");
ASSERT_OK(DestroyDB(dbname1, options));
DB* db1 = nullptr;
std::unique_ptr<DB> db1;
ASSERT_OK(DB::Open(options, dbname1, &db1));
std::string dbname2 = test::PerThreadDBPath("db_2");
ASSERT_OK(DestroyDB(dbname2, options));
DB* db2 = nullptr;
std::unique_ptr<DB> db2;
ASSERT_OK(DB::Open(options, dbname2, &db2));
fault_fs_->SetFailGetUniqueId(true);
@@ -2335,7 +2335,7 @@ TEST_P(DBSecondaryCacheTest, LRUCacheDumpLoadWithFilter) {
&cache_dumper);
ASSERT_OK(s);
std::vector<DB*> db_list;
db_list.push_back(db1);
db_list.push_back(db1.get());
s = cache_dumper->SetDumpFilter(db_list);
ASSERT_OK(s);
s = cache_dumper->DumpCacheEntriesToWriter();
@@ -2377,7 +2377,7 @@ TEST_P(DBSecondaryCacheTest, LRUCacheDumpLoadWithFilter) {
ASSERT_OK(s);
ASSERT_OK(db1->Close());
delete db1;
db1.reset();
ASSERT_OK(DB::Open(options, dbname1, &db1));
// After load, we do the Get again. To validate the cache, we do not allow any
@@ -2406,8 +2406,8 @@ TEST_P(DBSecondaryCacheTest, LRUCacheDumpLoadWithFilter) {
ASSERT_EQ(256, static_cast<int>(block_lookup));
fault_fs_->SetFailGetUniqueId(false);
fault_fs_->SetFilesystemActive(true);
delete db1;
delete db2;
db1.reset();
db2.reset();
ASSERT_OK(DestroyDB(dbname1, options));
ASSERT_OK(DestroyDB(dbname2, options));
}
@@ -2619,11 +2619,11 @@ TEST_P(DBSecondaryCacheTest, TestSecondaryCacheOptionTwoDB) {
options.paranoid_file_checks = true;
std::string dbname1 = test::PerThreadDBPath("db_t_1");
ASSERT_OK(DestroyDB(dbname1, options));
DB* db1 = nullptr;
std::unique_ptr<DB> db1;
ASSERT_OK(DB::Open(options, dbname1, &db1));
std::string dbname2 = test::PerThreadDBPath("db_t_2");
ASSERT_OK(DestroyDB(dbname2, options));
DB* db2 = nullptr;
std::unique_ptr<DB> db2;
Options options2 = options;
options2.lowest_used_cache_tier = CacheTier::kVolatileTier;
ASSERT_OK(DB::Open(options2, dbname2, &db2));
@@ -2700,8 +2700,8 @@ TEST_P(DBSecondaryCacheTest, TestSecondaryCacheOptionTwoDB) {
fault_fs_->SetFailGetUniqueId(false);
fault_fs_->SetFilesystemActive(true);
delete db1;
delete db2;
db1.reset();
db2.reset();
ASSERT_OK(DestroyDB(dbname1, options));
ASSERT_OK(DestroyDB(dbname2, options));
}
+30 -28
View File
@@ -11,6 +11,7 @@
#include <cstdlib>
#include <map>
#include <memory>
#include <unordered_set>
#include <vector>
@@ -1222,12 +1223,12 @@ char* rocksdb_open_and_compact_with_options(
rocksdb_t* rocksdb_open(const rocksdb_options_t* options, const char* name,
char** errptr) {
DB* db;
if (SaveError(errptr, DB::Open(options->rep, std::string(name), &db))) {
std::unique_ptr<DB> dbptr;
if (SaveError(errptr, DB::Open(options->rep, std::string(name), &dbptr))) {
return nullptr;
}
rocksdb_t* result = new rocksdb_t;
result->rep = db;
result->rep = dbptr.release();
return result;
}
@@ -1247,13 +1248,14 @@ rocksdb_t* rocksdb_open_for_read_only(const rocksdb_options_t* options,
const char* name,
unsigned char error_if_wal_file_exists,
char** errptr) {
DB* db;
if (SaveError(errptr, DB::OpenForReadOnly(options->rep, std::string(name),
&db, error_if_wal_file_exists))) {
std::unique_ptr<DB> dbptr;
if (SaveError(errptr,
DB::OpenForReadOnly(options->rep, std::string(name), &dbptr,
error_if_wal_file_exists))) {
return nullptr;
}
rocksdb_t* result = new rocksdb_t;
result->rep = db;
result->rep = dbptr.release();
return result;
}
@@ -1261,14 +1263,14 @@ rocksdb_t* rocksdb_open_as_secondary(const rocksdb_options_t* options,
const char* name,
const char* secondary_path,
char** errptr) {
DB* db;
std::unique_ptr<DB> dbptr;
if (SaveError(errptr,
DB::OpenAsSecondary(options->rep, std::string(name),
std::string(secondary_path), &db))) {
std::string(secondary_path), &dbptr))) {
return nullptr;
}
rocksdb_t* result = new rocksdb_t;
result->rep = db;
result->rep = dbptr.release();
return result;
}
@@ -1582,11 +1584,11 @@ rocksdb_t* rocksdb_open_and_trim_history(
std::string trim_ts_(trim_ts, trim_tslen);
DB* db;
std::unique_ptr<DB> dbptr;
std::vector<ColumnFamilyHandle*> handles;
if (SaveError(errptr, DB::OpenAndTrimHistory(
DBOptions(db_options->rep), std::string(name),
column_families, &handles, &db, trim_ts_))) {
column_families, &handles, &dbptr, trim_ts_))) {
return nullptr;
}
@@ -1598,7 +1600,7 @@ rocksdb_t* rocksdb_open_and_trim_history(
column_family_handles[i] = c_handle;
}
rocksdb_t* result = new rocksdb_t;
result->rep = db;
result->rep = dbptr.release();
return result;
}
@@ -1614,10 +1616,10 @@ rocksdb_t* rocksdb_open_column_families(
ColumnFamilyOptions(column_family_options[i]->rep));
}
DB* db;
std::unique_ptr<DB> dbptr;
std::vector<ColumnFamilyHandle*> handles;
if (SaveError(errptr, DB::Open(DBOptions(db_options->rep), std::string(name),
column_families, &handles, &db))) {
column_families, &handles, &dbptr))) {
return nullptr;
}
@@ -1629,7 +1631,7 @@ rocksdb_t* rocksdb_open_column_families(
column_family_handles[i] = c_handle;
}
rocksdb_t* result = new rocksdb_t;
result->rep = db;
result->rep = dbptr.release();
return result;
}
@@ -1682,12 +1684,12 @@ rocksdb_t* rocksdb_open_for_read_only_column_families(
ColumnFamilyOptions(column_family_options[i]->rep));
}
DB* db;
std::unique_ptr<DB> dbptr;
std::vector<ColumnFamilyHandle*> handles;
if (SaveError(errptr,
DB::OpenForReadOnly(DBOptions(db_options->rep),
std::string(name), column_families,
&handles, &db, error_if_wal_file_exists))) {
if (SaveError(errptr, DB::OpenForReadOnly(DBOptions(db_options->rep),
std::string(name), column_families,
&handles, &dbptr,
error_if_wal_file_exists))) {
return nullptr;
}
@@ -1699,7 +1701,7 @@ rocksdb_t* rocksdb_open_for_read_only_column_families(
column_family_handles[i] = c_handle;
}
rocksdb_t* result = new rocksdb_t;
result->rep = db;
result->rep = dbptr.release();
return result;
}
@@ -1715,12 +1717,12 @@ rocksdb_t* rocksdb_open_as_secondary_column_families(
std::string(column_family_names[i]),
ColumnFamilyOptions(column_family_options[i]->rep));
}
DB* db;
std::unique_ptr<DB> dbptr;
std::vector<ColumnFamilyHandle*> handles;
if (SaveError(errptr, DB::OpenAsSecondary(DBOptions(db_options->rep),
std::string(name),
std::string(secondary_path),
column_families, &handles, &db))) {
if (SaveError(errptr, DB::OpenAsSecondary(
DBOptions(db_options->rep), std::string(name),
std::string(secondary_path), column_families,
&handles, &dbptr))) {
return nullptr;
}
for (size_t i = 0; i != handles.size(); ++i) {
@@ -1731,7 +1733,7 @@ rocksdb_t* rocksdb_open_as_secondary_column_families(
column_family_handles[i] = c_handle;
}
rocksdb_t* result = new rocksdb_t;
result->rep = db;
result->rep = dbptr.release();
return result;
}
+6 -9
View File
@@ -118,8 +118,7 @@ class ColumnFamilyTestBase : public testing::Test {
for (int i = 0; i < n; i++) {
if (flush_every != 0 && i != 0 && i % flush_every == 0) {
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
dbi->TEST_FlushMemTable();
dbfull()->TEST_FlushMemTable();
}
int keyi = base + i;
@@ -177,8 +176,7 @@ class ColumnFamilyTestBase : public testing::Test {
}
handles_.clear();
names_.clear();
delete db_;
db_ = nullptr;
db_.reset();
}
Status TryOpen(std::vector<std::string> cf,
@@ -218,7 +216,7 @@ class ColumnFamilyTestBase : public testing::Test {
void Open() { Open({"default"}); }
DBImpl* dbfull() { return static_cast_with_check<DBImpl>(db_); }
DBImpl* dbfull() { return static_cast_with_check<DBImpl>(db_.get()); }
int GetProperty(int cf, std::string property) {
std::string value;
@@ -500,7 +498,7 @@ class ColumnFamilyTestBase : public testing::Test {
ColumnFamilyOptions column_family_options_;
DBOptions db_options_;
std::string dbname_;
DB* db_ = nullptr;
std::unique_ptr<DB> db_;
EnvCounter* env_;
std::shared_ptr<Env> env_guard_;
Random rnd_;
@@ -3542,11 +3540,10 @@ TEST_P(ColumnFamilyTest, MultipleCFPathsTest) {
// Re-open and verify the keys.
Reopen({ColumnFamilyOptions(), cf_opt1, cf_opt2});
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
for (int cf = 1; cf != 3; ++cf) {
ReadOptions read_options;
read_options.readahead_size = 0;
auto it = dbi->NewIterator(read_options, handles_[cf]);
auto it = db_->NewIterator(read_options, handles_[cf]);
for (it->SeekToFirst(); it->Valid(); it->Next()) {
ASSERT_OK(it->status());
Slice key(it->key());
@@ -3886,7 +3883,7 @@ TEST_F(ManualFlushSkipRetainUDTTest, FlushRemovesStaleEntries) {
static_cast_with_check<ColumnFamilyHandleImpl>(cfh)->cfd();
for (int version = 0; version < 100; version++) {
if (version == 50) {
ASSERT_OK(static_cast_with_check<DBImpl>(db_)->TEST_SwitchMemtable(cfd));
ASSERT_OK(dbfull()->TEST_SwitchMemtable(cfd));
}
ASSERT_OK(
Put(0, "foo", EncodeAsUint64(version), "v" + std::to_string(version)));
+32 -46
View File
@@ -75,10 +75,9 @@ TEST_F(CompactFilesTest, L0ConflictsFiles) {
options.level0_file_num_compaction_trigger = kLevel0Trigger;
options.compression = kNoCompression;
DB* db = nullptr;
std::unique_ptr<DB> db;
ASSERT_OK(DestroyDB(db_name_, options));
Status s = DB::Open(options, db_name_, &db);
assert(s.ok());
ASSERT_OK(DB::Open(options, db_name_, &db));
assert(db);
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->LoadDependency({
@@ -114,7 +113,6 @@ TEST_F(CompactFilesTest, L0ConflictsFiles) {
}
}
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
delete db;
}
TEST_F(CompactFilesTest, MultipleLevel) {
@@ -128,11 +126,11 @@ TEST_F(CompactFilesTest, MultipleLevel) {
FlushedFileCollector* collector = new FlushedFileCollector();
options.listeners.emplace_back(collector);
DB* db = nullptr;
std::unique_ptr<DB> db;
ASSERT_OK(DestroyDB(db_name_, options));
Status s = DB::Open(options, db_name_, &db);
ASSERT_OK(s);
ASSERT_NE(db, nullptr);
ASSERT_NE(db.get(), nullptr);
// create couple files in L0, L3, L4 and L5
for (int i = 5; i > 2; --i) {
@@ -141,7 +139,8 @@ TEST_F(CompactFilesTest, MultipleLevel) {
ASSERT_OK(db->Flush(FlushOptions()));
// Ensure background work is fully finished including listener callbacks
// before accessing listener state.
ASSERT_OK(static_cast_with_check<DBImpl>(db)->TEST_WaitForBackgroundWork());
ASSERT_OK(
static_cast_with_check<DBImpl>(db.get())->TEST_WaitForBackgroundWork());
auto l0_files = collector->GetFlushedFiles();
ASSERT_OK(db->CompactFiles(CompactionOptions(), l0_files, i));
@@ -191,8 +190,6 @@ TEST_F(CompactFilesTest, MultipleLevel) {
ASSERT_OK(db->CompactFiles(CompactionOptions(), files, 5));
SyncPoint::GetInstance()->DisableProcessing();
thread.join();
delete db;
}
TEST_F(CompactFilesTest, ObsoleteFiles) {
@@ -212,11 +209,11 @@ TEST_F(CompactFilesTest, ObsoleteFiles) {
FlushedFileCollector* collector = new FlushedFileCollector();
options.listeners.emplace_back(collector);
DB* db = nullptr;
std::unique_ptr<DB> db;
ASSERT_OK(DestroyDB(db_name_, options));
Status s = DB::Open(options, db_name_, &db);
ASSERT_OK(s);
ASSERT_NE(db, nullptr);
ASSERT_NE(db.get(), nullptr);
// create couple files
for (int i = 1000; i < 2000; ++i) {
@@ -226,13 +223,12 @@ TEST_F(CompactFilesTest, ObsoleteFiles) {
auto l0_files = collector->GetFlushedFiles();
ASSERT_OK(db->CompactFiles(CompactionOptions(), l0_files, 1));
ASSERT_OK(static_cast_with_check<DBImpl>(db)->TEST_WaitForCompact());
ASSERT_OK(static_cast_with_check<DBImpl>(db.get())->TEST_WaitForCompact());
// verify all compaction input files are deleted
for (const auto& fname : l0_files) {
ASSERT_EQ(Status::NotFound(), env_->FileExists(fname));
}
delete db;
}
TEST_F(CompactFilesTest, NotCutOutputOnLevel0) {
@@ -251,10 +247,9 @@ TEST_F(CompactFilesTest, NotCutOutputOnLevel0) {
FlushedFileCollector* collector = new FlushedFileCollector();
options.listeners.emplace_back(collector);
DB* db = nullptr;
std::unique_ptr<DB> db;
ASSERT_OK(DestroyDB(db_name_, options));
Status s = DB::Open(options, db_name_, &db);
assert(s.ok());
ASSERT_OK(DB::Open(options, db_name_, &db));
assert(db);
// create couple files
@@ -262,19 +257,20 @@ TEST_F(CompactFilesTest, NotCutOutputOnLevel0) {
ASSERT_OK(db->Put(WriteOptions(), std::to_string(i),
std::string(1000, 'a' + (i % 26))));
}
ASSERT_OK(static_cast_with_check<DBImpl>(db)->TEST_WaitForFlushMemTable());
ASSERT_OK(
static_cast_with_check<DBImpl>(db.get())->TEST_WaitForFlushMemTable());
auto l0_files_1 = collector->GetFlushedFiles();
collector->ClearFlushedFiles();
for (int i = 0; i < 500; ++i) {
ASSERT_OK(db->Put(WriteOptions(), std::to_string(i),
std::string(1000, 'a' + (i % 26))));
}
ASSERT_OK(static_cast_with_check<DBImpl>(db)->TEST_WaitForFlushMemTable());
ASSERT_OK(
static_cast_with_check<DBImpl>(db.get())->TEST_WaitForFlushMemTable());
auto l0_files_2 = collector->GetFlushedFiles();
ASSERT_OK(db->CompactFiles(CompactionOptions(), l0_files_1, 0));
ASSERT_OK(db->CompactFiles(CompactionOptions(), l0_files_2, 0));
// no assertion failure
delete db;
}
TEST_F(CompactFilesTest, CapturingPendingFiles) {
@@ -289,7 +285,7 @@ TEST_F(CompactFilesTest, CapturingPendingFiles) {
FlushedFileCollector* collector = new FlushedFileCollector();
options.listeners.emplace_back(collector);
DB* db = nullptr;
std::unique_ptr<DB> db;
ASSERT_OK(DestroyDB(db_name_, options));
Status s = DB::Open(options, db_name_, &db);
ASSERT_OK(s);
@@ -303,7 +299,8 @@ TEST_F(CompactFilesTest, CapturingPendingFiles) {
// Ensure background work is fully finished including listener callbacks
// before accessing listener state.
ASSERT_OK(static_cast_with_check<DBImpl>(db)->TEST_WaitForBackgroundWork());
ASSERT_OK(
static_cast_with_check<DBImpl>(db.get())->TEST_WaitForBackgroundWork());
auto l0_files = collector->GetFlushedFiles();
EXPECT_EQ(5, l0_files.size());
@@ -327,13 +324,12 @@ TEST_F(CompactFilesTest, CapturingPendingFiles) {
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
delete db;
db.reset();
// Make sure we can reopen the DB.
s = DB::Open(options, db_name_, &db);
ASSERT_OK(s);
assert(db);
delete db;
}
TEST_F(CompactFilesTest, CompactionFilterWithGetSv) {
@@ -365,12 +361,12 @@ TEST_F(CompactFilesTest, CompactionFilterWithGetSv) {
options.create_if_missing = true;
options.compaction_filter = cf.get();
DB* db = nullptr;
std::unique_ptr<DB> db;
ASSERT_OK(DestroyDB(db_name_, options));
Status s = DB::Open(options, db_name_, &db);
ASSERT_OK(s);
cf->SetDB(db);
cf->SetDB(db.get());
// Write one L0 file
ASSERT_OK(db->Put(WriteOptions(), "K1", "V1"));
@@ -384,8 +380,6 @@ TEST_F(CompactFilesTest, CompactionFilterWithGetSv) {
ASSERT_OK(
db->CompactFiles(ROCKSDB_NAMESPACE::CompactionOptions(), {fname}, 0));
}
delete db;
}
TEST_F(CompactFilesTest, SentinelCompressionType) {
@@ -413,7 +407,7 @@ TEST_F(CompactFilesTest, SentinelCompressionType) {
options.create_if_missing = true;
FlushedFileCollector* collector = new FlushedFileCollector();
options.listeners.emplace_back(collector);
DB* db = nullptr;
std::unique_ptr<DB> db;
ASSERT_OK(DB::Open(options, db_name_, &db));
ASSERT_OK(db->Put(WriteOptions(), "key", "val"));
@@ -421,7 +415,8 @@ TEST_F(CompactFilesTest, SentinelCompressionType) {
// Ensure background work is fully finished including listener callbacks
// before accessing listener state.
ASSERT_OK(static_cast_with_check<DBImpl>(db)->TEST_WaitForBackgroundWork());
ASSERT_OK(
static_cast_with_check<DBImpl>(db.get())->TEST_WaitForBackgroundWork());
auto l0_files = collector->GetFlushedFiles();
ASSERT_EQ(1, l0_files.size());
@@ -437,7 +432,6 @@ TEST_F(CompactFilesTest, SentinelCompressionType) {
// compression_name property
ASSERT_EQ("BuiltinV2;02;", name_and_table_props.second->compression_name);
}
delete db;
}
}
@@ -462,11 +456,7 @@ TEST_F(CompactFilesTest, CompressionWithBlockAlign) {
}
std::unique_ptr<DB> db;
{
DB* _db = nullptr;
ASSERT_OK(DB::Open(options, db_name_, &_db));
db.reset(_db);
}
ASSERT_OK(DB::Open(options, db_name_, &db));
ASSERT_OK(db->Put(WriteOptions(), "key", "val"));
ASSERT_OK(db->Flush(FlushOptions()));
@@ -505,7 +495,7 @@ TEST_F(CompactFilesTest, GetCompactionJobInfo) {
FlushedFileCollector* collector = new FlushedFileCollector();
options.listeners.emplace_back(collector);
DB* db = nullptr;
std::unique_ptr<DB> db;
ASSERT_OK(DestroyDB(db_name_, options));
Status s = DB::Open(options, db_name_, &db);
ASSERT_OK(s);
@@ -516,7 +506,8 @@ TEST_F(CompactFilesTest, GetCompactionJobInfo) {
ASSERT_OK(db->Put(WriteOptions(), std::to_string(i),
std::string(1000, 'a' + (i % 26))));
}
ASSERT_OK(static_cast_with_check<DBImpl>(db)->TEST_WaitForFlushMemTable());
ASSERT_OK(
static_cast_with_check<DBImpl>(db.get())->TEST_WaitForFlushMemTable());
auto l0_files_1 = collector->GetFlushedFiles();
CompactionOptions co;
co.compression = CompressionType::kLZ4Compression;
@@ -532,7 +523,6 @@ TEST_F(CompactFilesTest, GetCompactionJobInfo) {
ASSERT_EQ(compaction_job_info.output_level, 0);
ASSERT_OK(compaction_job_info.status);
// no assertion failure
delete db;
}
// Helper function to generate zero-padded keys
@@ -548,11 +538,11 @@ TEST_F(CompactFilesTest, TrivialMoveNonOverlappingFiles) {
options.compression = kNoCompression;
options.level_compaction_dynamic_level_bytes = false;
DB* db = nullptr;
std::unique_ptr<DB> db;
ASSERT_OK(DestroyDB(db_name_, options));
Status s = DB::Open(options, db_name_, &db);
ASSERT_OK(s);
ASSERT_NE(db, nullptr);
ASSERT_NE(db.get(), nullptr);
// Create 3 non-overlapping files in L0
// File 1: keys [a00-a99]
@@ -665,8 +655,6 @@ TEST_F(CompactFilesTest, TrivialMoveNonOverlappingFiles) {
ASSERT_OK(db->Get(ReadOptions(), key, &value));
ASSERT_EQ(value, "value_" + key);
}
delete db;
}
TEST_F(CompactFilesTest, TrivialMoveBlockedByOverlap) {
@@ -677,11 +665,11 @@ TEST_F(CompactFilesTest, TrivialMoveBlockedByOverlap) {
options.level_compaction_dynamic_level_bytes = false;
options.num_levels = 7;
DB* db = nullptr;
std::unique_ptr<DB> db;
ASSERT_OK(DestroyDB(db_name_, options));
Status s = DB::Open(options, db_name_, &db);
ASSERT_OK(s);
ASSERT_NE(db, nullptr);
ASSERT_NE(db.get(), nullptr);
// Create a file in L6 with keys [m00-m99] (wide range)
for (int i = 0; i < 100; i++) {
@@ -757,8 +745,6 @@ TEST_F(CompactFilesTest, TrivialMoveBlockedByOverlap) {
ASSERT_OK(db->Get(ReadOptions(), key, &value));
ASSERT_EQ(value, "updated_value_" + key);
}
delete db;
}
} // namespace ROCKSDB_NAMESPACE
+7 -7
View File
@@ -82,7 +82,7 @@ class CompactionJobStatsTest : public testing::Test,
std::string dbname_;
std::string alternative_wal_dir_;
Env* env_;
DB* db_;
std::unique_ptr<DB> db_;
std::vector<ColumnFamilyHandle*> handles_;
uint32_t max_subcompactions_;
@@ -123,7 +123,7 @@ class CompactionJobStatsTest : public testing::Test,
static void SetUpTestCase() {}
static void TearDownTestCase() {}
DBImpl* dbfull() { return static_cast_with_check<DBImpl>(db_); }
DBImpl* dbfull() { return static_cast_with_check<DBImpl>(db_.get()); }
void CreateColumnFamilies(const std::vector<std::string>& cfs,
const Options& options) {
@@ -162,7 +162,8 @@ class CompactionJobStatsTest : public testing::Test,
column_families.emplace_back(cfs[i], options[i]);
}
DBOptions db_opts = DBOptions(options[0]);
return DB::Open(db_opts, dbname_, column_families, &handles_, &db_);
auto s = DB::Open(db_opts, dbname_, column_families, &handles_, &db_);
return s;
}
Status TryReopenWithColumnFamilies(const std::vector<std::string>& cfs,
@@ -179,8 +180,7 @@ class CompactionJobStatsTest : public testing::Test,
delete h;
}
handles_.clear();
delete db_;
db_ = nullptr;
db_.reset();
}
void DestroyAndReopen(const Options& options) {
@@ -743,7 +743,7 @@ TEST_P(CompactionJobStatsTest, CompactionJobStatsTest) {
}
ASSERT_OK(Flush(1));
ASSERT_OK(static_cast_with_check<DBImpl>(db_)->TEST_WaitForCompact());
ASSERT_OK(dbfull()->TEST_WaitForCompact());
stats_checker->set_verify_next_comp_io_stats(true);
std::atomic<bool> first_prepare_write(true);
@@ -944,7 +944,7 @@ TEST_P(CompactionJobStatsTest, UniversalCompactionTest) {
start_key += key_base) {
MakeTableWithKeyValues(&rnd, start_key, start_key + key_base - 1, kKeySize,
kValueSize, key_interval, compression_ratio, 1);
ASSERT_OK(static_cast_with_check<DBImpl>(db_)->TEST_WaitForCompact());
ASSERT_OK(dbfull()->TEST_WaitForCompact());
}
ASSERT_EQ(stats_checker->NumberOfUnverifiedStats(), 0U);
}
+3 -2
View File
@@ -1380,8 +1380,9 @@ TEST_F(CompactionServiceTest, CancelCompactionOnPrimarySide) {
// Primary DB calls CancelAllBackgroundWork() while the compaction is running
SyncPoint::GetInstance()->SetCallBack(
"CompactionJob::Run():Inprogress",
[&](void* /*arg*/) { CancelAllBackgroundWork(db_, false /*wait*/); });
"CompactionJob::Run():Inprogress", [&](void* /*arg*/) {
CancelAllBackgroundWork(db_.get(), false /*wait*/);
});
SyncPoint::GetInstance()->EnableProcessing();
+4 -4
View File
@@ -1717,8 +1717,8 @@ TEST_P(PrecludeLastLevelTest, MigrationFromPreserveTimePartial) {
ASSERT_EQ("0,0,0,0,0,0,1", FilesPerLevel());
std::vector<KeyVersion> key_versions;
ASSERT_OK(GetAllKeyVersions(db_, {}, {}, std::numeric_limits<size_t>::max(),
&key_versions));
ASSERT_OK(GetAllKeyVersions(
db_.get(), {}, {}, std::numeric_limits<size_t>::max(), &key_versions));
// make sure there're more than 300 keys and first 100 keys are having seqno
// zeroed out, the last 100 key seqno not zeroed out
@@ -2319,8 +2319,8 @@ TEST_P(PrecludeLastLevelTest, LastLevelOnlyCompactionPartial) {
ASSERT_GT(GetSstSizeHelper(Temperature::kUnknown), 0);
std::vector<KeyVersion> key_versions;
ASSERT_OK(GetAllKeyVersions(db_, {}, {}, std::numeric_limits<size_t>::max(),
&key_versions));
ASSERT_OK(GetAllKeyVersions(
db_.get(), {}, {}, std::numeric_limits<size_t>::max(), &key_versions));
// make sure there're more than 300 keys and first 100 keys are having seqno
// zeroed out, the last 100 key seqno not zeroed out
+6 -8
View File
@@ -258,12 +258,12 @@ class ComparatorDBTest
private:
std::string dbname_;
Env* env_;
DB* db_;
std::unique_ptr<DB> db_;
Options last_options_;
std::unique_ptr<const Comparator> comparator_guard;
public:
ComparatorDBTest() : env_(Env::Default()), db_(nullptr) {
ComparatorDBTest() : env_(Env::Default()) {
kTestComparator = BytewiseComparator();
dbname_ = test::PerThreadDBPath("comparator_db_test");
BlockBasedTableOptions toptions;
@@ -274,12 +274,12 @@ class ComparatorDBTest
}
~ComparatorDBTest() override {
delete db_;
db_.reset();
EXPECT_OK(DestroyDB(dbname_, last_options_));
kTestComparator = BytewiseComparator();
}
DB* GetDB() { return db_; }
DB* GetDB() { return db_.get(); }
void SetOwnedComparator(const Comparator* cmp, bool owner = true) {
if (owner) {
@@ -301,14 +301,12 @@ class ComparatorDBTest
}
void Destroy() {
delete db_;
db_ = nullptr;
db_.reset();
ASSERT_OK(DestroyDB(dbname_, last_options_));
}
Status TryReopen() {
delete db_;
db_ = nullptr;
db_.reset();
last_options_.create_if_missing = true;
return DB::Open(last_options_, dbname_, &db_);
+60 -88
View File
@@ -73,7 +73,7 @@ class CorruptionTest : public testing::Test {
std::string dbname_;
std::shared_ptr<Cache> tiny_cache_;
Options options_;
DB* db_;
std::unique_ptr<DB> db_;
CorruptionTest() {
// If LRU cache shard bit is smaller than 2 (or -1 which will automatically
@@ -105,8 +105,7 @@ class CorruptionTest : public testing::Test {
SyncPoint::GetInstance()->DisableProcessing();
SyncPoint::GetInstance()->LoadDependency({});
SyncPoint::GetInstance()->ClearAllCallBacks();
delete db_;
db_ = nullptr;
db_.reset();
if (getenv("KEEP_DB")) {
fprintf(stdout, "db is still at %s\n", dbname_.c_str());
} else {
@@ -116,14 +115,12 @@ class CorruptionTest : public testing::Test {
}
}
void CloseDb() {
delete db_;
db_ = nullptr;
}
void CloseDb() { db_.reset(); }
DBImpl* dbfull() { return static_cast_with_check<DBImpl>(db_.get()); }
Status TryReopen(Options* options = nullptr) {
delete db_;
db_ = nullptr;
db_.reset();
Options opt = (options ? *options : options_);
if (opt.env == Options().env) {
// If env is not overridden, replace it with ErrorEnv.
@@ -141,8 +138,7 @@ class CorruptionTest : public testing::Test {
void Reopen(Options* options = nullptr) { ASSERT_OK(TryReopen(options)); }
void RepairDB() {
delete db_;
db_ = nullptr;
db_.reset();
ASSERT_OK(::ROCKSDB_NAMESPACE::RepairDB(dbname_, options_));
}
@@ -151,8 +147,7 @@ class CorruptionTest : public testing::Test {
WriteBatch batch;
for (int i = 0; i < n; i++) {
if (flush_every != 0 && i != 0 && i % flush_every == 0) {
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbfull()->TEST_FlushMemTable());
}
// if ((i % 100) == 0) fprintf(stderr, "@ %d of %d\n", i, n);
Slice key = Key(i + start, &key_space);
@@ -436,14 +431,14 @@ TEST_F(CorruptionTest, NewFileErrorDuringWrite) {
TEST_F(CorruptionTest, TableFile) {
Build(100);
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
DBImpl* dbi = dbfull();
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbi->TEST_CompactRange(0, nullptr, nullptr));
ASSERT_OK(dbi->TEST_CompactRange(1, nullptr, nullptr));
Corrupt(kTableFile, 100, 1);
Check(99, 99);
ASSERT_NOK(dbi->VerifyChecksum());
ASSERT_NOK(db_->VerifyChecksum());
}
TEST_F(CorruptionTest, VerifyChecksumReadahead) {
@@ -460,14 +455,14 @@ TEST_F(CorruptionTest, VerifyChecksumReadahead) {
Reopen(&options);
Build(10000);
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
DBImpl* dbi = dbfull();
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbi->TEST_CompactRange(0, nullptr, nullptr));
ASSERT_OK(dbi->TEST_CompactRange(1, nullptr, nullptr));
senv.count_random_reads_ = true;
senv.random_read_counter_.Reset();
ASSERT_OK(dbi->VerifyChecksum());
ASSERT_OK(db_->VerifyChecksum());
// Make sure the counter is enabled.
ASSERT_GT(senv.random_read_counter_.Read(), 0);
@@ -480,7 +475,7 @@ TEST_F(CorruptionTest, VerifyChecksumReadahead) {
senv.random_read_bytes_counter_ = 0;
ReadOptions ro;
ro.readahead_size = size_t{32 * 1024};
ASSERT_OK(dbi->VerifyChecksum(ro));
ASSERT_OK(db_->VerifyChecksum(ro));
// The SST file is about 10MB. We set readahead size to 32KB.
// Give 0 to 20 reads for metadata blocks, and allow real read
// to range from 24KB to 48KB. The lower bound would be:
@@ -494,8 +489,7 @@ TEST_F(CorruptionTest, VerifyChecksumReadahead) {
// disabled).
options.allow_mmap_reads = true;
Reopen(&options);
dbi = static_cast<DBImpl*>(db_);
ASSERT_OK(dbi->VerifyChecksum(ro));
ASSERT_OK(db_->VerifyChecksum(ro));
CloseDb();
}
@@ -508,18 +502,16 @@ TEST_F(CorruptionTest, TableFileIndexData) {
Reopen(&options);
// build 2 tables, flush at 5000
Build(10000, 5000);
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbfull()->TEST_FlushMemTable());
// corrupt an index block of an entire file
Corrupt(kTableFile, -2000, 500);
options.paranoid_checks = false;
Reopen(&options);
dbi = static_cast_with_check<DBImpl>(db_);
// one full file may be readable, since only one was corrupted
// the other file should be fully non-readable, since index was corrupted
Check(0, 5000, ReadOptions(true, true));
ASSERT_NOK(dbi->VerifyChecksum());
ASSERT_NOK(db_->VerifyChecksum());
// In paranoid mode, the db cannot be opened due to the corrupted file.
ASSERT_TRUE(TryReopen().IsCorruption());
@@ -527,8 +519,7 @@ TEST_F(CorruptionTest, TableFileIndexData) {
TEST_F(CorruptionTest, TableFileFooterMagic) {
Build(100);
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbfull()->TEST_FlushMemTable());
Check(100, 100);
// Corrupt the whole footer
Corrupt(kTableFile, -100, 100);
@@ -543,8 +534,7 @@ TEST_F(CorruptionTest, TableFileFooterMagic) {
TEST_F(CorruptionTest, TableFileFooterNotMagic) {
Build(100);
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbfull()->TEST_FlushMemTable());
Check(100, 100);
// Corrupt footer except magic number
Corrupt(kTableFile, -100, 92);
@@ -579,8 +569,7 @@ TEST_F(CorruptionTest, DBOpenWithWrongFileSize) {
for (auto* cfh : cfhs) {
delete cfh;
}
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbfull()->TEST_FlushMemTable());
// ********************************************
// Corrupt the file by making the file bigger
@@ -601,7 +590,8 @@ TEST_F(CorruptionTest, DBOpenWithWrongFileSize) {
// true
options_.paranoid_checks = true;
std::vector<ColumnFamilyHandle*> cfhs;
auto s = DB::Open(options_, dbname_, cf_descs, &cfhs, &db_);
Status s;
s = DB::Open(options_, dbname_, cf_descs, &cfhs, &db_);
ASSERT_TRUE(s.IsCorruption());
ASSERT_TRUE(s.ToString().find("file size mismatch") != std::string::npos);
@@ -626,8 +616,7 @@ TEST_F(CorruptionTest, DBOpenWithWrongFileSize) {
TEST_F(CorruptionTest, TableFileWrongSize) {
Build(100);
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbfull()->TEST_FlushMemTable());
Check(100, 100);
// ********************************************
@@ -710,12 +699,11 @@ TEST_F(CorruptionTest, SequenceNumberRecovery) {
TEST_F(CorruptionTest, CorruptedDescriptor) {
ASSERT_OK(db_->Put(WriteOptions(), "foo", "hello"));
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbfull()->TEST_FlushMemTable());
CompactRangeOptions cro;
cro.bottommost_level_compaction = BottommostLevelCompaction::kForce;
ASSERT_OK(
dbi->CompactRange(cro, dbi->DefaultColumnFamily(), nullptr, nullptr));
db_->CompactRange(cro, db_->DefaultColumnFamily(), nullptr, nullptr));
Corrupt(kDescriptorFile, 0, 1000);
Status s = TryReopen();
@@ -734,7 +722,7 @@ TEST_F(CorruptionTest, CompactionInputError) {
options.env = env_.get();
Reopen(&options);
Build(10);
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
DBImpl* dbi = dbfull();
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbi->TEST_CompactRange(0, nullptr, nullptr));
ASSERT_OK(dbi->TEST_CompactRange(1, nullptr, nullptr));
@@ -742,12 +730,12 @@ TEST_F(CorruptionTest, CompactionInputError) {
Corrupt(kTableFile, 100, 1);
Check(9, 9);
ASSERT_NOK(dbi->VerifyChecksum());
ASSERT_NOK(db_->VerifyChecksum());
// Force compactions by writing lots of values
Build(10000);
Check(10000, 10000);
ASSERT_NOK(dbi->VerifyChecksum());
ASSERT_NOK(db_->VerifyChecksum());
}
TEST_F(CorruptionTest, CompactionInputErrorParanoid) {
@@ -758,14 +746,14 @@ TEST_F(CorruptionTest, CompactionInputErrorParanoid) {
options.write_buffer_size = 131072;
options.max_write_buffer_number = 2;
Reopen(&options);
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
DBImpl* dbi = dbfull();
// Fill levels >= 1
for (int level = 1; level < dbi->NumberLevels(); level++) {
ASSERT_OK(dbi->Put(WriteOptions(), "", "begin"));
ASSERT_OK(dbi->Put(WriteOptions(), "~", "end"));
for (int level = 1; level < db_->NumberLevels(); level++) {
ASSERT_OK(db_->Put(WriteOptions(), "", "begin"));
ASSERT_OK(db_->Put(WriteOptions(), "~", "end"));
ASSERT_OK(dbi->TEST_FlushMemTable());
for (int comp_level = 0; comp_level < dbi->NumberLevels() - level;
for (int comp_level = 0; comp_level < db_->NumberLevels() - level;
++comp_level) {
ASSERT_OK(dbi->TEST_CompactRange(comp_level, nullptr, nullptr));
}
@@ -773,7 +761,7 @@ TEST_F(CorruptionTest, CompactionInputErrorParanoid) {
Reopen(&options);
dbi = static_cast_with_check<DBImpl>(db_);
dbi = dbfull();
Build(10);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbi->TEST_WaitForCompact());
@@ -781,7 +769,7 @@ TEST_F(CorruptionTest, CompactionInputErrorParanoid) {
CorruptTableFileAtLevel(0, 100, 1);
Check(9, 9);
ASSERT_NOK(dbi->VerifyChecksum());
ASSERT_NOK(db_->VerifyChecksum());
// Write must eventually fail because of corrupted table
Status s;
@@ -800,17 +788,16 @@ TEST_F(CorruptionTest, CompactionInputErrorParanoid) {
TEST_F(CorruptionTest, UnrelatedKeys) {
Build(10);
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbfull()->TEST_FlushMemTable());
Corrupt(kTableFile, 100, 1);
ASSERT_NOK(dbi->VerifyChecksum());
ASSERT_NOK(db_->VerifyChecksum());
std::string tmp1, tmp2;
ASSERT_OK(db_->Put(WriteOptions(), Key(1000, &tmp1), Value(1000, &tmp2)));
std::string v;
ASSERT_OK(db_->Get(ReadOptions(), Key(1000, &tmp1), &v));
ASSERT_EQ(Value(1000, &tmp2).ToString(), v);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbfull()->TEST_FlushMemTable());
ASSERT_OK(db_->Get(ReadOptions(), Key(1000, &tmp1), &v));
ASSERT_EQ(Value(1000, &tmp2).ToString(), v);
}
@@ -857,14 +844,12 @@ TEST_F(CorruptionTest, FileSystemStateCorrupted) {
Reopen(&options);
Build(10);
ASSERT_OK(db_->Flush(FlushOptions()));
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
std::vector<LiveFileMetaData> metadata;
dbi->GetLiveFilesMetaData(&metadata);
db_->GetLiveFilesMetaData(&metadata);
ASSERT_GT(metadata.size(), 0);
std::string filename = dbname_ + metadata[0].name;
delete db_;
db_ = nullptr;
db_.reset();
if (iter == 0) { // corrupt file size
std::unique_ptr<WritableFile> file;
@@ -896,8 +881,7 @@ TEST_F(CorruptionTest, ParanoidFileChecksOnFlush) {
options.create_if_missing = true;
Status s;
for (const auto& mode : corruption_modes) {
delete db_;
db_ = nullptr;
db_.reset();
s = DestroyDB(dbname_, options);
ASSERT_OK(s);
std::shared_ptr<mock::MockTableFactory> mock =
@@ -924,8 +908,7 @@ TEST_F(CorruptionTest, ParanoidFileChecksOnCompact) {
options.create_if_missing = true;
Status s;
for (const auto& mode : corruption_modes) {
delete db_;
db_ = nullptr;
db_.reset();
s = DestroyDB(dbname_, options);
ASSERT_OK(s);
std::shared_ptr<mock::MockTableFactory> mock =
@@ -934,12 +917,11 @@ TEST_F(CorruptionTest, ParanoidFileChecksOnCompact) {
ASSERT_OK(DB::Open(options, dbname_, &db_));
assert(db_ != nullptr); // suppress false clang-analyze report
Build(100, 2);
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbfull()->TEST_FlushMemTable());
mock->SetCorruptionMode(mode);
CompactRangeOptions cro;
cro.bottommost_level_compaction = BottommostLevelCompaction::kForce;
s = dbi->CompactRange(cro, dbi->DefaultColumnFamily(), nullptr, nullptr);
s = db_->CompactRange(cro, db_->DefaultColumnFamily(), nullptr, nullptr);
if (mode == mock::MockTableFactory::kCorruptNone) {
ASSERT_OK(s);
} else {
@@ -955,8 +937,7 @@ TEST_F(CorruptionTest, ParanoidFileChecksWithDeleteRangeFirst) {
options.paranoid_file_checks = true;
options.create_if_missing = true;
for (bool do_flush : {true, false}) {
delete db_;
db_ = nullptr;
db_.reset();
ASSERT_OK(DestroyDB(dbname_, options));
ASSERT_OK(DB::Open(options, dbname_, &db_));
std::string start, end;
@@ -973,12 +954,11 @@ TEST_F(CorruptionTest, ParanoidFileChecksWithDeleteRangeFirst) {
if (do_flush) {
ASSERT_OK(db_->Flush(FlushOptions()));
} else {
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbfull()->TEST_FlushMemTable());
CompactRangeOptions cro;
cro.bottommost_level_compaction = BottommostLevelCompaction::kForce;
ASSERT_OK(
dbi->CompactRange(cro, dbi->DefaultColumnFamily(), nullptr, nullptr));
db_->CompactRange(cro, db_->DefaultColumnFamily(), nullptr, nullptr));
}
db_->ReleaseSnapshot(snap);
}
@@ -991,8 +971,7 @@ TEST_F(CorruptionTest, ParanoidFileChecksWithDeleteRange) {
options.paranoid_file_checks = true;
options.create_if_missing = true;
for (bool do_flush : {true, false}) {
delete db_;
db_ = nullptr;
db_.reset();
ASSERT_OK(DestroyDB(dbname_, options));
ASSERT_OK(DB::Open(options, dbname_, &db_));
assert(db_ != nullptr); // suppress false clang-analyze report
@@ -1012,12 +991,11 @@ TEST_F(CorruptionTest, ParanoidFileChecksWithDeleteRange) {
if (do_flush) {
ASSERT_OK(db_->Flush(FlushOptions()));
} else {
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbfull()->TEST_FlushMemTable());
CompactRangeOptions cro;
cro.bottommost_level_compaction = BottommostLevelCompaction::kForce;
ASSERT_OK(
dbi->CompactRange(cro, dbi->DefaultColumnFamily(), nullptr, nullptr));
db_->CompactRange(cro, db_->DefaultColumnFamily(), nullptr, nullptr));
}
db_->ReleaseSnapshot(snap);
}
@@ -1030,8 +1008,7 @@ TEST_F(CorruptionTest, ParanoidFileChecksWithDeleteRangeLast) {
options.paranoid_file_checks = true;
options.create_if_missing = true;
for (bool do_flush : {true, false}) {
delete db_;
db_ = nullptr;
db_.reset();
ASSERT_OK(DestroyDB(dbname_, options));
ASSERT_OK(DB::Open(options, dbname_, &db_));
assert(db_ != nullptr); // suppress false clang-analyze report
@@ -1048,12 +1025,11 @@ TEST_F(CorruptionTest, ParanoidFileChecksWithDeleteRangeLast) {
if (do_flush) {
ASSERT_OK(db_->Flush(FlushOptions()));
} else {
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbfull()->TEST_FlushMemTable());
CompactRangeOptions cro;
cro.bottommost_level_compaction = BottommostLevelCompaction::kForce;
ASSERT_OK(
dbi->CompactRange(cro, dbi->DefaultColumnFamily(), nullptr, nullptr));
db_->CompactRange(cro, db_->DefaultColumnFamily(), nullptr, nullptr));
}
db_->ReleaseSnapshot(snap);
}
@@ -1066,8 +1042,7 @@ TEST_F(CorruptionTest, LogCorruptionErrorsInCompactionIterator) {
options.create_if_missing = true;
options.allow_data_in_errors = true;
auto mode = mock::MockTableFactory::kCorruptKey;
delete db_;
db_ = nullptr;
db_.reset();
ASSERT_OK(DestroyDB(dbname_, options));
std::shared_ptr<mock::MockTableFactory> mock =
@@ -1079,12 +1054,11 @@ TEST_F(CorruptionTest, LogCorruptionErrorsInCompactionIterator) {
assert(db_ != nullptr); // suppress false clang-analyze report
Build(100, 2);
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbfull()->TEST_FlushMemTable());
CompactRangeOptions cro;
cro.bottommost_level_compaction = BottommostLevelCompaction::kForce;
Status s =
dbi->CompactRange(cro, dbi->DefaultColumnFamily(), nullptr, nullptr);
db_->CompactRange(cro, db_->DefaultColumnFamily(), nullptr, nullptr);
ASSERT_NOK(s);
ASSERT_TRUE(s.IsCorruption());
}
@@ -1095,8 +1069,7 @@ TEST_F(CorruptionTest, CompactionKeyOrderCheck) {
options.env = env_.get();
options.paranoid_file_checks = false;
options.create_if_missing = true;
delete db_;
db_ = nullptr;
db_.reset();
ASSERT_OK(DestroyDB(dbname_, options));
std::shared_ptr<mock::MockTableFactory> mock =
std::make_shared<mock::MockTableFactory>();
@@ -1105,14 +1078,13 @@ TEST_F(CorruptionTest, CompactionKeyOrderCheck) {
assert(db_ != nullptr); // suppress false clang-analyze report
mock->SetCorruptionMode(mock::MockTableFactory::kCorruptReorderKey);
Build(100, 2);
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
ASSERT_OK(dbi->TEST_FlushMemTable());
ASSERT_OK(dbfull()->TEST_FlushMemTable());
mock->SetCorruptionMode(mock::MockTableFactory::kCorruptNone);
CompactRangeOptions cro;
cro.bottommost_level_compaction = BottommostLevelCompaction::kForce;
ASSERT_NOK(
dbi->CompactRange(cro, dbi->DefaultColumnFamily(), nullptr, nullptr));
db_->CompactRange(cro, db_->DefaultColumnFamily(), nullptr, nullptr));
}
TEST_F(CorruptionTest, FlushKeyOrderCheck) {
@@ -1139,7 +1111,7 @@ TEST_F(CorruptionTest, FlushKeyOrderCheck) {
}
});
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
Status s = static_cast_with_check<DBImpl>(db_)->TEST_FlushMemTable();
Status s = dbfull()->TEST_FlushMemTable();
ASSERT_NOK(s);
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks();
@@ -1263,7 +1235,7 @@ TEST_P(CrashDuringRecoveryWithCorruptionTest, CrashDuringRecovery) {
// while other don't.
{
ASSERT_OK(DB::Open(options, dbname_, cf_descs, &handles, &db_));
auto* dbimpl = static_cast_with_check<DBImpl>(db_);
auto* dbimpl = dbfull();
assert(dbimpl);
// Write one key to test_cf.
+10 -12
View File
@@ -21,18 +21,18 @@ class CuckooTableDBTest : public testing::Test {
private:
std::string dbname_;
Env* env_;
DB* db_;
std::unique_ptr<DB> db_;
public:
CuckooTableDBTest() : env_(Env::Default()) {
dbname_ = test::PerThreadDBPath("cuckoo_table_db_test");
EXPECT_OK(DestroyDB(dbname_, Options()));
db_ = nullptr;
db_.reset();
Reopen();
}
~CuckooTableDBTest() override {
delete db_;
db_.reset();
EXPECT_OK(DestroyDB(dbname_, Options()));
}
@@ -47,12 +47,11 @@ class CuckooTableDBTest : public testing::Test {
return options;
}
DBImpl* dbfull() { return static_cast_with_check<DBImpl>(db_); }
DBImpl* dbfull() { return static_cast_with_check<DBImpl>(db_.get()); }
// The following util methods are copied from plain_table_db_test.
void Reopen(Options* options = nullptr) {
delete db_;
db_ = nullptr;
db_.reset();
Options opts;
if (options != nullptr) {
opts = *options;
@@ -66,8 +65,7 @@ class CuckooTableDBTest : public testing::Test {
void DestroyAndReopen(Options* options) {
assert(options);
ASSERT_OK(db_->Close());
delete db_;
db_ = nullptr;
db_.reset();
ASSERT_OK(DestroyDB(dbname_, *options));
Reopen(options);
}
@@ -130,7 +128,7 @@ TEST_F(CuckooTableDBTest, Flush) {
ASSERT_OK(dbfull()->TEST_FlushMemTable());
TablePropertiesCollection ptc;
ASSERT_OK(static_cast<DB*>(dbfull())->GetPropertiesOfAllTables(&ptc));
ASSERT_OK(dbfull()->GetPropertiesOfAllTables(&ptc));
VerifySstUniqueIds(ptc);
ASSERT_EQ(1U, ptc.size());
ASSERT_EQ(3U, ptc.begin()->second->num_entries);
@@ -147,7 +145,7 @@ TEST_F(CuckooTableDBTest, Flush) {
ASSERT_OK(Put("key6", "v6"));
ASSERT_OK(dbfull()->TEST_FlushMemTable());
ASSERT_OK(static_cast<DB*>(dbfull())->GetPropertiesOfAllTables(&ptc));
ASSERT_OK(dbfull()->GetPropertiesOfAllTables(&ptc));
VerifySstUniqueIds(ptc);
ASSERT_EQ(2U, ptc.size());
auto row = ptc.begin();
@@ -165,7 +163,7 @@ TEST_F(CuckooTableDBTest, Flush) {
ASSERT_OK(Delete("key5"));
ASSERT_OK(Delete("key4"));
ASSERT_OK(dbfull()->TEST_FlushMemTable());
ASSERT_OK(static_cast<DB*>(dbfull())->GetPropertiesOfAllTables(&ptc));
ASSERT_OK(dbfull()->GetPropertiesOfAllTables(&ptc));
VerifySstUniqueIds(ptc);
ASSERT_EQ(3U, ptc.size());
row = ptc.begin();
@@ -190,7 +188,7 @@ TEST_F(CuckooTableDBTest, FlushWithDuplicateKeys) {
ASSERT_OK(dbfull()->TEST_FlushMemTable());
TablePropertiesCollection ptc;
ASSERT_OK(static_cast<DB*>(dbfull())->GetPropertiesOfAllTables(&ptc));
ASSERT_OK(dbfull()->GetPropertiesOfAllTables(&ptc));
VerifySstUniqueIds(ptc);
ASSERT_EQ(1U, ptc.size());
ASSERT_EQ(2U, ptc.begin()->second->num_entries);
+33 -40
View File
@@ -91,17 +91,15 @@ class DBBasicTest : public DBTestBase {
TEST_F(DBBasicTest, OpenWhenOpen) {
Options options = CurrentOptions();
options.env = env_;
DB* db2 = nullptr;
std::unique_ptr<DB> db2;
Status s = DB::Open(options, dbname_, &db2);
ASSERT_NOK(s) << [db2]() {
delete db2;
ASSERT_NOK(s) << [&db2]() {
db2.reset();
return "db2 open: ok";
}();
ASSERT_EQ(Status::Code::kIOError, s.code());
ASSERT_EQ(Status::SubCode::kNone, s.subcode());
ASSERT_TRUE(strstr(s.getState(), "lock ") != nullptr);
delete db2;
}
TEST_F(DBBasicTest, EnableDirectIOWithZeroBuf) {
@@ -586,14 +584,14 @@ TEST_F(DBBasicTest, GetSnapshot) {
TEST_F(DBBasicTest, CheckLock) {
do {
DB* localdb = nullptr;
std::unique_ptr<DB> localdb;
Options options = CurrentOptions();
ASSERT_OK(TryReopen(options));
// second open should fail
Status s = DB::Open(options, dbname_, &localdb);
ASSERT_NOK(s) << [localdb]() {
delete localdb;
ASSERT_NOK(s) << [&localdb]() {
localdb.reset();
return "localdb open: ok";
}();
#ifdef OS_LINUX
@@ -862,7 +860,7 @@ TEST_F(DBBasicTest, Snapshot) {
ASSERT_OK(Put(1, "foo", "1v3"));
{
ManagedSnapshot s3(db_);
ManagedSnapshot s3(db_.get());
ASSERT_EQ(3U, GetNumSnapshots());
ASSERT_EQ(time_snap1, GetTimeOldestSnapshots());
ASSERT_EQ(GetSequenceOldestSnapshots(), s1->GetSequenceNumber());
@@ -985,7 +983,7 @@ TEST_F(DBBasicTest, DBOpen_Options) {
Destroy(options);
// Does not exist, and create_if_missing == false: error
DB* db = nullptr;
std::unique_ptr<DB> db;
options.create_if_missing = false;
Status s = DB::Open(options, dbname_, &db);
ASSERT_TRUE(strstr(s.ToString().c_str(), "does not exist") != nullptr);
@@ -997,8 +995,7 @@ TEST_F(DBBasicTest, DBOpen_Options) {
ASSERT_OK(s);
ASSERT_TRUE(db != nullptr);
delete db;
db = nullptr;
db.reset();
// Does exist, and error_if_exists == true: error
options.create_if_missing = false;
@@ -1014,8 +1011,7 @@ TEST_F(DBBasicTest, DBOpen_Options) {
ASSERT_OK(s);
ASSERT_TRUE(db != nullptr);
delete db;
db = nullptr;
db.reset();
}
TEST_F(DBBasicTest, CompactOnFlush) {
@@ -1320,7 +1316,7 @@ TEST_F(DBBasicTest, DBClose) {
std::string dbname = test::PerThreadDBPath("db_close_test");
ASSERT_OK(DestroyDB(dbname, options));
DB* db = nullptr;
std::unique_ptr<DB> db;
TestEnv* env = new TestEnv(env_);
std::unique_ptr<TestEnv> local_env_guard(env);
options.create_if_missing = true;
@@ -1333,14 +1329,14 @@ TEST_F(DBBasicTest, DBClose) {
ASSERT_EQ(env->GetCloseCount(), 1);
ASSERT_EQ(s, Status::IOError());
delete db;
db.reset();
ASSERT_EQ(env->GetCloseCount(), 1);
// Do not call DB::Close() and ensure our logger Close() still gets called
s = DB::Open(options, dbname, &db);
ASSERT_OK(s);
ASSERT_TRUE(db != nullptr);
delete db;
db.reset();
ASSERT_EQ(env->GetCloseCount(), 2);
// close by WaitForCompact() with close_db option
@@ -1355,7 +1351,7 @@ TEST_F(DBBasicTest, DBClose) {
// see TestLogger::CloseHelper()
ASSERT_EQ(s, Status::IOError());
delete db;
db.reset();
ASSERT_EQ(env->GetCloseCount(), 3);
// Provide our own logger and ensure DB::Close() does not close it
@@ -1366,7 +1362,7 @@ TEST_F(DBBasicTest, DBClose) {
s = db->Close();
ASSERT_EQ(s, Status::OK());
delete db;
db.reset();
ASSERT_EQ(env->GetCloseCount(), 3);
options.info_log.reset();
ASSERT_EQ(env->GetCloseCount(), 4);
@@ -1384,7 +1380,7 @@ TEST_F(DBBasicTest, DBCloseAllDirectoryFDs) {
ASSERT_OK(DestroyDB(dbname, options));
DB* db = nullptr;
std::unique_ptr<DB> db;
std::unique_ptr<Env> env = NewCompositeEnv(
std::make_shared<CountedFileSystem>(FileSystem::Default()));
options.create_if_missing = true;
@@ -1402,7 +1398,7 @@ TEST_F(DBBasicTest, DBCloseAllDirectoryFDs) {
ASSERT_EQ(counted_fs->counters()->dir_opens,
counted_fs->counters()->dir_closes);
ASSERT_OK(s);
delete db;
db.reset();
}
TEST_F(DBBasicTest, DBCloseFlushError) {
@@ -1464,7 +1460,7 @@ TEST_P(DBMultiGetTestWithParam, MultiGetMultiCF) {
}
int get_sv_count = 0;
ROCKSDB_NAMESPACE::DBImpl* db = static_cast_with_check<DBImpl>(db_);
ROCKSDB_NAMESPACE::DBImpl* db = dbfull();
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
"DBImpl::MultiCFSnapshot::AfterRefSV", [&](void* /*arg*/) {
if (++get_sv_count == 2) {
@@ -1536,10 +1532,9 @@ TEST_P(DBMultiGetTestWithParam, MultiGetMultiCF) {
ASSERT_EQ(values[2], std::get<2>(cf_kv_vec[1]) + "_2");
for (int cf = 0; cf < 8; ++cf) {
auto* cfd =
static_cast_with_check<ColumnFamilyHandleImpl>(
static_cast_with_check<DBImpl>(db_)->GetColumnFamilyHandle(cf))
->cfd();
auto* cfd = static_cast_with_check<ColumnFamilyHandleImpl>(
dbfull()->GetColumnFamilyHandle(cf))
->cfd();
ASSERT_NE(cfd->TEST_GetLocalSV()->Get(), SuperVersion::kSVInUse);
ASSERT_NE(cfd->TEST_GetLocalSV()->Get(), SuperVersion::kSVObsolete);
}
@@ -1625,10 +1620,9 @@ TEST_P(DBMultiGetTestWithParam, MultiGetMultiCFMutex) {
"cf" + std::to_string(j) + "_val" + std::to_string(retries));
}
for (int i = 0; i < 8; ++i) {
auto* cfd =
static_cast_with_check<ColumnFamilyHandleImpl>(
static_cast_with_check<DBImpl>(db_)->GetColumnFamilyHandle(i))
->cfd();
auto* cfd = static_cast_with_check<ColumnFamilyHandleImpl>(
dbfull()->GetColumnFamilyHandle(i))
->cfd();
ASSERT_NE(cfd->TEST_GetLocalSV()->Get(), SuperVersion::kSVInUse);
}
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
@@ -1652,7 +1646,7 @@ TEST_P(DBMultiGetTestWithParam, MultiGetMultiCFSnapshot) {
}
int get_sv_count = 0;
ROCKSDB_NAMESPACE::DBImpl* db = static_cast_with_check<DBImpl>(db_);
ROCKSDB_NAMESPACE::DBImpl* db = dbfull();
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
"DBImpl::MultiCFSnapshot::AfterRefSV", [&](void* /*arg*/) {
if (++get_sv_count == 2) {
@@ -1693,10 +1687,9 @@ TEST_P(DBMultiGetTestWithParam, MultiGetMultiCFSnapshot) {
ASSERT_EQ(values[j], "cf" + std::to_string(j) + "_val");
}
for (int i = 0; i < 8; ++i) {
auto* cfd =
static_cast_with_check<ColumnFamilyHandleImpl>(
static_cast_with_check<DBImpl>(db_)->GetColumnFamilyHandle(i))
->cfd();
auto* cfd = static_cast_with_check<ColumnFamilyHandleImpl>(
dbfull()->GetColumnFamilyHandle(i))
->cfd();
ASSERT_NE(cfd->TEST_GetLocalSV()->Get(), SuperVersion::kSVInUse);
}
}
@@ -3301,8 +3294,8 @@ TEST_F(DBBasicTest, GetAllKeyVersions) {
ASSERT_OK(Delete(std::to_string(i)));
}
std::vector<KeyVersion> key_versions;
ASSERT_OK(GetAllKeyVersions(db_, {}, {}, std::numeric_limits<size_t>::max(),
&key_versions));
ASSERT_OK(GetAllKeyVersions(
db_.get(), {}, {}, std::numeric_limits<size_t>::max(), &key_versions));
ASSERT_EQ(kNumInserts + kNumDeletes + kNumUpdates, key_versions.size());
for (size_t i = 0; i < kNumInserts + kNumDeletes + kNumUpdates; i++) {
if (i % 3 == 0) {
@@ -3311,7 +3304,7 @@ TEST_F(DBBasicTest, GetAllKeyVersions) {
ASSERT_EQ(key_versions[i].GetTypeName(), "TypeValue");
}
}
ASSERT_OK(GetAllKeyVersions(db_, handles_[0], {}, {},
ASSERT_OK(GetAllKeyVersions(db_.get(), handles_[0], {}, {},
std::numeric_limits<size_t>::max(),
&key_versions));
ASSERT_EQ(kNumInserts + kNumDeletes + kNumUpdates, key_versions.size());
@@ -3326,14 +3319,14 @@ TEST_F(DBBasicTest, GetAllKeyVersions) {
for (size_t i = 0; i + 1 != kNumDeletes; ++i) {
ASSERT_OK(Delete(1, std::to_string(i)));
}
ASSERT_OK(GetAllKeyVersions(db_, handles_[1], {}, {},
ASSERT_OK(GetAllKeyVersions(db_.get(), handles_[1], {}, {},
std::numeric_limits<size_t>::max(),
&key_versions));
ASSERT_EQ(kNumInserts + kNumDeletes + kNumUpdates - 3, key_versions.size());
// Change from historical behavior: empty key is now interpreted literally as
// a legal key (rather than as a "not present" key)
ASSERT_OK(GetAllKeyVersions(db_, handles_[1], Slice(), Slice(),
ASSERT_OK(GetAllKeyVersions(db_.get(), handles_[1], Slice(), Slice(),
std::numeric_limits<size_t>::max(),
&key_versions));
ASSERT_EQ(key_versions.size(), 0);
+2 -2
View File
@@ -1661,7 +1661,7 @@ TEST_P(DBBlockCacheKeyTest, StableCacheKeys) {
std::string export_files_dir = dbname_ + "/exported";
ExportImportFilesMetaData* metadata_ptr_ = nullptr;
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->ExportColumnFamily(handles_[1], export_files_dir,
&metadata_ptr_));
ASSERT_NE(metadata_ptr_, nullptr);
@@ -1698,7 +1698,7 @@ TEST_P(DBBlockCacheKeyTest, StableCacheKeys) {
// StableCacheKeyTestFS, Checkpoint will resort to full copy not hard link.
// (Checkpoint not available in LITE mode to test this.)
auto db_copy_name = dbname_ + "-copy";
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->CreateCheckpoint(db_copy_name));
delete checkpoint;
+1 -1
View File
@@ -4145,7 +4145,7 @@ TEST_F(DBBloomFilterTest, SstQueryFilter) {
using Keys = std::vector<std::string>;
auto RangeQuery =
[factory, db = db_](
[factory, db = db_.get()](
std::string lb, std::string ub,
std::shared_ptr<SstQueryFilterConfigsManager::Factory> alt_factory =
nullptr) {
+16 -12
View File
@@ -2208,7 +2208,8 @@ TEST_P(DBDeleteFileRangeTest, DeleteFileRange) {
std::string end_string = Key(2000);
Slice begin(begin_string);
Slice end(end_string);
ASSERT_OK(DeleteFilesInRange(db_, db_->DefaultColumnFamily(), &begin, &end));
ASSERT_OK(
DeleteFilesInRange(db_.get(), db_->DefaultColumnFamily(), &begin, &end));
int32_t deleted_count = 0;
for (int32_t i = 0; i < 4300; i++) {
@@ -2229,8 +2230,8 @@ TEST_P(DBDeleteFileRangeTest, DeleteFileRange) {
Slice begin1(begin_string);
Slice end1(end_string);
// Try deleting files in range which contain no keys
ASSERT_OK(
DeleteFilesInRange(db_, db_->DefaultColumnFamily(), &begin1, &end1));
ASSERT_OK(DeleteFilesInRange(db_.get(), db_->DefaultColumnFamily(), &begin1,
&end1));
// Push data from level 0 to level 1 to force all data to be deleted
// Note that we don't delete level 0 files
@@ -2239,8 +2240,8 @@ TEST_P(DBDeleteFileRangeTest, DeleteFileRange) {
ASSERT_OK(db_->CompactRange(compact_options, nullptr, nullptr));
ASSERT_OK(dbfull()->TEST_WaitForCompact());
ASSERT_OK(
DeleteFilesInRange(db_, db_->DefaultColumnFamily(), nullptr, nullptr));
ASSERT_OK(DeleteFilesInRange(db_.get(), db_->DefaultColumnFamily(), nullptr,
nullptr));
int32_t deleted_count2 = 0;
for (int32_t i = 0; i < 4300; i++) {
@@ -2308,7 +2309,7 @@ TEST_P(DBDeleteFileRangeTest, DeleteFilesInRanges) {
ranges.emplace_back(begin_str1, end_str1);
ranges.emplace_back(begin_str2, end_str2);
ranges.emplace_back(begin_str3, end_str3);
ASSERT_OK(DeleteFilesInRanges(db_, db_->DefaultColumnFamily(),
ASSERT_OK(DeleteFilesInRanges(db_.get(), db_->DefaultColumnFamily(),
ranges.data(), ranges.size()));
ASSERT_EQ("0,3,7", FilesPerLevel(0));
@@ -2335,7 +2336,7 @@ TEST_P(DBDeleteFileRangeTest, DeleteFilesInRanges) {
ranges.emplace_back(&begin1, &end1);
ranges.emplace_back(&begin2, &end2);
ranges.emplace_back(&begin3, &end3);
ASSERT_OK(DeleteFilesInRanges(db_, db_->DefaultColumnFamily(),
ASSERT_OK(DeleteFilesInRanges(db_.get(), db_->DefaultColumnFamily(),
ranges.data(), ranges.size(), false));
ASSERT_EQ("0,1,4", FilesPerLevel(0));
@@ -2356,7 +2357,8 @@ TEST_P(DBDeleteFileRangeTest, DeleteFilesInRanges) {
// Delete all files.
{
RangeOpt range;
ASSERT_OK(DeleteFilesInRanges(db_, db_->DefaultColumnFamily(), &range, 1));
ASSERT_OK(
DeleteFilesInRanges(db_.get(), db_->DefaultColumnFamily(), &range, 1));
ASSERT_EQ("", FilesPerLevel(0));
for (auto i = 0; i < 1000; i++) {
@@ -2418,7 +2420,8 @@ TEST_P(DBDeleteFileRangeTest, DeleteFileRangeFileEndpointsOverlapBug) {
// "1 -> vals[0]" to reappear.
std::string begin_str = Key(0), end_str = Key(1);
Slice begin = begin_str, end = end_str;
ASSERT_OK(DeleteFilesInRange(db_, db_->DefaultColumnFamily(), &begin, &end));
ASSERT_OK(
DeleteFilesInRange(db_.get(), db_->DefaultColumnFamily(), &begin, &end));
ASSERT_EQ(vals[1], GetValue(Key(1)));
db_->ReleaseSnapshot(snapshot);
@@ -3657,7 +3660,7 @@ TEST_F(DBCompactionTest, SuggestCompactRangeNoTwoLevel0Compactions) {
GenerateNewRandomFile(&rnd, /* nowait */ true);
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
ASSERT_OK(experimental::SuggestCompactRange(db_, nullptr, nullptr));
ASSERT_OK(experimental::SuggestCompactRange(db_.get(), nullptr, nullptr));
for (int num = 0; num < options.level0_file_num_compaction_trigger + 1;
num++) {
GenerateNewRandomFile(&rnd, /* nowait */ true);
@@ -4533,7 +4536,8 @@ TEST_F(DBCompactionTest, DeleteFilesInRangeConflictWithCompaction) {
std::string end_string = Key(kMaxKey + 1);
Slice begin(begin_string);
Slice end(end_string);
ASSERT_OK(DeleteFilesInRange(db_, db_->DefaultColumnFamily(), &begin, &end));
ASSERT_OK(
DeleteFilesInRange(db_.get(), db_->DefaultColumnFamily(), &begin, &end));
SyncPoint::GetInstance()->DisableProcessing();
}
@@ -8063,7 +8067,7 @@ TEST_F(DBCompactionTest, CompactFilesSupportKeyPlacementRangeConflict) {
ASSERT_OK(Flush());
ASSERT_OK(Put("k4", "v"));
ASSERT_OK(Flush());
ASSERT_OK(experimental::PromoteL0(db_, db_->DefaultColumnFamily(), 1));
ASSERT_OK(experimental::PromoteL0(db_.get(), db_->DefaultColumnFamily(), 1));
ASSERT_EQ("0,2,1", FilesPerLevel());
ASSERT_OK(Put("k2", "v"));
+5 -6
View File
@@ -709,7 +709,7 @@ class TestFlushListener : public EventListener {
// that assumption does not hold (see the test case MultiDBMultiListeners
// below).
ASSERT_TRUE(test_);
if (db == test_->db_) {
if (db == test_->db_.get()) {
std::vector<std::vector<FileMetaData>> files_by_level;
test_->dbfull()->TEST_GetFilesMetaData(db->DefaultColumnFamily(),
&files_by_level);
@@ -2533,7 +2533,7 @@ TEST_F(DBFlushTest, TombstoneVisibleInSnapshot) {
ASSERT_OK(db_->Put(WriteOptions(), "foo", "value0"));
ManagedSnapshot snapshot_guard(db_);
ManagedSnapshot snapshot_guard(db_.get());
ColumnFamilyHandle* default_cf = db_->DefaultColumnFamily();
ASSERT_OK(db_->Flush(FlushOptions(), default_cf));
@@ -2574,7 +2574,7 @@ TEST_P(DBAtomicFlushTest, ManualFlushUnder2PC) {
txn_db_opts.write_policy = TxnDBWritePolicy::WRITE_COMMITTED;
ASSERT_OK(TransactionDB::Open(options, txn_db_opts, dbname_, &txn_db));
ASSERT_NE(txn_db, nullptr);
db_ = txn_db;
db_.reset(txn_db);
// Create two more columns other than default CF.
std::vector<std::string> cfs = {"puppy", "kitty"};
@@ -2638,9 +2638,8 @@ TEST_P(DBAtomicFlushTest, ManualFlushUnder2PC) {
// it means atomic flush didn't write the min_log_number_to_keep to MANIFEST.
cfs.push_back(kDefaultColumnFamilyName);
ASSERT_OK(TryReopenWithColumnFamilies(cfs, options));
DBImpl* db_impl = static_cast<DBImpl*>(db_);
ASSERT_TRUE(db_impl->allow_2pc());
ASSERT_NE(db_impl->MinLogNumberToKeep(), 0);
ASSERT_TRUE(dbfull()->allow_2pc());
ASSERT_NE(dbfull()->MinLogNumberToKeep(), 0);
}
TEST_P(DBAtomicFlushTest, ManualAtomicFlush) {
-2
View File
@@ -469,8 +469,6 @@ class DBImpl : public DB {
using DB::NumberLevels;
int NumberLevels(ColumnFamilyHandle* column_family) override;
using DB::MaxMemCompactionLevel;
int MaxMemCompactionLevel(ColumnFamilyHandle* column_family) override;
using DB::Level0StopWriteTrigger;
int Level0StopWriteTrigger(ColumnFamilyHandle* column_family) override;
const std::string& GetName() const override;
-4
View File
@@ -2025,10 +2025,6 @@ int DBImpl::NumberLevels(ColumnFamilyHandle* column_family) {
return cfh->cfd()->NumberLevels();
}
int DBImpl::MaxMemCompactionLevel(ColumnFamilyHandle* /*column_family*/) {
return 0;
}
int DBImpl::Level0StopWriteTrigger(ColumnFamilyHandle* column_family) {
auto cfh = static_cast_with_check<ColumnFamilyHandleImpl>(column_family);
InstrumentedMutexLock l(&mutex_);
+4 -4
View File
@@ -2264,7 +2264,7 @@ Status DB::OpenAndTrimHistory(
return s;
}
DB* db = nullptr;
std::unique_ptr<DB> db;
s = DB::Open(db_options, dbname, column_families, handles, &db);
if (!s.ok()) {
return s;
@@ -2273,7 +2273,7 @@ Status DB::OpenAndTrimHistory(
CompactRangeOptions options;
options.bottommost_level_compaction =
BottommostLevelCompaction::kForceOptimized;
auto db_impl = static_cast_with_check<DBImpl>(db);
auto db_impl = static_cast_with_check<DBImpl>(db.get());
for (auto handle : *handles) {
assert(handle != nullptr);
auto cfh = static_cast_with_check<ColumnFamilyHandleImpl>(handle);
@@ -2295,14 +2295,14 @@ Status DB::OpenAndTrimHistory(
assert(temp_s.ok());
}
handles->clear();
delete db;
db.reset();
};
if (!s.ok()) {
clean_op();
return s;
}
dbptr->reset(db);
*dbptr = std::move(db);
return s;
}
+5 -4
View File
@@ -1546,7 +1546,7 @@ Status DB::OpenAndCompact(
}
// 5. Open db As Secondary
DB* db;
std::unique_ptr<DB> db;
std::vector<ColumnFamilyHandle*> handles;
s = DB::OpenAsSecondary(db_options, name, output_directory, column_families,
&handles, &db);
@@ -1556,7 +1556,7 @@ Status DB::OpenAndCompact(
assert(db);
TEST_SYNC_POINT_CALLBACK(
"DBImplSecondary::OpenAndCompact::AfterOpenAsSecondary:0", db);
"DBImplSecondary::OpenAndCompact::AfterOpenAsSecondary:0", db.get());
// 6. Find the handle of the Column Family that this will compact
ColumnFamilyHandle* cfh = nullptr;
@@ -1571,7 +1571,8 @@ Status DB::OpenAndCompact(
// 7. Run the compaction without installation.
// Output will be stored in the directory specified by output_directory
CompactionServiceResult compaction_result;
DBImplSecondary* db_secondary = static_cast_with_check<DBImplSecondary>(db);
DBImplSecondary* db_secondary =
static_cast_with_check<DBImplSecondary>(db.get());
s = db_secondary->CompactWithoutInstallation(options, cfh, compaction_input,
&compaction_result);
@@ -1582,7 +1583,7 @@ Status DB::OpenAndCompact(
for (auto& handle : handles) {
delete handle;
}
delete db;
db.reset();
if (s.ok()) {
return serialization_status;
} else {
+1 -1
View File
@@ -2574,7 +2574,7 @@ TEST_P(DBIteratorTest, AutoRefreshIterator) {
ReadOptions read_options;
std::unique_ptr<ManagedSnapshot> snapshot = nullptr;
if (explicit_snapshot) {
snapshot = std::make_unique<ManagedSnapshot>(db_);
snapshot = std::make_unique<ManagedSnapshot>(db_.get());
}
read_options.snapshot =
explicit_snapshot ? snapshot->snapshot() : nullptr;
+22 -23
View File
@@ -67,7 +67,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, OpenClose) {
options.db_paths = {{data_path_0_, 2048}, {data_path_1_, 2048}};
for (int i = 0; i < 2; i++) {
DB* db;
std::unique_ptr<DB> db;
if (!i) {
printf("Open\n");
ASSERT_OK(DB::Open(options, dbname_, &db));
@@ -82,7 +82,6 @@ TEST_F(DBLogicalBlockSizeCacheTest, OpenClose) {
ASSERT_EQ(1, cache_->GetRefCount(data_path_1_));
ASSERT_OK(db->Close());
ASSERT_EQ(0, cache_->Size());
delete db;
}
ASSERT_OK(DestroyDB(dbname_, options, {}));
}
@@ -95,7 +94,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, OpenDelete) {
options.env = env_.get();
for (int i = 0; i < 2; i++) {
DB* db;
std::unique_ptr<DB> db;
if (!i) {
printf("Open\n");
ASSERT_OK(DB::Open(options, dbname_, &db));
@@ -106,7 +105,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, OpenDelete) {
ASSERT_EQ(1, cache_->Size());
ASSERT_TRUE(cache_->Contains(dbname_));
ASSERT_EQ(1, cache_->GetRefCount(dbname_));
delete db;
db.reset();
ASSERT_EQ(0, cache_->Size());
}
ASSERT_OK(DestroyDB(dbname_, options, {}));
@@ -122,7 +121,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, CreateColumnFamily) {
ColumnFamilyOptions cf_options;
cf_options.cf_paths = {{cf_path_0_, 1024}, {cf_path_1_, 2048}};
DB* db;
std::unique_ptr<DB> db;
ASSERT_OK(DB::Open(options, dbname_, &db));
ASSERT_EQ(1, cache_->Size());
ASSERT_TRUE(cache_->Contains(dbname_));
@@ -153,7 +152,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, CreateColumnFamily) {
ASSERT_TRUE(cache_->Contains(dbname_));
ASSERT_EQ(1, cache_->GetRefCount(dbname_));
delete db;
db.reset();
ASSERT_EQ(0, cache_->Size());
ASSERT_OK(DestroyDB(dbname_, options, {{"cf", cf_options}}));
}
@@ -173,7 +172,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, CreateColumnFamilies) {
ColumnFamilyOptions cf_options;
cf_options.cf_paths = {{cf_path_0_, 1024}};
DB* db;
std::unique_ptr<DB> db;
ASSERT_OK(DB::Open(options, dbname_, &db));
ASSERT_EQ(1, cache_->Size());
ASSERT_TRUE(cache_->Contains(dbname_));
@@ -211,7 +210,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, CreateColumnFamilies) {
ASSERT_OK(db->DestroyColumnFamilyHandle(cfs[1]));
ASSERT_TRUE(cache_->Contains(dbname_));
ASSERT_EQ(1, cache_->GetRefCount(dbname_));
delete db;
db.reset();
// Now cf_path_0_ in cache_ has been properly decreased and cf_path_0_'s entry
// is dropped from cache
@@ -233,15 +232,15 @@ TEST_F(DBLogicalBlockSizeCacheTest, OpenWithColumnFamilies) {
cf_options.cf_paths = {{cf_path_0_, 1024}};
for (int i = 0; i < 2; i++) {
DB* db;
std::unique_ptr<DB> db;
ASSERT_OK(DB::Open(options, dbname_, &db));
ColumnFamilyHandle* cf1 = nullptr;
ColumnFamilyHandle* cf2 = nullptr;
ASSERT_OK(DB::Open(options, dbname_, &db));
ASSERT_OK(db->CreateColumnFamily(cf_options, "cf1", &cf1));
ASSERT_OK(db->CreateColumnFamily(cf_options, "cf2", &cf2));
ASSERT_OK(db->DestroyColumnFamilyHandle(cf1));
ASSERT_OK(db->DestroyColumnFamilyHandle(cf2));
delete db;
db.reset();
ASSERT_EQ(0, cache_->Size());
std::vector<ColumnFamilyHandle*> cfs;
@@ -298,7 +297,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, OpenWithColumnFamilies) {
ASSERT_TRUE(cache_->Contains(dbname_));
ASSERT_EQ(1, cache_->GetRefCount(dbname_));
delete db;
db.reset();
ASSERT_EQ(0, cache_->Size());
}
ASSERT_OK(
@@ -315,7 +314,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, DestroyColumnFamilyHandle) {
ColumnFamilyOptions cf_options;
cf_options.cf_paths = {{cf_path_0_, 1024}};
DB* db;
std::unique_ptr<DB> db;
ASSERT_OK(DB::Open(options, dbname_, &db));
ASSERT_EQ(1, cache_->Size());
ASSERT_TRUE(cache_->Contains(dbname_));
@@ -336,7 +335,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, DestroyColumnFamilyHandle) {
ASSERT_TRUE(cache_->Contains(cf_path_0_));
ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));
delete db;
db.reset();
ASSERT_EQ(0, cache_->Size());
// Open with column families.
@@ -369,7 +368,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, DestroyColumnFamilyHandle) {
ASSERT_TRUE(cache_->Contains(cf_path_0_));
ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));
delete db;
db.reset();
ASSERT_EQ(0, cache_->Size());
}
ASSERT_OK(DestroyDB(dbname_, options, {{"cf", cf_options}}));
@@ -384,7 +383,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, MultiDBWithDifferentPaths) {
ASSERT_OK(env_->CreateDirIfMissing(dbname_));
DB* db0;
std::unique_ptr<DB> db0;
ASSERT_OK(DB::Open(options, data_path_0_, &db0));
ASSERT_EQ(1, cache_->Size());
ASSERT_TRUE(cache_->Contains(data_path_0_));
@@ -399,7 +398,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, MultiDBWithDifferentPaths) {
ASSERT_TRUE(cache_->Contains(cf_path_0_));
ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));
DB* db1;
std::unique_ptr<DB> db1;
ASSERT_OK(DB::Open(options, data_path_1_, &db1));
ASSERT_EQ(3, cache_->Size());
ASSERT_TRUE(cache_->Contains(data_path_0_));
@@ -424,7 +423,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, MultiDBWithDifferentPaths) {
ASSERT_EQ(1, cache_->GetRefCount(cf_path_1_));
ASSERT_OK(db0->DestroyColumnFamilyHandle(cf0));
delete db0;
db0.reset();
ASSERT_EQ(2, cache_->Size());
ASSERT_TRUE(cache_->Contains(data_path_1_));
ASSERT_EQ(1, cache_->GetRefCount(data_path_1_));
@@ -433,7 +432,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, MultiDBWithDifferentPaths) {
ASSERT_OK(DestroyDB(data_path_0_, options, {{"cf", cf_options0}}));
ASSERT_OK(db1->DestroyColumnFamilyHandle(cf1));
delete db1;
db1.reset();
ASSERT_EQ(0, cache_->Size());
ASSERT_OK(DestroyDB(data_path_1_, options, {{"cf", cf_options1}}));
}
@@ -450,7 +449,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, MultiDBWithSamePaths) {
ASSERT_OK(env_->CreateDirIfMissing(dbname_));
DB* db0;
std::unique_ptr<DB> db0;
ASSERT_OK(DB::Open(options, dbname_ + "/db0", &db0));
ASSERT_EQ(1, cache_->Size());
ASSERT_TRUE(cache_->Contains(data_path_0_));
@@ -464,7 +463,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, MultiDBWithSamePaths) {
ASSERT_TRUE(cache_->Contains(cf_path_0_));
ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_));
DB* db1;
std::unique_ptr<DB> db1;
ASSERT_OK(DB::Open(options, dbname_ + "/db1", &db1));
ASSERT_EQ(2, cache_->Size());
ASSERT_TRUE(cache_->Contains(data_path_0_));
@@ -481,7 +480,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, MultiDBWithSamePaths) {
ASSERT_EQ(2, cache_->GetRefCount(cf_path_0_));
ASSERT_OK(db0->DestroyColumnFamilyHandle(cf0));
delete db0;
db0.reset();
ASSERT_EQ(2, cache_->Size());
ASSERT_TRUE(cache_->Contains(data_path_0_));
ASSERT_EQ(1, cache_->GetRefCount(data_path_0_));
@@ -490,7 +489,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, MultiDBWithSamePaths) {
ASSERT_OK(DestroyDB(dbname_ + "/db0", options, {{"cf", cf_options}}));
ASSERT_OK(db1->DestroyColumnFamilyHandle(cf1));
delete db1;
db1.reset();
ASSERT_EQ(0, cache_->Size());
ASSERT_OK(DestroyDB(dbname_ + "/db1", options, {{"cf", cf_options}}));
}
+4 -4
View File
@@ -386,7 +386,7 @@ TEST_F(DBMergeOperatorTest, MergeOperandThresholdExceeded) {
snapshots.reserve(3);
for (size_t i = 0; i < keys.size(); ++i) {
snapshots.emplace_back(db_);
snapshots.emplace_back(db_.get());
const std::string suffix = std::to_string(i + 1);
@@ -985,7 +985,7 @@ TEST_F(DBMergeOperatorTest, MaxSuccessiveMergesBaseValues) {
// max_successive_merges.
constexpr size_t max_key_versions = 8;
std::vector<KeyVersion> key_versions;
ASSERT_OK(GetAllKeyVersions(db_, db_->DefaultColumnFamily(), key, key,
ASSERT_OK(GetAllKeyVersions(db_.get(), db_->DefaultColumnFamily(), key, key,
max_key_versions, &key_versions));
ASSERT_EQ(key_versions.size(), 2);
ASSERT_EQ(key_versions[0].type, kTypeValue);
@@ -1009,7 +1009,7 @@ TEST_F(DBMergeOperatorTest, MaxSuccessiveMergesBaseValues) {
// max_successive_merges.
constexpr size_t max_key_versions = 8;
std::vector<KeyVersion> key_versions;
ASSERT_OK(GetAllKeyVersions(db_, db_->DefaultColumnFamily(), key, key,
ASSERT_OK(GetAllKeyVersions(db_.get(), db_->DefaultColumnFamily(), key, key,
max_key_versions, &key_versions));
ASSERT_EQ(key_versions.size(), 3);
ASSERT_EQ(key_versions[0].type, kTypeValue);
@@ -1038,7 +1038,7 @@ TEST_F(DBMergeOperatorTest, MaxSuccessiveMergesBaseValues) {
// max_successive_merges.
constexpr size_t max_key_versions = 8;
std::vector<KeyVersion> key_versions;
ASSERT_OK(GetAllKeyVersions(db_, db_->DefaultColumnFamily(), key, key,
ASSERT_OK(GetAllKeyVersions(db_.get(), db_->DefaultColumnFamily(), key, key,
max_key_versions, &key_versions));
ASSERT_EQ(key_versions.size(), 3);
ASSERT_EQ(key_versions[0].type, kTypeWideColumnEntity);
+3 -3
View File
@@ -384,7 +384,7 @@ TEST_F(DBPropertiesTest, AggregatedTableProperties) {
// Hold open a snapshot to prevent range tombstones from being compacted
// away.
ManagedSnapshot snapshot(db_);
ManagedSnapshot snapshot(db_.get());
Random rnd(5632);
for (int table = 1; table <= kTableCount; ++table) {
@@ -582,7 +582,7 @@ TEST_F(DBPropertiesTest, AggregatedTablePropertiesAtLevel) {
DestroyAndReopen(options);
// Hold open a snapshot to prevent range tombstones from being compacted away.
ManagedSnapshot snapshot(db_);
ManagedSnapshot snapshot(db_.get());
std::string level_tp_strings[kMaxLevel];
std::string tp_string;
@@ -1864,7 +1864,7 @@ TEST_F(DBPropertiesTest, MinObsoleteSstNumberToKeep) {
options.listeners.push_back(listener);
options.level0_file_num_compaction_trigger = kNumL0Files;
DestroyAndReopen(options);
listener->SetDB(db_);
listener->SetDB(db_.get());
for (int i = 0; i < kNumL0Files; ++i) {
// Make sure they overlap in keyspace to prevent trivial move
+1 -1
View File
@@ -2047,7 +2047,7 @@ TEST_F(DBRangeDelTest, IteratorReseek) {
// Immutable memtable
ASSERT_OK(db_->DeleteRange(WriteOptions(), db_->DefaultColumnFamily(), Key(1),
Key(2)));
ASSERT_OK(static_cast_with_check<DBImpl>(db_)->TEST_SwitchMemtable());
ASSERT_OK(dbfull()->TEST_SwitchMemtable());
std::string value;
ASSERT_TRUE(dbfull()->GetProperty(db_->DefaultColumnFamily(),
"rocksdb.num-immutable-mem-table", &value));
+4 -4
View File
@@ -237,7 +237,7 @@ TEST_F(DBReadOnlyTestWithTimestamp, IteratorAndGet) {
it->Next(), ++count, ++key) {
CheckIterUserEntry(it.get(), Key1(key), kTypeValue,
"value" + std::to_string(i), write_timestamps[i]);
get_value_and_check(db_, read_opts, it->key(), it->value(),
get_value_and_check(db_.get(), read_opts, it->key(), it->value(),
write_timestamps[i]);
}
ASSERT_OK(it->status());
@@ -250,7 +250,7 @@ TEST_F(DBReadOnlyTestWithTimestamp, IteratorAndGet) {
it->Prev(), ++count, --key) {
CheckIterUserEntry(it.get(), Key1(key), kTypeValue,
"value" + std::to_string(i), write_timestamps[i]);
get_value_and_check(db_, read_opts, it->key(), it->value(),
get_value_and_check(db_.get(), read_opts, it->key(), it->value(),
write_timestamps[i]);
}
ASSERT_OK(it->status());
@@ -272,7 +272,7 @@ TEST_F(DBReadOnlyTestWithTimestamp, IteratorAndGet) {
it->Valid(); it->Next(), ++key, ++count) {
CheckIterUserEntry(it.get(), Key1(key), kTypeValue,
"value" + std::to_string(i), write_timestamps[i]);
get_value_and_check(db_, read_opts, it->key(), it->value(),
get_value_and_check(db_.get(), read_opts, it->key(), it->value(),
write_timestamps[i]);
}
ASSERT_OK(it->status());
@@ -282,7 +282,7 @@ TEST_F(DBReadOnlyTestWithTimestamp, IteratorAndGet) {
it->Valid(); it->Prev(), --key, ++count) {
CheckIterUserEntry(it.get(), Key1(key - 1), kTypeValue,
"value" + std::to_string(i), write_timestamps[i]);
get_value_and_check(db_, read_opts, it->key(), it->value(),
get_value_and_check(db_.get(), read_opts, it->key(), it->value(),
write_timestamps[i]);
}
ASSERT_OK(it->status());
+14 -15
View File
@@ -56,12 +56,11 @@ class DBSecondaryTestBase : public DBBasicTestWithTimestampBase {
ASSERT_OK(db_secondary_->DestroyColumnFamilyHandle(h));
}
handles_secondary_.clear();
delete db_secondary_;
db_secondary_ = nullptr;
db_secondary_.reset();
}
DBImplSecondary* db_secondary_full() {
return static_cast<DBImplSecondary*>(db_secondary_);
return static_cast<DBImplSecondary*>(db_secondary_.get());
}
void CheckFileTypeCounts(const std::string& dir, int expected_log,
@@ -69,7 +68,7 @@ class DBSecondaryTestBase : public DBBasicTestWithTimestampBase {
std::string secondary_path_;
std::vector<ColumnFamilyHandle*> handles_secondary_;
DB* db_secondary_;
std::unique_ptr<DB> db_secondary_;
};
void DBSecondaryTestBase::OpenSecondary(const Options& options) {
@@ -152,8 +151,8 @@ TEST_F(DBSecondaryTest, NonExistingDb) {
options.env = env_;
options.max_open_files = -1;
const std::string dbname = "/doesnt/exist";
Status s =
DB::OpenAsSecondary(options, dbname, secondary_path_, &db_secondary_);
std::unique_ptr<DB> dbptr;
Status s = DB::OpenAsSecondary(options, dbname, secondary_path_, &dbptr);
ASSERT_TRUE(s.IsIOError());
}
@@ -182,7 +181,7 @@ TEST_F(DBSecondaryTest, ReopenAsSecondary) {
ReadOptions ropts;
ropts.verify_checksums = true;
auto db1 = static_cast<DBImplSecondary*>(db_);
auto db1 = static_cast<DBImplSecondary*>(db_.get());
ASSERT_NE(nullptr, db1);
Iterator* iter = db1->NewIterator(ropts);
ASSERT_NE(nullptr, iter);
@@ -834,7 +833,7 @@ TEST_F(DBSecondaryTest, OpenWithSubsetOfColumnFamilies) {
options1.max_open_files = -1;
OpenSecondary(options1);
ASSERT_EQ(0, handles_secondary_.size());
ASSERT_NE(nullptr, db_secondary_);
ASSERT_NE(nullptr, db_secondary_.get());
ASSERT_OK(Put(0 /*cf*/, "foo", "foo_value"));
ASSERT_OK(Put(1 /*cf*/, "foo", "foo_value"));
@@ -1152,7 +1151,7 @@ TEST_F(DBSecondaryTest, DISABLED_SwitchWAL) {
for (int k = 0; k != 16; ++k) {
ASSERT_OK(Put("key" + std::to_string(k), "value" + std::to_string(k)));
ASSERT_OK(db_secondary_->TryCatchUpWithPrimary());
verify_db(dbfull(), db_secondary_);
verify_db(dbfull(), db_secondary_.get());
}
}
@@ -1221,7 +1220,7 @@ TEST_F(DBSecondaryTest, DISABLED_SwitchWALMultiColumnFamilies) {
TEST_SYNC_POINT(
"DBSecondaryTest::SwitchWALMultipleColumnFamilies:BeforeCatchUp");
ASSERT_OK(db_secondary_->TryCatchUpWithPrimary());
verify_db(dbfull(), handles_, db_secondary_, handles_secondary_);
verify_db(dbfull(), handles_, db_secondary_.get(), handles_secondary_);
SyncPoint::GetInstance()->ClearTrace();
}
}
@@ -1357,7 +1356,7 @@ TEST_F(DBSecondaryTest, OpenWithTransactionDB) {
TransactionDBOptions txn_db_opts;
ASSERT_OK(TransactionDB::Open(options, txn_db_opts, dbname_, &txn_db));
ASSERT_NE(txn_db, nullptr);
db_ = txn_db;
db_.reset(txn_db);
std::vector<std::string> cfs = {"new_CF"};
CreateColumnFamilies(cfs, options);
@@ -1561,7 +1560,7 @@ TEST_F(DBSecondaryTestWithTimestamp, IteratorAndGet) {
it->Next(), ++count, ++key) {
CheckIterUserEntry(it.get(), Key1(key), kTypeValue,
"value" + std::to_string(i), write_timestamps[i]);
get_value_and_check(db_, read_opts, it->key(), it->value(),
get_value_and_check(db_.get(), read_opts, it->key(), it->value(),
write_timestamps[i]);
}
ASSERT_OK(it->status());
@@ -1574,7 +1573,7 @@ TEST_F(DBSecondaryTestWithTimestamp, IteratorAndGet) {
it->Prev(), ++count, --key) {
CheckIterUserEntry(it.get(), Key1(key), kTypeValue,
"value" + std::to_string(i), write_timestamps[i]);
get_value_and_check(db_, read_opts, it->key(), it->value(),
get_value_and_check(db_.get(), read_opts, it->key(), it->value(),
write_timestamps[i]);
}
ASSERT_OK(it->status());
@@ -1596,7 +1595,7 @@ TEST_F(DBSecondaryTestWithTimestamp, IteratorAndGet) {
it->Valid(); it->Next(), ++key, ++count) {
CheckIterUserEntry(it.get(), Key1(key), kTypeValue,
"value" + std::to_string(i), write_timestamps[i]);
get_value_and_check(db_, read_opts, it->key(), it->value(),
get_value_and_check(db_.get(), read_opts, it->key(), it->value(),
write_timestamps[i]);
}
ASSERT_OK(it->status());
@@ -1606,7 +1605,7 @@ TEST_F(DBSecondaryTestWithTimestamp, IteratorAndGet) {
it->Valid(); it->Prev(), --key, ++count) {
CheckIterUserEntry(it.get(), Key1(key - 1), kTypeValue,
"value" + std::to_string(i), write_timestamps[i]);
get_value_and_check(db_, read_opts, it->key(), it->value(),
get_value_and_check(db_.get(), read_opts, it->key(), it->value(),
write_timestamps[i]);
}
ASSERT_OK(it->status());
+2 -3
View File
@@ -321,7 +321,7 @@ TEST_F(DBStatisticsTest, BytesWrittenStats) {
options.enable_pipelined_write = enable_pipelined_write;
ASSERT_OK(TransactionDB::Open(options, txn_db_opts, dbname_, &txn_db));
ASSERT_NE(txn_db, nullptr);
db_ = txn_db->GetBaseDB();
db_.reset(txn_db);
WriteOptions wopts;
TransactionOptions txn_opts;
@@ -351,8 +351,7 @@ TEST_F(DBStatisticsTest, BytesWrittenStats) {
WriteBatchInternal::kHeader);
// Cleanup
db_ = nullptr;
delete txn_db;
db_.reset();
}
}
+3 -3
View File
@@ -90,7 +90,7 @@ TEST_F(DBTablePropertiesTest, GetPropertiesOfAllTablesTest) {
// Clear out auto-opened files
dbfull()->TEST_table_cache()->EraseUnRefEntries();
ASSERT_EQ(dbfull()->TEST_table_cache()->GetUsage(), 0U);
VerifyTableProperties(db_, 10 + 11 + 12 + 13);
VerifyTableProperties(db_.get(), 10 + 11 + 12 + 13);
// 2. Put two tables to table cache and
Reopen(options);
@@ -103,7 +103,7 @@ TEST_F(DBTablePropertiesTest, GetPropertiesOfAllTablesTest) {
Get(std::to_string(i * 100 + 0));
}
VerifyTableProperties(db_, 10 + 11 + 12 + 13);
VerifyTableProperties(db_.get(), 10 + 11 + 12 + 13);
// 3. Put all tables to table cache
Reopen(options);
@@ -111,7 +111,7 @@ TEST_F(DBTablePropertiesTest, GetPropertiesOfAllTablesTest) {
for (int i = 0; i < 4; ++i) {
Get(std::to_string(i * 100 + 0));
}
VerifyTableProperties(db_, 10 + 11 + 12 + 13);
VerifyTableProperties(db_.get(), 10 + 11 + 12 + 13);
// 4. Try to read CORRUPT properties (a) directly from file, and (b)
// through reader on Get
+82 -61
View File
@@ -104,7 +104,7 @@ TEST_F(DBTest, MockEnvTest) {
Options options;
options.create_if_missing = true;
options.env = env.get();
DB* db;
std::unique_ptr<DB> db;
const Slice keys[] = {Slice("aaa"), Slice("bbb"), Slice("ccc")};
const Slice vals[] = {Slice("foo"), Slice("bar"), Slice("baz")};
@@ -132,7 +132,7 @@ TEST_F(DBTest, MockEnvTest) {
ASSERT_OK(iterator->status());
delete iterator;
DBImpl* dbi = static_cast_with_check<DBImpl>(db);
DBImpl* dbi = static_cast_with_check<DBImpl>(db.get());
ASSERT_OK(dbi->TEST_FlushMemTable());
for (size_t i = 0; i < 3; ++i) {
@@ -141,7 +141,7 @@ TEST_F(DBTest, MockEnvTest) {
ASSERT_TRUE(res == vals[i]);
}
delete db;
db.reset();
}
TEST_F(DBTest, RequestIdPlumbingTest) {
@@ -264,7 +264,7 @@ TEST_F(DBTest, MemEnvTest) {
Options options;
options.create_if_missing = true;
options.env = env.get();
DB* db;
std::unique_ptr<DB> db;
const Slice keys[] = {Slice("aaa"), Slice("bbb"), Slice("ccc")};
const Slice vals[] = {Slice("foo"), Slice("bar"), Slice("baz")};
@@ -292,7 +292,7 @@ TEST_F(DBTest, MemEnvTest) {
ASSERT_OK(iterator->status());
delete iterator;
DBImpl* dbi = static_cast_with_check<DBImpl>(db);
DBImpl* dbi = static_cast_with_check<DBImpl>(db.get());
ASSERT_OK(dbi->TEST_FlushMemTable());
for (size_t i = 0; i < 3; ++i) {
@@ -301,7 +301,7 @@ TEST_F(DBTest, MemEnvTest) {
ASSERT_TRUE(res == vals[i]);
}
delete db;
db.reset();
options.create_if_missing = false;
ASSERT_OK(DB::Open(options, "/dir/db", &db));
@@ -310,7 +310,7 @@ TEST_F(DBTest, MemEnvTest) {
ASSERT_OK(db->Get(ReadOptions(), keys[i], &res));
ASSERT_TRUE(res == vals[i]);
}
delete db;
db.reset();
}
TEST_F(DBTest, WriteEmptyBatch) {
@@ -1078,7 +1078,9 @@ TEST_F(DBTest, WrongLevel0Config) {
options.level0_stop_writes_trigger = 1;
options.level0_slowdown_writes_trigger = 2;
options.level0_file_num_compaction_trigger = 3;
ASSERT_OK(DB::Open(options, dbname_, &db_));
{
ASSERT_OK(DB::Open(options, dbname_, &db_));
}
}
TEST_F(DBTest, GetOrderedByLevels) {
@@ -1207,8 +1209,10 @@ TEST_F(DBTest, FlushSchedule) {
t.join();
}
auto default_tables = GetNumberOfSstFilesForColumnFamily(db_, "default");
auto pikachu_tables = GetNumberOfSstFilesForColumnFamily(db_, "pikachu");
auto default_tables =
GetNumberOfSstFilesForColumnFamily(db_.get(), "default");
auto pikachu_tables =
GetNumberOfSstFilesForColumnFamily(db_.get(), "pikachu");
ASSERT_LE(default_tables, static_cast<uint64_t>(10));
ASSERT_GT(default_tables, static_cast<uint64_t>(0));
ASSERT_LE(pikachu_tables, static_cast<uint64_t>(10));
@@ -2368,7 +2372,7 @@ TEST_F(DBTest, Snapshot) {
ASSERT_OK(Put(1, "foo", "1v3"));
{
ManagedSnapshot s3(db_);
ManagedSnapshot s3(db_.get());
ASSERT_EQ(3U, GetNumSnapshots());
ASSERT_EQ(time_snap1, GetTimeOldestSnapshots());
ASSERT_EQ(GetSequenceOldestSnapshots(), s1->GetSequenceNumber());
@@ -2725,37 +2729,43 @@ TEST_F(DBTest, DBOpen_Options) {
ASSERT_OK(DestroyDB(dbname, options));
// Does not exist, and create_if_missing == false: error
DB* db = nullptr;
std::unique_ptr<DB> db;
options.create_if_missing = false;
Status s = DB::Open(options, dbname, &db);
ASSERT_TRUE(strstr(s.ToString().c_str(), "does not exist") != nullptr);
{
Status s = DB::Open(options, dbname, &db);
ASSERT_TRUE(strstr(s.ToString().c_str(), "does not exist") != nullptr);
}
ASSERT_TRUE(db == nullptr);
// Does not exist, and create_if_missing == true: OK
options.create_if_missing = true;
s = DB::Open(options, dbname, &db);
ASSERT_OK(s);
{
Status s = DB::Open(options, dbname, &db);
ASSERT_OK(s);
}
ASSERT_TRUE(db != nullptr);
delete db;
db = nullptr;
db.reset();
// Does exist, and error_if_exists == true: error
options.create_if_missing = false;
options.error_if_exists = true;
s = DB::Open(options, dbname, &db);
ASSERT_TRUE(strstr(s.ToString().c_str(), "exists") != nullptr);
{
Status s = DB::Open(options, dbname, &db);
ASSERT_TRUE(strstr(s.ToString().c_str(), "exists") != nullptr);
}
ASSERT_TRUE(db == nullptr);
// Does exist, and error_if_exists == false: OK
options.create_if_missing = true;
options.error_if_exists = false;
s = DB::Open(options, dbname, &db);
ASSERT_OK(s);
{
Status s = DB::Open(options, dbname, &db);
ASSERT_OK(s);
}
ASSERT_TRUE(db != nullptr);
delete db;
db = nullptr;
db.reset();
}
TEST_F(DBTest, DBOpen_Change_NumLevels) {
@@ -2793,25 +2803,36 @@ TEST_F(DBTest, DestroyDBMetaDatabase) {
ASSERT_OK(DestroyDB(dbname, options));
// Setup databases
DB* db = nullptr;
ASSERT_OK(DB::Open(options, dbname, &db));
delete db;
db = nullptr;
ASSERT_OK(DB::Open(options, metadbname, &db));
delete db;
db = nullptr;
ASSERT_OK(DB::Open(options, metametadbname, &db));
delete db;
db = nullptr;
{
std::unique_ptr<DB> db;
ASSERT_OK(DB::Open(options, dbname, &db));
}
{
std::unique_ptr<DB> db;
ASSERT_OK(DB::Open(options, metadbname, &db));
}
{
std::unique_ptr<DB> db;
ASSERT_OK(DB::Open(options, metametadbname, &db));
}
// Delete databases
ASSERT_OK(DestroyDB(dbname, options));
// Check if deletion worked.
options.create_if_missing = false;
ASSERT_TRUE(!(DB::Open(options, dbname, &db)).ok());
ASSERT_TRUE(!(DB::Open(options, metadbname, &db)).ok());
ASSERT_TRUE(!(DB::Open(options, metametadbname, &db)).ok());
{
std::unique_ptr<DB> dbptr;
ASSERT_TRUE(!(DB::Open(options, dbname, &dbptr)).ok());
}
{
std::unique_ptr<DB> dbptr;
ASSERT_TRUE(!(DB::Open(options, metadbname, &dbptr)).ok());
}
{
std::unique_ptr<DB> dbptr;
ASSERT_TRUE(!(DB::Open(options, metametadbname, &dbptr)).ok());
}
}
TEST_F(DBTest, SnapshotFiles) {
@@ -2890,13 +2911,11 @@ TEST_F(DBTest, SnapshotFiles) {
column_families.emplace_back("default", ColumnFamilyOptions());
column_families.emplace_back("pikachu", ColumnFamilyOptions());
std::vector<ColumnFamilyHandle*> cf_handles;
DB* snapdb;
std::unique_ptr<DB> snapdb;
DBOptions opts;
opts.env = env_;
opts.create_if_missing = false;
Status stat =
DB::Open(opts, snapdir, column_families, &cf_handles, &snapdb);
ASSERT_OK(stat);
ASSERT_OK(DB::Open(opts, snapdir, column_families, &cf_handles, &snapdb));
ReadOptions roptions;
std::string val;
@@ -2907,7 +2926,7 @@ TEST_F(DBTest, SnapshotFiles) {
for (auto cfh : cf_handles) {
delete cfh;
}
delete snapdb;
snapdb.reset();
// look at the new live files after we added an 'extra' key
// and after we took the first snapshot.
@@ -3109,7 +3128,7 @@ struct MTThread {
static void MTThreadBody(void* arg) {
MTThread* t = static_cast<MTThread*>(arg);
int id = t->id;
DB* db = t->state->test->db_;
DB* db = t->state->test->db_.get();
int counter = 0;
std::shared_ptr<SystemClock> clock = SystemClock::Default();
auto end_micros = clock->NowMicros() + kTestSeconds * 1000000U;
@@ -3324,7 +3343,7 @@ TEST_F(DBTest, GroupCommitTest) {
GCThread thread[kGCNumThreads];
for (int id = 0; id < kGCNumThreads; id++) {
thread[id].id = id;
thread[id].db = db_;
thread[id].db = db_.get();
thread[id].done = false;
env_->StartThread(GCThreadBody, &thread[id]);
}
@@ -3996,8 +4015,10 @@ TEST_P(DBTestRandomized, Randomized) {
// than return a key that is close to it.
if (option_config_ != kBlockBasedTableWithWholeKeyHashIndex &&
option_config_ != kBlockBasedTableWithPrefixHashIndex) {
ASSERT_TRUE(CompareIterators(step, &model, db_, nullptr, nullptr));
ASSERT_TRUE(CompareIterators(step, &model, db_, model_snap, db_snap));
ASSERT_TRUE(
CompareIterators(step, &model, db_.get(), nullptr, nullptr));
ASSERT_TRUE(
CompareIterators(step, &model, db_.get(), model_snap, db_snap));
}
// Save a snapshot from each DB this time that we'll use next
@@ -4011,7 +4032,7 @@ TEST_P(DBTestRandomized, Randomized) {
}
Reopen(options);
ASSERT_TRUE(CompareIterators(step, &model, db_, nullptr, nullptr));
ASSERT_TRUE(CompareIterators(step, &model, db_.get(), nullptr, nullptr));
model_snap = model.GetSnapshot();
db_snap = db_->GetSnapshot();
@@ -5437,7 +5458,7 @@ TEST_P(DBTestWithParam, PreShutdownManualCompaction) {
// Compact all
MakeTables(1, "a", "z", 1);
ASSERT_EQ("1,0,2", FilesPerLevel(1));
CancelAllBackgroundWork(db_);
CancelAllBackgroundWork(db_.get());
ASSERT_TRUE(
db_->CompactRange(CompactRangeOptions(), handles_[1], nullptr, nullptr)
.IsShutdownInProgress());
@@ -5457,7 +5478,7 @@ TEST_F(DBTest, PreShutdownFlush) {
Options options = CurrentOptions();
CreateAndReopenWithCF({"pikachu"}, options);
ASSERT_OK(Put(1, "key", "value"));
CancelAllBackgroundWork(db_);
CancelAllBackgroundWork(db_.get());
Status s =
db_->CompactRange(CompactRangeOptions(), handles_[1], nullptr, nullptr);
ASSERT_TRUE(s.IsShutdownInProgress());
@@ -5538,7 +5559,7 @@ TEST_P(DBTestWithParam, PreShutdownMultipleCompaction) {
TEST_SYNC_POINT("DBTest::PreShutdownMultipleCompaction:Preshutdown");
ASSERT_GE(operation_count[ThreadStatus::OP_COMPACTION], 1);
CancelAllBackgroundWork(db_);
CancelAllBackgroundWork(db_.get());
TEST_SYNC_POINT("DBTest::PreShutdownMultipleCompaction:VerifyPreshutdown");
ASSERT_OK(dbfull()->TEST_WaitForBackgroundWork());
// Record the number of compactions at a time.
@@ -5624,7 +5645,7 @@ TEST_P(DBTestWithParam, PreShutdownCompactionMiddle) {
}
ASSERT_GE(operation_count[ThreadStatus::OP_COMPACTION], 1);
CancelAllBackgroundWork(db_);
CancelAllBackgroundWork(db_.get());
TEST_SYNC_POINT("DBTest::PreShutdownCompactionMiddle:Preshutdown");
TEST_SYNC_POINT("DBTest::PreShutdownCompactionMiddle:VerifyPreshutdown");
ASSERT_OK(dbfull()->TEST_WaitForBackgroundWork());
@@ -5645,7 +5666,7 @@ TEST_F(DBTest, FlushOnDestroy) {
WriteOptions wo;
wo.disableWAL = true;
ASSERT_OK(Put("foo", "v1", wo));
CancelAllBackgroundWork(db_);
CancelAllBackgroundWork(db_.get());
}
TEST_F(DBTest, DynamicCompactionOptions) {
@@ -6513,7 +6534,7 @@ TEST_F(DBTest, SuggestCompactRangeTest) {
// compact it three times
for (int i = 0; i < 3; ++i) {
ASSERT_OK(experimental::SuggestCompactRange(db_, nullptr, nullptr));
ASSERT_OK(experimental::SuggestCompactRange(db_.get(), nullptr, nullptr));
ASSERT_OK(dbfull()->TEST_WaitForCompact());
}
@@ -6526,7 +6547,7 @@ TEST_F(DBTest, SuggestCompactRangeTest) {
// nonoverlapping with the file on level 0
Slice start("a"), end("b");
ASSERT_OK(experimental::SuggestCompactRange(db_, &start, &end));
ASSERT_OK(experimental::SuggestCompactRange(db_.get(), &start, &end));
ASSERT_OK(dbfull()->TEST_WaitForCompact());
// should not compact the level 0 file
@@ -6534,7 +6555,7 @@ TEST_F(DBTest, SuggestCompactRangeTest) {
start = Slice("j");
end = Slice("m");
ASSERT_OK(experimental::SuggestCompactRange(db_, &start, &end));
ASSERT_OK(experimental::SuggestCompactRange(db_.get(), &start, &end));
ASSERT_OK(dbfull()->TEST_WaitForCompact());
// SuggestCompactRange() is not going to be reported as manual compaction
ASSERT_TRUE(!CompactionFilterFactoryGetContext::IsManual(
@@ -6585,7 +6606,7 @@ TEST_F(DBTest, SuggestCompactRangeUniversal) {
// nonoverlapping with the file on level 0
Slice start("a"), end("b");
ASSERT_OK(experimental::SuggestCompactRange(db_, &start, &end));
ASSERT_OK(experimental::SuggestCompactRange(db_.get(), &start, &end));
ASSERT_OK(dbfull()->TEST_WaitForCompact());
// should not compact the level 0 file
@@ -6593,7 +6614,7 @@ TEST_F(DBTest, SuggestCompactRangeUniversal) {
start = Slice("j");
end = Slice("m");
ASSERT_OK(experimental::SuggestCompactRange(db_, &start, &end));
ASSERT_OK(experimental::SuggestCompactRange(db_.get(), &start, &end));
ASSERT_OK(dbfull()->TEST_WaitForCompact());
// now it should compact the level 0 file to the last level
@@ -6630,7 +6651,7 @@ TEST_F(DBTest, PromoteL0) {
ASSERT_EQ(NumTableFilesAtLevel(1, 0), 0); // No files in L1
// Promote L0 level to L2.
ASSERT_OK(experimental::PromoteL0(db_, db_->DefaultColumnFamily(), 2));
ASSERT_OK(experimental::PromoteL0(db_.get(), db_->DefaultColumnFamily(), 2));
// We expect that all the files were trivially moved from L0 to L2
ASSERT_EQ(NumTableFilesAtLevel(0, 0), 0);
ASSERT_EQ(NumTableFilesAtLevel(2, 0), level0_files);
@@ -6655,7 +6676,7 @@ TEST_F(DBTest, PromoteL0Failure) {
Status status;
// Fails because L0 has overlapping files.
status = experimental::PromoteL0(db_, db_->DefaultColumnFamily());
status = experimental::PromoteL0(db_.get(), db_->DefaultColumnFamily());
ASSERT_TRUE(status.IsInvalidArgument());
ASSERT_OK(db_->CompactRange(CompactRangeOptions(), nullptr, nullptr));
@@ -6665,7 +6686,7 @@ TEST_F(DBTest, PromoteL0Failure) {
ASSERT_OK(Put(Key(5), ""));
ASSERT_OK(Flush());
// Fails because L1 is non-empty.
status = experimental::PromoteL0(db_, db_->DefaultColumnFamily());
status = experimental::PromoteL0(db_.get(), db_->DefaultColumnFamily());
ASSERT_TRUE(status.IsInvalidArgument());
}
@@ -7736,7 +7757,7 @@ TEST_F(DBTest, ShuttingDownNotBlockStalledWrites) {
});
TEST_SYNC_POINT("DBTest::ShuttingDownNotBlockStalledWrites");
CancelAllBackgroundWork(db_, true);
CancelAllBackgroundWork(db_.get(), true);
thd.join();
}
+79 -81
View File
@@ -39,7 +39,7 @@ class DBTest2 : public DBTestBase {
};
TEST_F(DBTest2, OpenForReadOnly) {
DB* db_ptr = nullptr;
std::unique_ptr<DB> db_ptr;
std::string dbname = test::PerThreadDBPath("db_readonly");
Options options = CurrentOptions();
options.create_if_missing = true;
@@ -63,7 +63,7 @@ TEST_F(DBTest2, OpenForReadOnly) {
}
TEST_F(DBTest2, OpenForReadOnlyWithColumnFamilies) {
DB* db_ptr = nullptr;
std::unique_ptr<DB> db_ptr;
std::string dbname = test::PerThreadDBPath("db_readonly");
Options options = CurrentOptions();
options.create_if_missing = true;
@@ -349,9 +349,9 @@ TEST_P(DBTestSharedWriteBufferAcrossCFs, SharedWriteBufferAcrossCFs) {
ASSERT_OK(Put(3, Key(1), DummyString(1), wo));
ASSERT_OK(Put(0, Key(1), DummyString(1), wo));
ASSERT_OK(Flush(0));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "default"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "default"),
static_cast<uint64_t>(1));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "nikitich"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "nikitich"),
static_cast<uint64_t>(1));
flush_listener->expected_flush_reason = FlushReason::kWriteBufferManager;
@@ -371,13 +371,13 @@ TEST_P(DBTestSharedWriteBufferAcrossCFs, SharedWriteBufferAcrossCFs) {
// No flush should trigger
wait_flush();
{
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "default"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "default"),
static_cast<uint64_t>(1));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "pikachu"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "pikachu"),
static_cast<uint64_t>(0));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "dobrynia"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "dobrynia"),
static_cast<uint64_t>(0));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "nikitich"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "nikitich"),
static_cast<uint64_t>(1));
}
@@ -387,13 +387,13 @@ TEST_P(DBTestSharedWriteBufferAcrossCFs, SharedWriteBufferAcrossCFs) {
ASSERT_OK(Put(0, Key(1), DummyString(1), wo));
wait_flush();
{
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "default"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "default"),
static_cast<uint64_t>(1));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "pikachu"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "pikachu"),
static_cast<uint64_t>(0));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "dobrynia"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "dobrynia"),
static_cast<uint64_t>(0));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "nikitich"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "nikitich"),
static_cast<uint64_t>(2));
}
@@ -405,13 +405,13 @@ TEST_P(DBTestSharedWriteBufferAcrossCFs, SharedWriteBufferAcrossCFs) {
ASSERT_OK(Put(2, Key(1), DummyString(1), wo));
wait_flush();
{
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "default"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "default"),
static_cast<uint64_t>(1));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "pikachu"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "pikachu"),
static_cast<uint64_t>(0));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "dobrynia"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "dobrynia"),
static_cast<uint64_t>(0));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "nikitich"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "nikitich"),
static_cast<uint64_t>(2));
}
@@ -428,13 +428,13 @@ TEST_P(DBTestSharedWriteBufferAcrossCFs, SharedWriteBufferAcrossCFs) {
ASSERT_OK(Put(0, Key(1), DummyString(1), wo));
wait_flush();
{
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "default"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "default"),
static_cast<uint64_t>(2));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "pikachu"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "pikachu"),
static_cast<uint64_t>(0));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "dobrynia"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "dobrynia"),
static_cast<uint64_t>(0));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "nikitich"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "nikitich"),
static_cast<uint64_t>(2));
}
@@ -450,13 +450,13 @@ TEST_P(DBTestSharedWriteBufferAcrossCFs, SharedWriteBufferAcrossCFs) {
wait_flush();
{
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "default"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "default"),
static_cast<uint64_t>(2));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "pikachu"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "pikachu"),
static_cast<uint64_t>(0));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "dobrynia"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "dobrynia"),
static_cast<uint64_t>(1));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "nikitich"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "nikitich"),
static_cast<uint64_t>(2));
}
if (cost_cache_) {
@@ -506,7 +506,7 @@ TEST_F(DBTest2, SharedWriteBufferLimitAcrossDB) {
CreateAndReopenWithCF({"cf1", "cf2"}, options);
ASSERT_OK(DestroyDB(dbname2, options));
DB* db2 = nullptr;
std::unique_ptr<DB> db2;
ASSERT_OK(DB::Open(options, dbname2, &db2));
WriteOptions wo;
@@ -516,12 +516,12 @@ TEST_F(DBTest2, SharedWriteBufferLimitAcrossDB) {
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable(handles_[0]));
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable(handles_[1]));
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable(handles_[2]));
ASSERT_OK(static_cast<DBImpl*>(db2)->TEST_WaitForFlushMemTable());
ASSERT_OK(static_cast<DBImpl*>(db2.get())->TEST_WaitForFlushMemTable());
// Ensure background work is fully finished including listener callbacks
// before accessing listener state.
ASSERT_OK(dbfull()->TEST_WaitForBackgroundWork());
ASSERT_OK(
static_cast_with_check<DBImpl>(db2)->TEST_WaitForBackgroundWork());
ASSERT_OK(static_cast_with_check<DBImpl>(db2.get())
->TEST_WaitForBackgroundWork());
};
// Trigger a flush on cf2
@@ -537,13 +537,13 @@ TEST_F(DBTest2, SharedWriteBufferLimitAcrossDB) {
ASSERT_OK(Put(2, Key(1), DummyString(1), wo));
wait_flush();
ASSERT_OK(static_cast<DBImpl*>(db2)->TEST_WaitForFlushMemTable());
ASSERT_OK(static_cast<DBImpl*>(db2.get())->TEST_WaitForFlushMemTable());
{
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "default") +
GetNumberOfSstFilesForColumnFamily(db_, "cf1") +
GetNumberOfSstFilesForColumnFamily(db_, "cf2"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "default") +
GetNumberOfSstFilesForColumnFamily(db_.get(), "cf1") +
GetNumberOfSstFilesForColumnFamily(db_.get(), "cf2"),
static_cast<uint64_t>(1));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db2, "default"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db2.get(), "default"),
static_cast<uint64_t>(0));
}
@@ -553,13 +553,13 @@ TEST_F(DBTest2, SharedWriteBufferLimitAcrossDB) {
ASSERT_OK(Put(2, Key(1), DummyString(1), wo));
wait_flush();
{
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "default"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "default"),
static_cast<uint64_t>(1));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "cf1"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "cf1"),
static_cast<uint64_t>(0));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "cf2"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "cf2"),
static_cast<uint64_t>(1));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db2, "default"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db2.get(), "default"),
static_cast<uint64_t>(0));
}
@@ -568,19 +568,19 @@ TEST_F(DBTest2, SharedWriteBufferLimitAcrossDB) {
wait_flush();
ASSERT_OK(db2->Put(wo, Key(1), DummyString(1)));
wait_flush();
ASSERT_OK(static_cast<DBImpl*>(db2)->TEST_WaitForFlushMemTable());
ASSERT_OK(static_cast<DBImpl*>(db2.get())->TEST_WaitForFlushMemTable());
{
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "default"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "default"),
static_cast<uint64_t>(1));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "cf1"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "cf1"),
static_cast<uint64_t>(0));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "cf2"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "cf2"),
static_cast<uint64_t>(1));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db2, "default"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db2.get(), "default"),
static_cast<uint64_t>(1));
}
delete db2;
db2.reset();
ASSERT_OK(DestroyDB(dbname2, options));
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
@@ -785,7 +785,7 @@ TEST_F(DBTest2, WalFilterTest) {
while (true) {
// Ensure that expected keys exists
// and not expected keys don't exist after recovery
ValidateKeyExistence(db_, keys_must_exist, keys_must_not_exist);
ValidateKeyExistence(db_.get(), keys_must_exist, keys_must_not_exist);
if (checked_after_reopen) {
break;
@@ -922,7 +922,7 @@ TEST_F(DBTest2, WalFilterTestWithChangeBatch) {
while (true) {
// Ensure that expected keys exists
// and not expected keys don't exist after recovery
ValidateKeyExistence(db_, keys_must_exist, keys_must_not_exist);
ValidateKeyExistence(db_.get(), keys_must_exist, keys_must_not_exist);
if (checked_after_reopen) {
break;
@@ -1004,7 +1004,7 @@ TEST_F(DBTest2, WalFilterTestWithChangeBatchExtraKeys) {
}
}
ValidateKeyExistence(db_, keys_must_exist, keys_must_not_exist);
ValidateKeyExistence(db_.get(), keys_must_exist, keys_must_not_exist);
}
TEST_F(DBTest2, WalFilterTestWithColumnFamilies) {
@@ -1292,7 +1292,7 @@ TEST_F(DBTest2, DuplicateSnapshot) {
Options options;
options = CurrentOptions(options);
std::vector<const Snapshot*> snapshots;
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
DBImpl* dbi = dbfull();
SequenceNumber oldest_ww_snap, first_ww_snap;
ASSERT_OK(Put("k", "v")); // inc seq
@@ -3694,16 +3694,16 @@ TEST_F(DBTest2, TraceAndReplay) {
// Using a different name than db2, to pacify infer's use-after-lifetime
// warnings (http://fbinfer.com).
DB* db2_init = nullptr;
std::unique_ptr<DB> db2_init;
options.create_if_missing = true;
ASSERT_OK(DB::Open(options, dbname2, &db2_init));
ColumnFamilyHandle* cf;
ASSERT_OK(
db2_init->CreateColumnFamily(ColumnFamilyOptions(), "pikachu", &cf));
delete cf;
delete db2_init;
db2_init.reset();
DB* db2 = nullptr;
std::unique_ptr<DB> db2;
std::vector<ColumnFamilyDescriptor> column_families;
ColumnFamilyOptions cf_options;
cf_options.merge_operator = MergeOperators::CreatePutOperator();
@@ -3790,7 +3790,7 @@ TEST_F(DBTest2, TraceAndReplay) {
for (auto handle : handles) {
delete handle;
}
delete db2;
db2.reset();
ASSERT_OK(DestroyDB(dbname2, options));
}
@@ -3885,16 +3885,16 @@ TEST_F(DBTest2, TraceAndManualReplay) {
// Using a different name than db2, to pacify infer's use-after-lifetime
// warnings (http://fbinfer.com).
DB* db2_init = nullptr;
std::unique_ptr<DB> db2_init;
options.create_if_missing = true;
ASSERT_OK(DB::Open(options, dbname2, &db2_init));
ColumnFamilyHandle* cf;
ASSERT_OK(
db2_init->CreateColumnFamily(ColumnFamilyOptions(), "pikachu", &cf));
delete cf;
delete db2_init;
db2_init.reset();
DB* db2 = nullptr;
std::unique_ptr<DB> db2;
std::vector<ColumnFamilyDescriptor> column_families;
ColumnFamilyOptions cf_options;
cf_options.merge_operator = MergeOperators::CreatePutOperator();
@@ -4130,7 +4130,7 @@ TEST_F(DBTest2, TraceAndManualReplay) {
for (auto handle : handles) {
delete handle;
}
delete db2;
db2.reset();
ASSERT_OK(DestroyDB(dbname2, options));
}
@@ -4161,16 +4161,16 @@ TEST_F(DBTest2, TraceWithLimit) {
// Using a different name than db2, to pacify infer's use-after-lifetime
// warnings (http://fbinfer.com).
DB* db2_init = nullptr;
std::unique_ptr<DB> db2_init;
options.create_if_missing = true;
ASSERT_OK(DB::Open(options, dbname2, &db2_init));
ColumnFamilyHandle* cf;
ASSERT_OK(
db2_init->CreateColumnFamily(ColumnFamilyOptions(), "pikachu", &cf));
delete cf;
delete db2_init;
db2_init.reset();
DB* db2 = nullptr;
std::unique_ptr<DB> db2;
std::vector<ColumnFamilyDescriptor> column_families;
ColumnFamilyOptions cf_options;
cf_options.merge_operator = MergeOperators::CreatePutOperator();
@@ -4203,7 +4203,7 @@ TEST_F(DBTest2, TraceWithLimit) {
for (auto handle : handles) {
delete handle;
}
delete db2;
db2.reset();
ASSERT_OK(DestroyDB(dbname2, options));
}
@@ -4235,16 +4235,16 @@ TEST_F(DBTest2, TraceWithSampling) {
// Using a different name than db2, to pacify infer's use-after-lifetime
// warnings (http://fbinfer.com).
DB* db2_init = nullptr;
std::unique_ptr<DB> db2_init;
options.create_if_missing = true;
ASSERT_OK(DB::Open(options, dbname2, &db2_init));
ColumnFamilyHandle* cf;
ASSERT_OK(
db2_init->CreateColumnFamily(ColumnFamilyOptions(), "pikachu", &cf));
delete cf;
delete db2_init;
db2_init.reset();
DB* db2 = nullptr;
std::unique_ptr<DB> db2;
std::vector<ColumnFamilyDescriptor> column_families;
ColumnFamilyOptions cf_options;
column_families.emplace_back("default", cf_options);
@@ -4279,7 +4279,7 @@ TEST_F(DBTest2, TraceWithSampling) {
for (auto handle : handles) {
delete handle;
}
delete db2;
db2.reset();
ASSERT_OK(DestroyDB(dbname2, options));
}
@@ -4339,16 +4339,16 @@ TEST_F(DBTest2, TraceWithFilter) {
// Using a different name than db2, to pacify infer's use-after-lifetime
// warnings (http://fbinfer.com).
DB* db2_init = nullptr;
std::unique_ptr<DB> db2_init;
options.create_if_missing = true;
ASSERT_OK(DB::Open(options, dbname2, &db2_init));
ColumnFamilyHandle* cf;
ASSERT_OK(
db2_init->CreateColumnFamily(ColumnFamilyOptions(), "pikachu", &cf));
delete cf;
delete db2_init;
db2_init.reset();
DB* db2 = nullptr;
std::unique_ptr<DB> db2;
std::vector<ColumnFamilyDescriptor> column_families;
ColumnFamilyOptions cf_options;
cf_options.merge_operator = MergeOperators::CreatePutOperator();
@@ -4384,28 +4384,28 @@ TEST_F(DBTest2, TraceWithFilter) {
for (auto handle : handles) {
delete handle;
}
delete db2;
db2.reset();
ASSERT_OK(DestroyDB(dbname2, options));
// Set up a new db.
std::string dbname3 = test::PerThreadDBPath(env_, "db_not_trace_read");
ASSERT_OK(DestroyDB(dbname3, options));
DB* db3_init = nullptr;
std::unique_ptr<DB> db3_init;
options.create_if_missing = true;
ColumnFamilyHandle* cf3;
ASSERT_OK(DB::Open(options, dbname3, &db3_init));
ASSERT_OK(
db3_init->CreateColumnFamily(ColumnFamilyOptions(), "pikachu", &cf3));
delete cf3;
delete db3_init;
db3_init.reset();
column_families.clear();
column_families.emplace_back("default", cf_options);
column_families.emplace_back("pikachu", ColumnFamilyOptions());
handles.clear();
DB* db3 = nullptr;
std::unique_ptr<DB> db3;
ASSERT_OK(DB::Open(db_opts, dbname3, column_families, &handles, &db3));
env_->SleepForMicroseconds(100);
@@ -4435,7 +4435,7 @@ TEST_F(DBTest2, TraceWithFilter) {
for (auto handle : handles) {
delete handle;
}
delete db3;
db3.reset();
ASSERT_OK(DestroyDB(dbname3, options));
std::unique_ptr<TraceReader> trace_reader3;
@@ -4626,7 +4626,7 @@ TEST_F(DBTest2, TestGetColumnFamilyHandleUnlocked) {
CreateColumnFamilies({"test1", "test2"}, Options());
ASSERT_EQ(handles_.size(), 2);
DBImpl* dbi = static_cast_with_check<DBImpl>(db_);
DBImpl* dbi = dbfull();
port::Thread user_thread1([&]() {
auto cfh = dbi->GetColumnFamilyHandleUnlocked(handles_[0]->GetID());
ASSERT_EQ(cfh->GetID(), handles_[0]->GetID());
@@ -4830,7 +4830,7 @@ TEST_F(DBTest2, MultiDBParallelOpenTest) {
// Verify empty DBs can be created in parallel
std::vector<std::thread> open_threads;
std::vector<DB*> dbs{static_cast<unsigned int>(kNumDbs), nullptr};
std::vector<std::unique_ptr<DB>> dbs(kNumDbs);
options.create_if_missing = true;
for (int i = 0; i < kNumDbs; ++i) {
open_threads.emplace_back(
@@ -4845,7 +4845,7 @@ TEST_F(DBTest2, MultiDBParallelOpenTest) {
for (int i = 0; i < kNumDbs; ++i) {
open_threads[i].join();
ASSERT_OK(dbs[i]->Put(WriteOptions(), "xi", "gua"));
delete dbs[i];
dbs[i].reset();
}
// Verify non-empty DBs can be recovered in parallel
@@ -4861,7 +4861,7 @@ TEST_F(DBTest2, MultiDBParallelOpenTest) {
// Wait and cleanup
for (int i = 0; i < kNumDbs; ++i) {
open_threads[i].join();
delete dbs[i];
dbs[i].reset();
ASSERT_OK(DestroyDB(dbnames[i], options));
}
}
@@ -4922,8 +4922,7 @@ TEST_F(DBTest2, CloseWithUnreleasedSnapshot) {
ASSERT_NOK(db_->Close());
db_->ReleaseSnapshot(ss);
ASSERT_OK(db_->Close());
delete db_;
db_ = nullptr;
db_.reset();
}
TEST_F(DBTest2, PrefixBloomReseek) {
@@ -6774,7 +6773,7 @@ TEST_F(DBTest2, CheckpointFileTemperature) {
test_fs->PopRequestedSstFileTemperatures();
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(
checkpoint->CreateCheckpoint(dbname_ + kFilePathSeparator + "tempcp"));
@@ -7536,7 +7535,7 @@ TEST_F(DBTest2, GetFileChecksumsFromCurrentManifest_CRC32) {
opts.level0_file_num_compaction_trigger = 10;
// Bootstrap the test database.
DB* db = nullptr;
std::unique_ptr<DB> db;
std::string dbname = test::PerThreadDBPath("file_chksum");
ASSERT_OK(DB::Open(opts, dbname, &db));
@@ -7570,8 +7569,7 @@ TEST_F(DBTest2, GetFileChecksumsFromCurrentManifest_CRC32) {
db->GetLiveFilesMetaData(&live_files);
ASSERT_OK(db->Close());
delete db;
db = nullptr;
db.reset();
// Process current MANIFEST file and build internal file checksum mappings.
std::unique_ptr<FileChecksumList> checksum_list(NewFileChecksumList());
+12 -9
View File
@@ -97,7 +97,7 @@ DBTestBase::DBTestBase(const std::string path, bool env_do_fsync)
EXPECT_OK(DestroyDB(dbname_, delete_options));
// Destroy it for not alternative WAL dir is used.
EXPECT_OK(DestroyDB(dbname_, options));
db_ = nullptr;
db_.reset();
Reopen(options);
Random::GetTLSInstance()->Reset(0xdeadbeef);
}
@@ -664,7 +664,8 @@ Status DBTestBase::TryReopenWithColumnFamilies(
DBOptions db_opts = DBOptions(options[0]);
last_options_ = options[0];
MaybeInstallTimeElapseOnlySleep(db_opts);
return DB::Open(db_opts, dbname_, column_families, &handles_, &db_);
Status s = DB::Open(db_opts, dbname_, column_families, &handles_, &db_);
return s;
}
Status DBTestBase::TryReopenWithColumnFamilies(
@@ -683,8 +684,7 @@ void DBTestBase::Close() {
EXPECT_OK(db_->DestroyColumnFamilyHandle(h));
}
handles_.clear();
delete db_;
db_ = nullptr;
db_.reset();
}
void DBTestBase::DestroyAndReopen(const Options& options) {
@@ -709,7 +709,8 @@ void DBTestBase::Destroy(const Options& options, bool delete_cf_paths) {
Status DBTestBase::ReadOnlyReopen(const Options& options) {
Close();
MaybeInstallTimeElapseOnlySleep(options);
return DB::OpenForReadOnly(options, dbname_, &db_);
Status s = DB::OpenForReadOnly(options, dbname_, &db_);
return s;
}
Status DBTestBase::EnforcedReadOnlyReopen(const Options& options) {
@@ -720,7 +721,8 @@ Status DBTestBase::EnforcedReadOnlyReopen(const Options& options) {
std::make_shared<ReadOnlyFileSystem>(env_->GetFileSystem());
env_read_only_ = std::make_shared<CompositeEnvWrapper>(env_, fs_read_only);
options_copy.env = env_read_only_.get();
return DB::OpenForReadOnly(options_copy, dbname_, &db_);
Status s = DB::OpenForReadOnly(options_copy, dbname_, &db_);
return s;
}
Status DBTestBase::TryReopen(const Options& options) {
@@ -735,7 +737,8 @@ Status DBTestBase::TryReopen(const Options& options) {
// clears the block cache.
last_options_ = options;
MaybeInstallTimeElapseOnlySleep(options);
return DB::Open(options, dbname_, &db_);
Status s = DB::Open(options, dbname_, &db_);
return s;
}
bool DBTestBase::IsDirectIOSupported() {
@@ -1162,7 +1165,7 @@ int DBTestBase::NumTableFilesAtLevel(int level, int cf) {
int DBTestBase::NumTableFilesAtLevel(int level, ColumnFamilyHandle* cfh,
DB* db) {
if (!db) {
db = db_;
db = db_.get();
}
std::string property;
EXPECT_TRUE(db->GetProperty(
@@ -1208,7 +1211,7 @@ std::string DBTestBase::FilesPerLevel(int cf) {
std::string DBTestBase::FilesPerLevel(ColumnFamilyHandle* cfh, DB* db) {
if (!db) {
db = db_;
db = db_.get();
}
int num_levels = db->NumberLevels(cfh);
std::string result;
+2 -2
View File
@@ -1072,7 +1072,7 @@ class DBTestBase : public testing::Test {
SpecialEnv* env_;
std::shared_ptr<Env> env_read_only_;
std::shared_ptr<Env> env_guard_;
DB* db_;
std::unique_ptr<DB> db_;
std::vector<ColumnFamilyHandle*> handles_;
int option_config_;
@@ -1157,7 +1157,7 @@ class DBTestBase : public testing::Test {
const anon::OptionsOverride& options_override =
anon::OptionsOverride()) const;
DBImpl* dbfull() { return static_cast_with_check<DBImpl>(db_); }
DBImpl* dbfull() { return static_cast_with_check<DBImpl>(db_.get()); }
void CreateColumnFamilies(const std::vector<std::string>& cfs,
const Options& options);
+33 -29
View File
@@ -395,13 +395,13 @@ TEST_P(DBWALTestWithTimestamp, RecoverAndNoFlush) {
read_opts.timestamp = &ts_slice;
ASSERT_OK(CreateAndReopenWithTs({"pikachu"}, ts_options, persist_udt,
avoid_flush_during_recovery));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "pikachu"), 0U);
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "pikachu"), 0U);
ASSERT_OK(Put(1, "foo", ts1, "v1"));
ASSERT_OK(Put(1, "baz", ts1, "v5"));
ASSERT_OK(ReopenColumnFamiliesWithTs({"pikachu"}, ts_options, persist_udt,
avoid_flush_during_recovery));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "pikachu"), 0U);
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "pikachu"), 0U);
// Do a timestamped read with ts1 after second reopen.
CheckGet(read_opts, 1, "foo", "v1", ts1);
CheckGet(read_opts, 1, "baz", "v5", ts1);
@@ -415,7 +415,7 @@ TEST_P(DBWALTestWithTimestamp, RecoverAndNoFlush) {
ASSERT_OK(ReopenColumnFamiliesWithTs({"pikachu"}, ts_options, persist_udt,
avoid_flush_during_recovery));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "pikachu"), 0U);
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "pikachu"), 0U);
std::string ts3;
PutFixed64(&ts3, 3);
ASSERT_OK(Put(1, "foo", ts3, "v4"));
@@ -466,14 +466,14 @@ TEST_P(DBWALTestWithTimestamp, RecoverAndFlush) {
ASSERT_OK(CreateAndReopenWithTs({"pikachu"}, ts_options, persist_udt));
// No flush, no sst files, because of no data.
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "pikachu"), 0U);
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "pikachu"), 0U);
ASSERT_OK(Put(1, largest_ukey_without_ts, write_ts, "v1"));
ASSERT_OK(Put(1, smallest_ukey_without_ts, write_ts, "v5"));
ASSERT_OK(ReopenColumnFamiliesWithTs({"pikachu"}, ts_options, persist_udt));
// Memtable recovered from WAL flushed because `avoid_flush_during_recovery`
// defaults to false, created one L0 file.
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "pikachu"), 1U);
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "pikachu"), 1U);
std::vector<std::vector<FileMetaData>> level_to_files;
dbfull()->TEST_GetFilesMetaData(handles_[1], &level_to_files);
@@ -1347,7 +1347,7 @@ TEST_F(DBWALTest, RecoverCheckFileAmountWithSmallWriteBuffer) {
auto tables = ListTableFiles(env_, dbname_);
ASSERT_EQ(tables.size(), static_cast<size_t>(1));
// Make sure 'dobrynia' was flushed: check sst files amount
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "dobrynia"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "dobrynia"),
static_cast<uint64_t>(1));
}
// New WAL file
@@ -1363,16 +1363,16 @@ TEST_F(DBWALTest, RecoverCheckFileAmountWithSmallWriteBuffer) {
options);
{
// No inserts => default is empty
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "default"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "default"),
static_cast<uint64_t>(0));
// First 4 keys goes to separate SSTs + 1 more SST for 2 smaller keys
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "pikachu"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "pikachu"),
static_cast<uint64_t>(5));
// 1 SST for big key + 1 SST for small one
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "dobrynia"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "dobrynia"),
static_cast<uint64_t>(2));
// 1 SST for all keys
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "nikitich"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "nikitich"),
static_cast<uint64_t>(1));
}
}
@@ -1401,7 +1401,7 @@ TEST_F(DBWALTest, RecoverCheckFileAmount) {
{
auto tables = ListTableFiles(env_, dbname_);
ASSERT_EQ(tables.size(), static_cast<size_t>(1));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "nikitich"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "nikitich"),
static_cast<uint64_t>(1));
}
// Memtable for 'nikitich' has flushed, new WAL file has opened
@@ -1425,7 +1425,7 @@ TEST_F(DBWALTest, RecoverCheckFileAmount) {
{
auto tables = ListTableFiles(env_, dbname_);
ASSERT_EQ(tables.size(), static_cast<size_t>(2));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "nikitich"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "nikitich"),
static_cast<uint64_t>(2));
}
@@ -1437,13 +1437,13 @@ TEST_F(DBWALTest, RecoverCheckFileAmount) {
// first, second and third WALs went to the same SST.
// So, there is 6 SSTs: three for 'nikitich', one for 'default', one for
// 'dobrynia', one for 'pikachu'
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "default"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "default"),
static_cast<uint64_t>(1));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "nikitich"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "nikitich"),
static_cast<uint64_t>(3));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "dobrynia"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "dobrynia"),
static_cast<uint64_t>(1));
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_, "pikachu"),
ASSERT_EQ(GetNumberOfSstFilesForColumnFamily(db_.get(), "pikachu"),
static_cast<uint64_t>(1));
}
}
@@ -1521,9 +1521,9 @@ TEST_F(DBWALTest, DISABLED_RecycleMultipleWalsCrash) {
// from an old incarnation of the WAL on recovery
ASSERT_OK(db_->PauseBackgroundWork());
ASSERT_OK(Put("ignore1", Random::GetTLSInstance()->RandomString(500)));
ASSERT_OK(static_cast_with_check<DBImpl>(db_)->TEST_SwitchMemtable());
ASSERT_OK(dbfull()->TEST_SwitchMemtable());
ASSERT_OK(Put("ignore2", Random::GetTLSInstance()->RandomString(500)));
ASSERT_OK(static_cast_with_check<DBImpl>(db_)->TEST_SwitchMemtable());
ASSERT_OK(dbfull()->TEST_SwitchMemtable());
ASSERT_OK(db_->ContinueBackgroundWork());
ASSERT_OK(Flush());
ASSERT_OK(Put("ignore3", Random::GetTLSInstance()->RandomString(500)));
@@ -1545,13 +1545,13 @@ TEST_F(DBWALTest, DISABLED_RecycleMultipleWalsCrash) {
// gap in sequence numbers to interfere with recovery
ASSERT_OK(db_->PauseBackgroundWork());
ASSERT_OK(Put("key1", "val1"));
ASSERT_OK(static_cast_with_check<DBImpl>(db_)->TEST_SwitchMemtable());
ASSERT_OK(dbfull()->TEST_SwitchMemtable());
ASSERT_OK(Put("key2", "val2"));
ASSERT_OK(static_cast_with_check<DBImpl>(db_)->TEST_SwitchMemtable());
ASSERT_OK(dbfull()->TEST_SwitchMemtable());
// Need a gap in sequence numbers, so e.g. ingest external file
// with an open snapshot
{
ManagedSnapshot snapshot(db_);
ManagedSnapshot snapshot(db_.get());
ASSERT_OK(
db_->IngestExternalFile({external_file1}, IngestExternalFileOptions()));
}
@@ -1560,7 +1560,7 @@ TEST_F(DBWALTest, DISABLED_RecycleMultipleWalsCrash) {
// Need an SST file that is logically after that WAL, so that dropping WAL
// data is not a valid point in time.
{
ManagedSnapshot snapshot(db_);
ManagedSnapshot snapshot(db_.get());
ASSERT_OK(
db_->IngestExternalFile({external_file2}, IngestExternalFileOptions()));
}
@@ -1655,10 +1655,10 @@ TEST_F(DBWALTest, SyncWalPartialFailure) {
// with a single thread, to exercise as much logic as we reasonably can.
ASSERT_OK(db_->PauseBackgroundWork());
ASSERT_OK(Put("key1", "val1"));
ASSERT_OK(static_cast_with_check<DBImpl>(db_)->TEST_SwitchMemtable());
ASSERT_OK(dbfull()->TEST_SwitchMemtable());
ASSERT_OK(db_->SyncWAL());
ASSERT_OK(Put("key2", "val2"));
ASSERT_OK(static_cast_with_check<DBImpl>(db_)->TEST_SwitchMemtable());
ASSERT_OK(dbfull()->TEST_SwitchMemtable());
ASSERT_OK(Put("key3", "val3"));
// Allow 1 of the WALs to sync, but another won't
@@ -1879,9 +1879,11 @@ TEST_F(DBWALTest, TrackAndVerifyWALsRecycleWAL) {
// Drop `Put("key1", "old_value")` in the first WAL
ASSERT_OK(test::TruncateFile(options.env, log_name, 0 /* new_length */));
Status s = DB::Open(options, dbname_, &db_);
{
Status s = DB::Open(options, dbname_, &db_);
ASSERT_OK(s);
ASSERT_OK(s);
}
ASSERT_EQ("wal_to_recycle", Get("key_ignore2"));
ASSERT_EQ("NOT_FOUND", Get("key1"));
@@ -1979,7 +1981,10 @@ TEST_P(DBWALTrackAndVerifyWALsWithParamsTest, Basic) {
ASSERT_OK(options.env->DeleteFile(second_log_name));
}
Status s = DB::Open(options, dbname_, &db_);
Status s;
{
s = DB::Open(options, dbname_, &db_);
}
if (i == 0) {
ASSERT_OK(s);
@@ -2266,11 +2271,10 @@ TEST_F(DBWALTest, RaceInstallFlushResultsWithWalObsoletion) {
SyncPoint::GetInstance()->DisableProcessing();
SyncPoint::GetInstance()->ClearAllCallBacks();
DB* db1 = nullptr;
std::unique_ptr<DB> db1;
Status s = DB::OpenForReadOnly(options, dbname_, &db1);
ASSERT_OK(s);
assert(db1);
delete db1;
}
TEST_F(DBWALTest, FixSyncWalOnObseletedWalWithNewManifestCausingMissingWAL) {
+5 -5
View File
@@ -662,7 +662,7 @@ TEST_F(DBBasicTestWithTimestamp, TrimHistoryTest) {
ASSERT_OK(db_->Put(WriteOptions(), "k1", Timestamp(4, 0), "v2"));
ASSERT_OK(db_->Delete(WriteOptions(), "k1", Timestamp(5, 0)));
ASSERT_OK(db_->Put(WriteOptions(), "k1", Timestamp(6, 0), "v3"));
check_value_by_ts(db_, "k1", Timestamp(7, 0), Status::OK(), "v3",
check_value_by_ts(db_.get(), "k1", Timestamp(7, 0), Status::OK(), "v3",
Timestamp(6, 0));
ASSERT_OK(Flush());
Close();
@@ -675,27 +675,27 @@ TEST_F(DBBasicTestWithTimestamp, TrimHistoryTest) {
// Trim data whose version > Timestamp(5, 0), read(k1, ts(7)) <- NOT_FOUND.
ASSERT_OK(DB::OpenAndTrimHistory(db_options, dbname_, column_families,
&handles_, &db_, Timestamp(5, 0)));
check_value_by_ts(db_, "k1", Timestamp(7, 0), Status::NotFound(), "",
check_value_by_ts(db_.get(), "k1", Timestamp(7, 0), Status::NotFound(), "",
Timestamp(5, 0));
Close();
// Trim data whose timestamp > Timestamp(4, 0), read(k1, ts(7)) <- v2
ASSERT_OK(DB::OpenAndTrimHistory(db_options, dbname_, column_families,
&handles_, &db_, Timestamp(4, 0)));
check_value_by_ts(db_, "k1", Timestamp(7, 0), Status::OK(), "v2",
check_value_by_ts(db_.get(), "k1", Timestamp(7, 0), Status::OK(), "v2",
Timestamp(4, 0));
Close();
Reopen(options);
ASSERT_OK(db_->DeleteRange(WriteOptions(), db_->DefaultColumnFamily(), "k1",
"k3", Timestamp(7, 0)));
check_value_by_ts(db_, "k1", Timestamp(8, 0), Status::NotFound(), "",
check_value_by_ts(db_.get(), "k1", Timestamp(8, 0), Status::NotFound(), "",
Timestamp(7, 0));
Close();
// Trim data whose timestamp > Timestamp(6, 0), read(k1, ts(8)) <- v2
ASSERT_OK(DB::OpenAndTrimHistory(db_options, dbname_, column_families,
&handles_, &db_, Timestamp(6, 0)));
check_value_by_ts(db_, "k1", Timestamp(8, 0), Status::OK(), "v2",
check_value_by_ts(db_.get(), "k1", Timestamp(8, 0), Status::OK(), "v2",
Timestamp(4, 0));
Close();
}
+20 -20
View File
@@ -183,11 +183,11 @@ TEST_P(DBWriteBufferManagerTest, SharedWriteBufferAcrossCFs2) {
// is waiting to be finished but DBs tries to write meanwhile.
TEST_P(DBWriteBufferManagerTest, SharedWriteBufferLimitAcrossDB) {
std::vector<std::string> dbnames;
std::vector<DB*> dbs;
std::vector<std::unique_ptr<DB>> dbs;
int num_dbs = 3;
for (int i = 0; i < num_dbs; i++) {
dbs.push_back(nullptr);
dbs.emplace_back();
dbnames.push_back(
test::PerThreadDBPath("db_shared_wb_db" + std::to_string(i)));
}
@@ -266,7 +266,7 @@ TEST_P(DBWriteBufferManagerTest, SharedWriteBufferLimitAcrossDB) {
// Last writer will write and when its blocked it will signal Flush to
// continue to clear the stall.
threads.emplace_back(write_db, db_);
threads.emplace_back(write_db, db_.get());
// Wait untill first DB is blocked and then create the multiple writers for
// different DBs which will be blocked from getting added to the queue because
// stall is in effect.
@@ -277,7 +277,7 @@ TEST_P(DBWriteBufferManagerTest, SharedWriteBufferLimitAcrossDB) {
}
}
for (int i = 0; i < num_dbs; i++) {
threads.emplace_back(write_db, dbs[i]);
threads.emplace_back(write_db, dbs[i].get());
}
for (auto& t : threads) {
t.join();
@@ -289,7 +289,7 @@ TEST_P(DBWriteBufferManagerTest, SharedWriteBufferLimitAcrossDB) {
for (int i = 0; i < num_dbs; i++) {
ASSERT_OK(dbs[i]->Close());
ASSERT_OK(DestroyDB(dbnames[i], options));
delete dbs[i];
dbs[i].reset();
}
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks();
@@ -300,11 +300,11 @@ TEST_P(DBWriteBufferManagerTest, SharedWriteBufferLimitAcrossDB) {
// blocked when stall by WriteBufferManager is in effect.
TEST_P(DBWriteBufferManagerTest, SharedWriteBufferLimitAcrossDB1) {
std::vector<std::string> dbnames;
std::vector<DB*> dbs;
std::vector<std::unique_ptr<DB>> dbs;
int num_dbs = 3;
for (int i = 0; i < num_dbs; i++) {
dbs.push_back(nullptr);
dbs.emplace_back();
dbnames.push_back(
test::PerThreadDBPath("db_shared_wb_db" + std::to_string(i)));
}
@@ -407,7 +407,7 @@ TEST_P(DBWriteBufferManagerTest, SharedWriteBufferLimitAcrossDB1) {
// |
// Last writer thread will write and when its blocked it will signal Flush to
// continue to clear the stall.
threads.emplace_back(write_db, db_);
threads.emplace_back(write_db, db_.get());
// Wait untill first thread is blocked and then create the multiple writer
// threads.
{
@@ -421,7 +421,7 @@ TEST_P(DBWriteBufferManagerTest, SharedWriteBufferLimitAcrossDB1) {
// Write to multiple columns of db_.
writer_threads.emplace_back(write_cf, i % 3);
// Write to different dbs.
threads.emplace_back(write_db, dbs[i]);
threads.emplace_back(write_db, dbs[i].get());
}
for (auto& t : threads) {
t.join();
@@ -441,7 +441,7 @@ TEST_P(DBWriteBufferManagerTest, SharedWriteBufferLimitAcrossDB1) {
for (int i = 0; i < num_dbs; i++) {
ASSERT_OK(dbs[i]->Close());
ASSERT_OK(DestroyDB(dbnames[i], options));
delete dbs[i];
dbs[i].reset();
}
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks();
@@ -604,11 +604,11 @@ TEST_P(DBWriteBufferManagerTest, MixedSlowDownOptionsSingleDB) {
// dbs by passing different values to WriteOption.no_slown_down.
TEST_P(DBWriteBufferManagerTest, MixedSlowDownOptionsMultipleDB) {
std::vector<std::string> dbnames;
std::vector<DB*> dbs;
std::vector<std::unique_ptr<DB>> dbs;
int num_dbs = 4;
for (int i = 0; i < num_dbs; i++) {
dbs.push_back(nullptr);
dbs.emplace_back();
dbnames.push_back(
test::PerThreadDBPath("db_shared_wb_db" + std::to_string(i)));
}
@@ -732,7 +732,7 @@ TEST_P(DBWriteBufferManagerTest, MixedSlowDownOptionsMultipleDB) {
// |
// Last writer thread will write and when its blocked/return it will signal
// Flush to continue to clear the stall.
threads.emplace_back(write_slow_down, db_);
threads.emplace_back(write_slow_down, db_.get());
// Wait untill first thread writing to DB is blocked and then
// create the multiple writers.
{
@@ -744,11 +744,11 @@ TEST_P(DBWriteBufferManagerTest, MixedSlowDownOptionsMultipleDB) {
for (int i = 0; i < num_dbs; i += 2) {
// Write to multiple columns of db_.
writer_threads.emplace_back(write_slow_down, db_);
writer_threads.emplace_back(write_no_slow_down, db_);
writer_threads.emplace_back(write_slow_down, db_.get());
writer_threads.emplace_back(write_no_slow_down, db_.get());
// Write to different DBs.
threads.emplace_back(write_slow_down, dbs[i]);
threads.emplace_back(write_no_slow_down, dbs[i + 1]);
threads.emplace_back(write_slow_down, dbs[i].get());
threads.emplace_back(write_no_slow_down, dbs[i + 1].get());
}
for (auto& t : threads) {
@@ -773,7 +773,7 @@ TEST_P(DBWriteBufferManagerTest, MixedSlowDownOptionsMultipleDB) {
for (int i = 0; i < num_dbs; i++) {
ASSERT_OK(dbs[i]->Close());
ASSERT_OK(DestroyDB(dbnames[i], options));
delete dbs[i];
dbs[i].reset();
}
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->ClearAllCallBacks();
@@ -809,7 +809,7 @@ TEST_P(DBWriteBufferManagerTest, StopSwitchingMemTablesOnceFlushing) {
Reopen(options);
std::string dbname = test::PerThreadDBPath("db_shared_wbm_db");
DB* shared_wbm_db = nullptr;
std::unique_ptr<DB> shared_wbm_db;
ASSERT_OK(DestroyDB(dbname, options));
ASSERT_OK(DB::Open(options, dbname, &shared_wbm_db));
@@ -842,7 +842,7 @@ TEST_P(DBWriteBufferManagerTest, StopSwitchingMemTablesOnceFlushing) {
sleeping_task_high.WaitUntilDone();
ASSERT_OK(shared_wbm_db->Close());
ASSERT_OK(DestroyDB(dbname, options));
delete shared_wbm_db;
shared_wbm_db.reset();
}
TEST_F(DBWriteBufferManagerTest, RuntimeChangeableAllowStall) {
+12 -14
View File
@@ -1550,7 +1550,7 @@ TEST_F(DBErrorHandlingFSTest, MultiDBCompactionError) {
std::vector<FaultInjectionTestFS*> fault_fs;
std::vector<Options> options;
std::vector<std::shared_ptr<ErrorHandlerFSListener>> listener;
std::vector<DB*> db;
std::vector<std::unique_ptr<DB>> db;
std::shared_ptr<SstFileManager> sfm(NewSstFileManager(def_env));
int kNumDbInstances = 3;
Random rnd(301);
@@ -1567,7 +1567,6 @@ TEST_F(DBErrorHandlingFSTest, MultiDBCompactionError) {
options[i].writable_file_max_buffer_size = 32768;
options[i].listeners.emplace_back(listener[i]);
options[i].sst_file_manager = sfm;
DB* dbptr;
char buf[16];
listener[i]->EnableAutoRecovery();
@@ -1576,8 +1575,8 @@ TEST_F(DBErrorHandlingFSTest, MultiDBCompactionError) {
IOStatus::NoSpace("Out of space"));
snprintf(buf, sizeof(buf), "_%d", i);
ASSERT_OK(DestroyDB(dbname_ + std::string(buf), options[i]));
ASSERT_OK(DB::Open(options[i], dbname_ + std::string(buf), &dbptr));
db.emplace_back(dbptr);
ASSERT_OK(
DB::Open(options[i], dbname_ + std::string(buf), &db.emplace_back()));
}
for (auto i = 0; i < kNumDbInstances; ++i) {
@@ -1609,7 +1608,7 @@ TEST_F(DBErrorHandlingFSTest, MultiDBCompactionError) {
}
for (auto i = 0; i < kNumDbInstances; ++i) {
Status s = static_cast<DBImpl*>(db[i])->TEST_WaitForCompact();
Status s = static_cast<DBImpl*>(db[i].get())->TEST_WaitForCompact();
ASSERT_EQ(s.severity(), Status::Severity::kSoftError);
fault_fs[i]->SetFilesystemActive(true);
}
@@ -1618,7 +1617,7 @@ TEST_F(DBErrorHandlingFSTest, MultiDBCompactionError) {
for (auto i = 0; i < kNumDbInstances; ++i) {
std::string prop;
ASSERT_EQ(listener[i]->WaitForRecovery(5000000), true);
ASSERT_OK(static_cast<DBImpl*>(db[i])->TEST_WaitForCompact());
ASSERT_OK(static_cast<DBImpl*>(db[i].get())->TEST_WaitForCompact());
EXPECT_TRUE(db[i]->GetProperty(
"rocksdb.num-files-at-level" + std::to_string(0), &prop));
EXPECT_EQ(atoi(prop.c_str()), 0);
@@ -1634,7 +1633,7 @@ TEST_F(DBErrorHandlingFSTest, MultiDBCompactionError) {
for (auto i = 0; i < kNumDbInstances; ++i) {
char buf[16];
snprintf(buf, sizeof(buf), "_%d", i);
delete db[i];
db[i].reset();
fault_fs[i]->SetFilesystemActive(true);
if (getenv("KEEP_DB")) {
printf("DB is still at %s%s\n", dbname_.c_str(), buf);
@@ -1657,7 +1656,7 @@ TEST_F(DBErrorHandlingFSTest, MultiDBVariousErrors) {
std::vector<FaultInjectionTestFS*> fault_fs;
std::vector<Options> options;
std::vector<std::shared_ptr<ErrorHandlerFSListener>> listener;
std::vector<DB*> db;
std::vector<std::unique_ptr<DB>> db;
std::shared_ptr<SstFileManager> sfm(NewSstFileManager(def_env));
int kNumDbInstances = 3;
Random rnd(301);
@@ -1674,7 +1673,6 @@ TEST_F(DBErrorHandlingFSTest, MultiDBVariousErrors) {
options[i].writable_file_max_buffer_size = 32768;
options[i].listeners.emplace_back(listener[i]);
options[i].sst_file_manager = sfm;
DB* dbptr;
char buf[16];
listener[i]->EnableAutoRecovery();
@@ -1695,8 +1693,8 @@ TEST_F(DBErrorHandlingFSTest, MultiDBVariousErrors) {
}
snprintf(buf, sizeof(buf), "_%d", i);
ASSERT_OK(DestroyDB(dbname_ + std::string(buf), options[i]));
ASSERT_OK(DB::Open(options[i], dbname_ + std::string(buf), &dbptr));
db.emplace_back(dbptr);
ASSERT_OK(
DB::Open(options[i], dbname_ + std::string(buf), &db.emplace_back()));
}
for (auto i = 0; i < kNumDbInstances; ++i) {
@@ -1732,7 +1730,7 @@ TEST_F(DBErrorHandlingFSTest, MultiDBVariousErrors) {
}
for (auto i = 0; i < kNumDbInstances; ++i) {
Status s = static_cast<DBImpl*>(db[i])->TEST_WaitForCompact();
Status s = static_cast<DBImpl*>(db[i].get())->TEST_WaitForCompact();
switch (i) {
case 0:
ASSERT_EQ(s.severity(), Status::Severity::kSoftError);
@@ -1754,7 +1752,7 @@ TEST_F(DBErrorHandlingFSTest, MultiDBVariousErrors) {
ASSERT_EQ(listener[i]->WaitForRecovery(5000000), true);
}
if (i == 1) {
ASSERT_OK(static_cast<DBImpl*>(db[i])->TEST_WaitForCompact());
ASSERT_OK(static_cast<DBImpl*>(db[i].get())->TEST_WaitForCompact());
}
EXPECT_TRUE(db[i]->GetProperty(
"rocksdb.num-files-at-level" + std::to_string(0), &prop));
@@ -1772,7 +1770,7 @@ TEST_F(DBErrorHandlingFSTest, MultiDBVariousErrors) {
char buf[16];
snprintf(buf, sizeof(buf), "_%d", i);
fault_fs[i]->SetFilesystemActive(true);
delete db[i];
db[i].reset();
if (getenv("KEEP_DB")) {
printf("DB is still at %s%s\n", dbname_.c_str(), buf);
} else {
+1 -1
View File
@@ -2816,7 +2816,7 @@ TEST_F(ExternalSSTFileBasicTest, FailIfNotBottommostLevelAndDisallowMemtable) {
{
const Snapshot* snapshot = db_->GetSnapshot();
ManagedSnapshot snapshot_guard(db_, snapshot);
ManagedSnapshot snapshot_guard(db_.get(), snapshot);
IngestExternalFileOptions ifo;
ifo.fail_if_not_bottommost_level = true;
ifo.snapshot_consistency = true;
+12 -11
View File
@@ -80,8 +80,7 @@ class ExternSSTFileLinkFailFallbackTest
}
void TearDown() override {
delete db_;
db_ = nullptr;
db_.reset();
ASSERT_OK(DestroyDB(dbname_, options_));
}
@@ -4040,7 +4039,7 @@ TEST_P(IngestDBGeneratedFileTest2, NotOverlapWithDB) {
std::string db2_path = test::PerThreadDBPath("DB2");
Options db2_options;
db2_options.create_if_missing = true;
DB* db2 = nullptr;
std::unique_ptr<DB> db2;
ASSERT_OK(DB::Open(db2_options, db2_path, &db2));
// Write some base data.
expected_value.emplace_back(rnd.RandomString(100));
@@ -4069,10 +4068,10 @@ TEST_P(IngestDBGeneratedFileTest2, NotOverlapWithDB) {
ASSERT_OK(db_->DropColumnFamily(temp_cfh));
ASSERT_OK(db_->DestroyColumnFamilyHandle(temp_cfh));
ASSERT_OK(db2->Close());
delete db2;
db2.reset();
ASSERT_OK(DB::Open(db2_options, db2_path, &db2));
ASSERT_OK(db2->Close());
delete db2;
db2.reset();
ASSERT_OK(DestroyDB(db2_path, db2_options));
} else {
ASSERT_OK(db_->DropColumnFamily(temp_cfh));
@@ -4135,6 +4134,7 @@ TEST_P(IngestDBGeneratedFileTest2, NonZeroSeqno) {
// Create temp CF/DB
Options temp_cf_opts;
ColumnFamilyHandle* temp_cfh = nullptr;
std::unique_ptr<DB> temp_db_holder;
DB* from_db = nullptr;
std::string temp_db_name;
// Using a separate DB also validates that latest sequence number
@@ -4155,10 +4155,11 @@ TEST_P(IngestDBGeneratedFileTest2, NonZeroSeqno) {
if (use_temp_db) {
temp_cf_opts.create_if_missing = true;
temp_db_name = dbname_ + "/temp_db_" + std::to_string(rnd->Next());
ASSERT_OK(DB::Open(temp_cf_opts, temp_db_name, &from_db));
ASSERT_OK(DB::Open(temp_cf_opts, temp_db_name, &temp_db_holder));
from_db = temp_db_holder.get();
temp_cfh = from_db->DefaultColumnFamily();
} else {
from_db = db_;
from_db = db_.get();
ASSERT_OK(
from_db->CreateColumnFamily(temp_cf_opts, "temp_cf", &temp_cfh));
}
@@ -4293,7 +4294,7 @@ TEST_P(IngestDBGeneratedFileTest2, NonZeroSeqno) {
ASSERT_OK(db_->WaitForCompact({}));
if (use_temp_db) {
ASSERT_OK(from_db->Close());
delete from_db;
temp_db_holder.reset();
ASSERT_OK(DestroyDB(temp_db_name, temp_cf_opts));
} else {
ASSERT_OK(db_->DropColumnFamily(temp_cfh));
@@ -4381,7 +4382,7 @@ TEST_P(IngestDBGeneratedFileTest2, ZeroAndNonZeroSeqno) {
std::string temp_db_name =
dbname_ + "/temp_db_" + std::to_string(rnd->Next());
DB* temp_db = nullptr;
std::unique_ptr<DB> temp_db;
ASSERT_OK(DB::Open(temp_db_opts, temp_db_name, &temp_db));
const Snapshot* snapshot = db_->GetSnapshot();
@@ -4444,7 +4445,7 @@ TEST_P(IngestDBGeneratedFileTest2, ZeroAndNonZeroSeqno) {
cro.bottommost_level_compaction = BottommostLevelCompaction::kForce;
ASSERT_OK(temp_db->CompactRange(cro, nullptr, nullptr));
SCOPED_TRACE("Temp DB LSM: " +
FilesPerLevel(temp_db->DefaultColumnFamily(), temp_db));
FilesPerLevel(temp_db->DefaultColumnFamily(), temp_db.get()));
// Base data from snapshot
std::vector<std::string> sst_file_paths_zero_seqno;
@@ -4539,7 +4540,7 @@ TEST_P(IngestDBGeneratedFileTest2, ZeroAndNonZeroSeqno) {
ASSERT_OK(db_->DestroyColumnFamilyHandle(live_write_cfh));
ASSERT_OK(temp_db->Close());
delete temp_db;
temp_db.reset();
ASSERT_OK(DestroyDB(temp_db_name, temp_db_opts));
} while (ChangeOptions(kSkipPlainTable | kSkipFIFOCompaction));
}
+4 -6
View File
@@ -76,7 +76,7 @@ class FaultInjectionTest
std::string dbname_;
std::shared_ptr<Cache> tiny_cache_;
Options options_;
DB* db_;
std::unique_ptr<DB> db_;
FaultInjectionTest()
: option_config_(std::get<1>(GetParam())),
@@ -260,10 +260,7 @@ class FaultInjectionTest
return Slice(*storage);
}
void CloseDB() {
delete db_;
db_ = nullptr;
}
void CloseDB() { db_.reset(); }
Status OpenDB() {
CloseDB();
@@ -348,7 +345,8 @@ class FaultInjectionTest
}
void WaitCompactionFinish() {
ASSERT_OK(static_cast<DBImpl*>(db_->GetRootDB())->TEST_WaitForCompact());
ASSERT_OK(static_cast_with_check<DBImpl>(db_->GetRootDB())
->TEST_WaitForCompact());
ASSERT_OK(db_->Put(WriteOptions(), "", ""));
}
+5 -6
View File
@@ -344,19 +344,18 @@ int main(int argc, char** argv) {
status = ROCKSDB_NAMESPACE::DestroyDB(path, options);
assert(status.ok());
ROCKSDB_NAMESPACE::DB* db_raw;
status = ROCKSDB_NAMESPACE::DB::Open(options, path, &db_raw);
std::unique_ptr<ROCKSDB_NAMESPACE::DB> db;
status = ROCKSDB_NAMESPACE::DB::Open(options, path, &db);
assert(status.ok());
std::unique_ptr<ROCKSDB_NAMESPACE::DB> db(db_raw);
std::vector<ShardState> shard_states(FLAGS_shards + 1);
std::deque<Reader> readers;
while (static_cast<int>(readers.size()) < FLAGS_readers) {
readers.emplace_back(&shard_states, db_raw);
readers.emplace_back(&shard_states, db.get());
}
std::deque<Writer> writers;
while (static_cast<int>(writers.size()) < FLAGS_writers) {
writers.emplace_back(&shard_states, db_raw);
writers.emplace_back(&shard_states, db.get());
}
// Each shard gets a random reader and random writer assigned to it
@@ -367,7 +366,7 @@ int main(int argc, char** argv) {
shard_states[i].writer = &writers[writer_dist(rng)];
}
StatsThread stats_thread(db_raw);
StatsThread stats_thread(db.get());
for (Writer& w : writers) {
w.start();
}
+17 -17
View File
@@ -371,7 +371,7 @@ TEST_F(ImportColumnFamilyTest, ImportExportedSSTFromAnotherCF) {
ASSERT_OK(Flush(1));
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->ExportColumnFamily(handles_[1], export_files_dir_,
&metadata_ptr_));
ASSERT_NE(metadata_ptr_, nullptr);
@@ -481,14 +481,14 @@ TEST_F(ImportColumnFamilyTest, ImportExportedSSTFromAnotherDB) {
ASSERT_OK(Flush(1));
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->ExportColumnFamily(handles_[1], export_files_dir_,
&metadata_ptr_));
ASSERT_NE(metadata_ptr_, nullptr);
delete checkpoint;
// Create a new db and import the files.
DB* db_copy;
std::unique_ptr<DB> db_copy;
ASSERT_OK(DestroyDir(env_, dbname_ + "/db_copy"));
ASSERT_OK(DB::Open(options, dbname_ + "/db_copy", &db_copy));
ColumnFamilyHandle* cfh = nullptr;
@@ -504,7 +504,7 @@ TEST_F(ImportColumnFamilyTest, ImportExportedSSTFromAnotherDB) {
}
ASSERT_OK(db_copy->DropColumnFamily(cfh));
ASSERT_OK(db_copy->DestroyColumnFamilyHandle(cfh));
delete db_copy;
db_copy.reset();
ASSERT_OK(DestroyDir(env_, dbname_ + "/db_copy"));
}
@@ -529,7 +529,7 @@ TEST_F(ImportColumnFamilyTest,
ASSERT_OK(db_->DeleteRange(WriteOptions(), handles_[1], Key(0), Key(2)));
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->ExportColumnFamily(handles_[1], export_files_dir_,
&metadata_ptr_));
ASSERT_NE(metadata_ptr_, nullptr);
@@ -605,14 +605,14 @@ TEST_F(ImportColumnFamilyTest, LevelFilesOverlappingAtEndpoints) {
ASSERT_GT(NumTableFilesAtLevel(1, 1), 1);
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->ExportColumnFamily(handles_[1], export_files_dir_,
&metadata_ptr_));
ASSERT_NE(metadata_ptr_, nullptr);
delete checkpoint;
// Create a new db and import the files.
DB* db_copy;
std::unique_ptr<DB> db_copy;
ASSERT_OK(DestroyDir(env_, dbname_ + "/db_copy"));
ASSERT_OK(DB::Open(options, dbname_ + "/db_copy", &db_copy));
ColumnFamilyHandle* cfh = nullptr;
@@ -627,7 +627,7 @@ TEST_F(ImportColumnFamilyTest, LevelFilesOverlappingAtEndpoints) {
}
ASSERT_OK(db_copy->DropColumnFamily(cfh));
ASSERT_OK(db_copy->DestroyColumnFamilyHandle(cfh));
delete db_copy;
db_copy.reset();
ASSERT_OK(DestroyDir(env_, dbname_ + "/db_copy"));
for (const Snapshot* snapshot : snapshots) {
db_->ReleaseSnapshot(snapshot);
@@ -771,12 +771,12 @@ TEST_F(ImportColumnFamilyTest, ImportMultiColumnFamilyTest) {
Checkpoint* checkpoint1;
Checkpoint* checkpoint2;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint1));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint1));
ASSERT_OK(checkpoint1->ExportColumnFamily(handles_[1], export_files_dir_,
&metadata_ptr_));
// Create a new db and import the files.
DB* db_copy;
std::unique_ptr<DB> db_copy;
ASSERT_OK(DestroyDir(env_, dbname_ + "/db_copy"));
ASSERT_OK(DB::Open(options, dbname_ + "/db_copy", &db_copy));
ColumnFamilyHandle* copy_cfh = nullptr;
@@ -796,7 +796,7 @@ TEST_F(ImportColumnFamilyTest, ImportMultiColumnFamilyTest) {
ASSERT_OK(db_copy->Flush(FlushOptions()));
// Flush again to create another L0 file. It should have higher sequencer.
ASSERT_OK(Checkpoint::Create(db_copy, &checkpoint2));
ASSERT_OK(Checkpoint::Create(db_copy.get(), &checkpoint2));
ASSERT_OK(checkpoint2->ExportColumnFamily(copy_cfh, export_files_dir2_,
&metadata_ptr2_));
@@ -826,7 +826,7 @@ TEST_F(ImportColumnFamilyTest, ImportMultiColumnFamilyTest) {
ASSERT_OK(db_copy->DropColumnFamily(copy_cfh));
ASSERT_OK(db_copy->DestroyColumnFamilyHandle(copy_cfh));
delete db_copy;
db_copy.reset();
ASSERT_OK(DestroyDir(env_, dbname_ + "/db_copy"));
}
@@ -840,12 +840,12 @@ TEST_F(ImportColumnFamilyTest, ImportMultiColumnFamilyWithOverlap) {
Checkpoint* checkpoint1;
Checkpoint* checkpoint2;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint1));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint1));
ASSERT_OK(checkpoint1->ExportColumnFamily(handles_[1], export_files_dir_,
&metadata_ptr_));
// Create a new db and import the files.
DB* db_copy;
std::unique_ptr<DB> db_copy;
ASSERT_OK(DestroyDir(env_, dbname_ + "/db_copy"));
ASSERT_OK(DB::Open(options, dbname_ + "/db_copy", &db_copy));
ColumnFamilyHandle* copy_cfh = nullptr;
@@ -857,7 +857,7 @@ TEST_F(ImportColumnFamilyTest, ImportMultiColumnFamilyWithOverlap) {
ASSERT_OK(db_copy->Flush(FlushOptions()));
// Flush again to create another L0 file. It should have higher sequencer.
ASSERT_OK(Checkpoint::Create(db_copy, &checkpoint2));
ASSERT_OK(Checkpoint::Create(db_copy.get(), &checkpoint2));
ASSERT_OK(checkpoint2->ExportColumnFamily(copy_cfh, export_files_dir2_,
&metadata_ptr2_));
@@ -877,7 +877,7 @@ TEST_F(ImportColumnFamilyTest, ImportMultiColumnFamilyWithOverlap) {
ASSERT_OK(db_copy->DropColumnFamily(copy_cfh));
ASSERT_OK(db_copy->DestroyColumnFamilyHandle(copy_cfh));
delete db_copy;
db_copy.reset();
ASSERT_OK(DestroyDir(env_, dbname_ + "/db_copy"));
}
@@ -1017,7 +1017,7 @@ TEST_F(ImportColumnFamilyTest, AssignEpochNumberToMultipleCF) {
// corruption where two L0 files can have the same epoch number but
// with overlapping key range.
Checkpoint* checkpoint1;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint1));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint1));
ASSERT_OK(checkpoint1->ExportColumnFamily(handles_[1], export_files_dir_,
&metadata_ptr_));
ASSERT_OK(checkpoint1->ExportColumnFamily(handles_[2], export_files_dir2_,
+16 -17
View File
@@ -105,7 +105,7 @@ class TestCompactionListener : public EventListener {
ASSERT_EQ(ci.output_files.size(), ci.output_file_infos.size());
ASSERT_TRUE(test_);
ASSERT_EQ(test_->db_, db);
ASSERT_EQ(test_->db_.get(), db);
std::vector<std::vector<FileMetaData>> files_by_level;
test_->dbfull()->TEST_GetFilesMetaData(test_->handles_[ci.cf_id],
@@ -197,7 +197,7 @@ TEST_F(EventListenerTest, OnSingleDBCompactionTest) {
ASSERT_EQ(listener->compacted_dbs_.size(), cf_names.size());
for (size_t i = 0; i < cf_names.size(); ++i) {
ASSERT_EQ(listener->compacted_dbs_[i], db_);
ASSERT_EQ(listener->compacted_dbs_[i], db_.get());
}
}
@@ -268,7 +268,7 @@ class TestFlushListener : public EventListener {
// that assumption does not hold (see the test case MultiDBMultiListeners
// below).
ASSERT_TRUE(test_);
if (db == test_->db_) {
if (db == test_->db_.get()) {
std::vector<std::vector<FileMetaData>> files_by_level;
ASSERT_LT(info.cf_id, test_->handles_.size());
ASSERT_GE(info.cf_id, 0u);
@@ -343,7 +343,7 @@ TEST_F(EventListenerTest, OnSingleDBFlushTest) {
// make sure callback functions are called in the right order
for (size_t i = 0; i < cf_names.size(); ++i) {
ASSERT_EQ(listener->flushed_dbs_[i], db_);
ASSERT_EQ(listener->flushed_dbs_[i], db_.get());
ASSERT_EQ(listener->flushed_column_family_names_[i], cf_names[i]);
}
}
@@ -387,7 +387,7 @@ TEST_F(EventListenerTest, MultiCF) {
// make sure callback functions are called in the right order
if (i == 7) {
for (size_t j = 0; j < cf_names.size(); j++) {
ASSERT_EQ(listener->flushed_dbs_[j], db_);
ASSERT_EQ(listener->flushed_dbs_[j], db_.get());
ASSERT_EQ(listener->flushed_column_family_names_[j], cf_names[j]);
}
}
@@ -422,22 +422,21 @@ TEST_F(EventListenerTest, MultiDBMultiListeners) {
DBOptions db_opts(options);
ColumnFamilyOptions cf_opts(options);
std::vector<DB*> dbs;
std::vector<std::unique_ptr<DB>> dbs;
std::vector<std::vector<ColumnFamilyHandle*>> vec_handles;
for (int d = 0; d < kNumDBs; ++d) {
ASSERT_OK(DestroyDB(dbname_ + std::to_string(d), options));
DB* db;
ASSERT_OK(
DB::Open(options, dbname_ + std::to_string(d), &dbs.emplace_back()));
std::vector<ColumnFamilyHandle*> handles;
ASSERT_OK(DB::Open(options, dbname_ + std::to_string(d), &db));
for (size_t c = 0; c < cf_names.size(); ++c) {
ColumnFamilyHandle* handle;
ASSERT_OK(db->CreateColumnFamily(cf_opts, cf_names[c], &handle));
ASSERT_OK(dbs.back()->CreateColumnFamily(cf_opts, cf_names[c], &handle));
handles.push_back(handle);
}
vec_handles.push_back(std::move(handles));
dbs.push_back(db);
}
for (int d = 0; d < kNumDBs; ++d) {
@@ -450,23 +449,23 @@ TEST_F(EventListenerTest, MultiDBMultiListeners) {
for (size_t c = 0; c < cf_names.size(); ++c) {
for (int d = 0; d < kNumDBs; ++d) {
ASSERT_OK(dbs[d]->Flush(FlushOptions(), vec_handles[d][c]));
ASSERT_OK(
static_cast_with_check<DBImpl>(dbs[d])->TEST_WaitForFlushMemTable());
ASSERT_OK(static_cast_with_check<DBImpl>(dbs[d].get())
->TEST_WaitForFlushMemTable());
}
}
for (int d = 0; d < kNumDBs; ++d) {
// Ensure background work is fully finished including listener callbacks
// before accessing listener state.
ASSERT_OK(
static_cast_with_check<DBImpl>(dbs[d])->TEST_WaitForBackgroundWork());
ASSERT_OK(static_cast_with_check<DBImpl>(dbs[d].get())
->TEST_WaitForBackgroundWork());
}
for (auto* listener : listeners) {
int pos = 0;
for (size_t c = 0; c < cf_names.size(); ++c) {
for (int d = 0; d < kNumDBs; ++d) {
ASSERT_EQ(listener->flushed_dbs_[pos], dbs[d]);
ASSERT_EQ(listener->flushed_dbs_[pos], dbs[d].get());
ASSERT_EQ(listener->flushed_column_family_names_[pos], cf_names[c]);
pos++;
}
@@ -481,8 +480,8 @@ TEST_F(EventListenerTest, MultiDBMultiListeners) {
}
vec_handles.clear();
for (auto db : dbs) {
delete db;
for (auto& db : dbs) {
db.reset();
}
}
+6 -6
View File
@@ -98,7 +98,7 @@ class LogCompactionFilter : public CompactionFilter {
TEST_F(ManualCompactionTest, CompactTouchesAllKeys) {
for (int iter = 0; iter < 2; ++iter) {
DB* db;
std::unique_ptr<DB> db;
Options options;
if (iter == 0) { // level compaction
options.num_levels = 3;
@@ -128,7 +128,7 @@ TEST_F(ManualCompactionTest, CompactTouchesAllKeys) {
delete itr;
delete options.compaction_filter;
delete db;
db.reset();
ASSERT_OK(DestroyDB(dbname_, options));
}
}
@@ -137,7 +137,7 @@ TEST_F(ManualCompactionTest, Test) {
// Open database. Disable compression since it affects the creation
// of layers and the code below is trying to test against a very
// specific scenario.
DB* db;
std::unique_ptr<DB> db;
Options db_options;
db_options.write_buffer_size = 1024;
db_options.create_if_missing = true;
@@ -185,12 +185,12 @@ TEST_F(ManualCompactionTest, Test) {
ASSERT_EQ(kNumKeys, num_keys) << "Bad number of keys";
// close database
delete db;
db.reset();
ASSERT_OK(DestroyDB(dbname_, Options()));
}
TEST_F(ManualCompactionTest, SkipLevel) {
DB* db;
std::unique_ptr<DB> db;
Options options;
options.level_compaction_dynamic_level_bytes = false;
options.num_levels = 3;
@@ -298,7 +298,7 @@ TEST_F(ManualCompactionTest, SkipLevel) {
}
delete filter;
delete db;
db.reset();
ASSERT_OK(DestroyDB(dbname_, options));
}
+3 -4
View File
@@ -33,12 +33,12 @@ std::string ValueWithWriteTime(std::string value, uint64_t write_time) {
class MemTableListTest : public testing::Test {
public:
std::string dbname;
DB* db;
std::unique_ptr<DB> db;
Options options;
std::vector<ColumnFamilyHandle*> handles;
std::atomic<uint64_t> file_number;
MemTableListTest() : db(nullptr), file_number(1) {
MemTableListTest() : file_number(1) {
dbname = test::PerThreadDBPath("memtable_list_test");
options.create_if_missing = true;
EXPECT_OK(DestroyDB(dbname, options));
@@ -88,8 +88,7 @@ class MemTableListTest : public testing::Test {
}
}
handles.clear();
delete db;
db = nullptr;
db.reset();
EXPECT_OK(DestroyDB(dbname, options, cf_descs));
}
}
+37 -35
View File
@@ -19,6 +19,7 @@
#include "rocksdb/utilities/db_ttl.h"
#include "rocksdb/wide_columns.h"
#include "test_util/testharness.h"
#include "util/cast_util.h"
#include "util/coding.h"
#include "utilities/merge_operators.h"
@@ -96,9 +97,9 @@ class EnvMergeTest : public EnvWrapper {
uint64_t EnvMergeTest::now_nanos_count_{0};
std::unique_ptr<EnvMergeTest> EnvMergeTest::singleton_;
std::shared_ptr<DB> OpenDb(const std::string& dbname, const bool ttl = false,
std::unique_ptr<DB> OpenDb(const std::string& dbname, const bool ttl = false,
const size_t max_successive_merges = 0) {
DB* db;
std::unique_ptr<DB> db;
Options options;
options.create_if_missing = true;
options.merge_operator = std::make_shared<CountMergeOperator>();
@@ -109,7 +110,7 @@ std::shared_ptr<DB> OpenDb(const std::string& dbname, const bool ttl = false,
if (ttl) {
DBWithTTL* db_with_ttl;
s = DBWithTTL::Open(options, dbname, &db_with_ttl);
db = db_with_ttl;
db.reset(db_with_ttl);
} else {
s = DB::Open(options, dbname, &db);
}
@@ -118,7 +119,7 @@ std::shared_ptr<DB> OpenDb(const std::string& dbname, const bool ttl = false,
// Allowed to call NowNanos during DB creation (in GenerateRawUniqueId() for
// session ID)
EnvMergeTest::now_nanos_count_ = 0;
return std::shared_ptr<DB>(db);
return db;
}
// Imagine we are maintaining a set of uint64 counters.
@@ -128,7 +129,7 @@ std::shared_ptr<DB> OpenDb(const std::string& dbname, const bool ttl = false,
// This is a quick implementation without a Merge operation.
class Counters {
protected:
std::shared_ptr<DB> db_;
UnownedPtr<DB> db_;
WriteOptions put_option_;
ReadOptions get_option_;
@@ -137,7 +138,7 @@ class Counters {
uint64_t default_;
public:
explicit Counters(std::shared_ptr<DB> db, uint64_t defaultCount = 0)
explicit Counters(UnownedPtr<DB> db, uint64_t defaultCount = 0)
: db_(db),
put_option_(),
get_option_(),
@@ -242,7 +243,7 @@ class MergeBasedCounters : public Counters {
WriteOptions merge_option_; // for merge
public:
explicit MergeBasedCounters(std::shared_ptr<DB> db, uint64_t defaultCount = 0)
explicit MergeBasedCounters(UnownedPtr<DB> db, uint64_t defaultCount = 0)
: Counters(db, defaultCount), merge_option_() {}
// mapped to a rocksdb Merge operation
@@ -261,7 +262,7 @@ class MergeBasedCounters : public Counters {
}
};
void dumpDb(DB* db) {
void dumpDb(const std::unique_ptr<DB>& db) {
auto it = std::unique_ptr<Iterator>(db->NewIterator(ReadOptions()));
for (it->SeekToFirst(); it->Valid(); it->Next()) {
// uint64_t value = DecodeFixed64(it->value().data());
@@ -270,7 +271,8 @@ void dumpDb(DB* db) {
assert(it->status().ok()); // Check for any errors found during the scan
}
void testCounters(Counters& counters, DB* db, bool test_compaction) {
void testCounters(Counters& counters, const std::unique_ptr<DB>& db,
bool test_compaction) {
FlushOptions o;
o.wait = true;
@@ -320,7 +322,8 @@ void testCounters(Counters& counters, DB* db, bool test_compaction) {
}
}
void testCountersWithFlushAndCompaction(Counters& counters, DB* db) {
void testCountersWithFlushAndCompaction(Counters& counters,
const std::unique_ptr<DB>& db) {
ASSERT_OK(db->Put({}, "1", "1"));
ASSERT_OK(db->Flush(FlushOptions()));
@@ -388,12 +391,12 @@ void testCountersWithFlushAndCompaction(Counters& counters, DB* db) {
SyncPoint::GetInstance()->EnableProcessing();
port::Thread set_options_thread([&]() {
ASSERT_OK(static_cast<DBImpl*>(db)->SetOptions(
ASSERT_OK(static_cast_with_check<DBImpl>(db.get())->SetOptions(
{{"disable_auto_compactions", "false"}}));
});
TEST_SYNC_POINT("testCountersWithCompactionAndFlush:BeforeCompact");
port::Thread compact_thread([&]() {
ASSERT_OK(static_cast<DBImpl*>(db)->CompactRange(
ASSERT_OK(static_cast_with_check<DBImpl>(db.get())->CompactRange(
CompactRangeOptions(), db->DefaultColumnFamily(), nullptr, nullptr));
});
@@ -440,8 +443,8 @@ void testSuccessiveMerge(Counters& counters, size_t max_num_merges,
}
}
void testPartialMerge(Counters* counters, DB* db, size_t max_merge,
size_t min_merge, size_t count) {
void testPartialMerge(Counters* counters, const std::unique_ptr<DB>& db,
size_t max_merge, size_t min_merge, size_t count) {
FlushOptions o;
o.wait = true;
@@ -481,8 +484,8 @@ void testPartialMerge(Counters* counters, DB* db, size_t max_merge,
ASSERT_EQ(EnvMergeTest::now_nanos_count_, 0U);
}
void testSingleBatchSuccessiveMerge(DB* db, size_t max_num_merges,
size_t num_merges) {
void testSingleBatchSuccessiveMerge(const std::unique_ptr<DB>& db,
size_t max_num_merges, size_t num_merges) {
ASSERT_GT(num_merges, max_num_merges);
Slice key("BatchSuccessiveMerge");
@@ -520,13 +523,13 @@ void runTest(const std::string& dbname, const bool use_ttl = false) {
auto db = OpenDb(dbname, use_ttl);
{
Counters counters(db, 0);
testCounters(counters, db.get(), true);
Counters counters(db.get(), 0);
testCounters(counters, db, true);
}
{
MergeBasedCounters counters(db, 0);
testCounters(counters, db.get(), use_compression);
MergeBasedCounters counters(db.get(), 0);
testCounters(counters, db, use_compression);
}
}
@@ -535,10 +538,10 @@ void runTest(const std::string& dbname, const bool use_ttl = false) {
{
size_t max_merge = 5;
auto db = OpenDb(dbname, use_ttl, max_merge);
MergeBasedCounters counters(db, 0);
testCounters(counters, db.get(), use_compression);
MergeBasedCounters counters(db.get(), 0);
testCounters(counters, db, use_compression);
testSuccessiveMerge(counters, max_merge, max_merge * 2);
testSingleBatchSuccessiveMerge(db.get(), 5, 7);
testSingleBatchSuccessiveMerge(db, 5, 7);
ASSERT_OK(db->Close());
ASSERT_OK(DestroyDB(dbname, Options()));
}
@@ -549,16 +552,15 @@ void runTest(const std::string& dbname, const bool use_ttl = false) {
uint32_t min_merge = 2;
for (uint32_t count = min_merge - 1; count <= min_merge + 1; count++) {
auto db = OpenDb(dbname, use_ttl, max_merge);
MergeBasedCounters counters(db, 0);
testPartialMerge(&counters, db.get(), max_merge, min_merge, count);
MergeBasedCounters counters(db.get(), 0);
testPartialMerge(&counters, db, max_merge, min_merge, count);
ASSERT_OK(db->Close());
ASSERT_OK(DestroyDB(dbname, Options()));
}
{
auto db = OpenDb(dbname, use_ttl, max_merge);
MergeBasedCounters counters(db, 0);
testPartialMerge(&counters, db.get(), max_merge, min_merge,
min_merge * 10);
MergeBasedCounters counters(db.get(), 0);
testPartialMerge(&counters, db, max_merge, min_merge, min_merge * 10);
ASSERT_OK(db->Close());
ASSERT_OK(DestroyDB(dbname, Options()));
}
@@ -567,18 +569,18 @@ void runTest(const std::string& dbname, const bool use_ttl = false) {
{
{
auto db = OpenDb(dbname);
MergeBasedCounters counters(db, 0);
MergeBasedCounters counters(db.get(), 0);
counters.add("test-key", 1);
counters.add("test-key", 1);
counters.add("test-key", 1);
ASSERT_OK(db->CompactRange(CompactRangeOptions(), nullptr, nullptr));
}
DB* reopen_db;
std::unique_ptr<DB> reopen_db;
ASSERT_OK(DB::Open(Options(), dbname, &reopen_db));
std::string value;
ASSERT_NOK(reopen_db->Get(ReadOptions(), "test-key", &value));
delete reopen_db;
reopen_db.reset();
ASSERT_OK(DestroyDB(dbname, Options()));
}
@@ -587,13 +589,13 @@ void runTest(const std::string& dbname, const bool use_ttl = false) {
std::cout << "Test merge-operator not set after reopen (recovery case)\n";
{
auto db = OpenDb(dbname);
MergeBasedCounters counters(db, 0);
MergeBasedCounters counters(db.get(), 0);
counters.add("test-key", 1);
counters.add("test-key", 1);
counters.add("test-key", 1);
}
DB* reopen_db;
std::unique_ptr<DB> reopen_db;
ASSERT_TRUE(DB::Open(Options(), dbname, &reopen_db).IsInvalidArgument());
}
*/
@@ -614,8 +616,8 @@ TEST_F(MergeTest, MergeWithCompactionAndFlush) {
{
auto db = OpenDb(dbname);
{
MergeBasedCounters counters(db, 0);
testCountersWithFlushAndCompaction(counters, db.get());
MergeBasedCounters counters(db.get(), 0);
testCountersWithFlushAndCompaction(counters, db);
}
}
ASSERT_OK(DestroyDB(dbname, Options()));
+2 -1
View File
@@ -309,7 +309,8 @@ TEST_F(ObsoleteFilesTest, GetSortedWalFilesHangsAfterNoopPurge) {
// Grab an iterator and flush to switch the super version. That way, when the
// iterator is destroyed, it will go through the purge path.
DB* db = db_; // Only using `db` makes it clear we only use DB-level APIs.
DB* db =
db_.get(); // Only using `db` makes it clear we only use DB-level APIs.
ASSERT_OK(db->Put(WriteOptions(), "key", "value"));
std::unique_ptr<Iterator> iter(db->NewIterator(ReadOptions()));
ASSERT_OK(db->Flush(FlushOptions()));
+4 -4
View File
@@ -66,16 +66,16 @@ TEST_F(OptionsFileTest, NumberOfOptionsFiles) {
opt.create_if_missing = true;
ASSERT_OK(DestroyDB(dbname_, opt));
std::unordered_set<std::string> filename_history;
DB* db;
std::unique_ptr<DB> db;
for (int i = 0; i < kReopenCount; ++i) {
ASSERT_OK(DB::Open(opt, dbname_, &db));
int num_options_files = 0;
UpdateOptionsFiles(db, &filename_history, &num_options_files);
UpdateOptionsFiles(db.get(), &filename_history, &num_options_files);
ASSERT_GT(num_options_files, 0);
ASSERT_LE(num_options_files, 2);
// Make sure we always keep the latest option files.
VerifyOptionsFileName(db, filename_history);
delete db;
VerifyOptionsFileName(db.get(), filename_history);
db.reset();
}
}
+9 -11
View File
@@ -38,8 +38,8 @@ const std::string kDbName =
namespace ROCKSDB_NAMESPACE {
std::shared_ptr<DB> OpenDb(bool read_only = false) {
DB* db;
std::unique_ptr<DB> OpenDb(bool read_only = false) {
std::unique_ptr<DB> db;
Options options;
options.create_if_missing = true;
options.max_open_files = -1;
@@ -61,7 +61,7 @@ std::shared_ptr<DB> OpenDb(bool read_only = false) {
s = DB::OpenForReadOnly(options, kDbName, &db);
}
EXPECT_OK(s);
return std::shared_ptr<DB>(db);
return db;
}
class PerfContextTest : public testing::Test {};
@@ -659,12 +659,11 @@ TEST_F(PerfContextTest, ToString) {
TEST_F(PerfContextTest, MergeOperatorTime) {
ASSERT_OK(DestroyDB(kDbName, Options()));
DB* db;
std::unique_ptr<DB> db;
Options options;
options.create_if_missing = true;
options.merge_operator = MergeOperators::CreateStringAppendOperator();
Status s = DB::Open(options, kDbName, &db);
EXPECT_OK(s);
EXPECT_OK(DB::Open(options, kDbName, &db));
std::string val;
ASSERT_OK(db->Merge(WriteOptions(), "k1", "val1"));
@@ -704,7 +703,7 @@ TEST_F(PerfContextTest, MergeOperatorTime) {
#endif
EXPECT_GT(get_perf_context()->merge_operator_time_nanos, 0);
delete db;
db.reset();
}
TEST_F(PerfContextTest, CopyAndMove) {
@@ -972,13 +971,12 @@ TEST_F(PerfContextTest, CPUTimer) {
TEST_F(PerfContextTest, MergeOperandCount) {
ASSERT_OK(DestroyDB(kDbName, Options()));
DB* db = nullptr;
Options options;
options.create_if_missing = true;
options.merge_operator = MergeOperators::CreateStringAppendOperator();
std::unique_ptr<DB> db;
ASSERT_OK(DB::Open(options, kDbName, &db));
std::unique_ptr<DB> db_guard(db);
constexpr size_t num_keys = 3;
const std::string key_prefix("key");
@@ -1007,7 +1005,7 @@ TEST_F(PerfContextTest, MergeOperandCount) {
for (size_t j = 0; j <= i; ++j) {
// Take a snapshot before each Merge so they are preserved and not
// collapsed during flush.
snapshots.emplace_back(db);
snapshots.emplace_back(db.get());
ASSERT_OK(db->Merge(WriteOptions(), keys[i], value + std::to_string(j)));
}
@@ -1124,7 +1122,7 @@ TEST_F(PerfContextTest, MergeOperandCount) {
TEST_F(PerfContextTest, WriteMemtableTimePerfLevel) {
// Write and check time
ASSERT_OK(DestroyDB(kDbName, Options()));
std::shared_ptr<DB> db = OpenDb();
auto db = OpenDb();
SetPerfLevel(PerfLevel::kEnableWait);
PerfContext* perf_ctx = get_perf_context();
+6 -6
View File
@@ -157,13 +157,13 @@ TEST_F(PeriodicTaskSchedulerTest, MultiInstances) {
[&](void*) { pst_st_counter++; });
SyncPoint::GetInstance()->EnableProcessing();
auto dbs = std::vector<DB*>(kInstanceNum);
auto dbs = std::vector<std::unique_ptr<DB>>(kInstanceNum);
for (int i = 0; i < kInstanceNum; i++) {
ASSERT_OK(
DB::Open(options, test::PerThreadDBPath(std::to_string(i)), &(dbs[i])));
}
auto dbi = static_cast_with_check<DBImpl>(dbs[kInstanceNum - 1]);
auto dbi = static_cast_with_check<DBImpl>(dbs[kInstanceNum - 1].get());
const PeriodicTaskScheduler& scheduler = dbi->TEST_GetPeriodicTaskScheduler();
// kRecordSeqnoTime is not registered since the feature is not enabled
@@ -190,7 +190,7 @@ TEST_F(PeriodicTaskSchedulerTest, MultiInstances) {
int half = kInstanceNum / 2;
for (int i = 0; i < half; i++) {
delete dbs[i];
dbs[i].reset();
}
expected_run += (kInstanceNum - half) * 2;
@@ -204,7 +204,7 @@ TEST_F(PeriodicTaskSchedulerTest, MultiInstances) {
for (int i = half; i < kInstanceNum; i++) {
ASSERT_OK(dbs[i]->Close());
delete dbs[i];
dbs[i].reset();
}
}
@@ -229,11 +229,11 @@ TEST_F(PeriodicTaskSchedulerTest, MultiEnv) {
options1.env = mock_env2.get();
std::string dbname = test::PerThreadDBPath("multi_env_test");
DB* db;
std::unique_ptr<DB> db;
ASSERT_OK(DB::Open(options2, dbname, &db));
ASSERT_OK(db->Close());
delete db;
db.reset();
Close();
}
+10 -17
View File
@@ -98,7 +98,7 @@ class PlainTableDBTest : public testing::Test,
private:
std::string dbname_;
Env* env_;
DB* db_;
std::unique_ptr<DB> db_;
bool mmap_mode_;
Options last_options_;
@@ -107,7 +107,7 @@ class PlainTableDBTest : public testing::Test,
PlainTableDBTest() : env_(Env::Default()) {}
~PlainTableDBTest() override {
delete db_;
db_.reset();
EXPECT_OK(DestroyDB(dbname_, Options()));
}
@@ -115,7 +115,7 @@ class PlainTableDBTest : public testing::Test,
mmap_mode_ = GetParam();
dbname_ = test::PerThreadDBPath("plain_table_db_test");
EXPECT_OK(DestroyDB(dbname_, Options()));
db_ = nullptr;
db_.reset();
Reopen();
}
@@ -144,14 +144,11 @@ class PlainTableDBTest : public testing::Test,
return options;
}
DBImpl* dbfull() { return static_cast_with_check<DBImpl>(db_); }
DBImpl* dbfull() { return static_cast_with_check<DBImpl>(db_.get()); }
void Reopen(Options* options = nullptr) { ASSERT_OK(TryReopen(options)); }
void Close() {
delete db_;
db_ = nullptr;
}
void Close() { db_.reset(); }
bool mmap_mode() const { return mmap_mode_; }
@@ -162,24 +159,21 @@ class PlainTableDBTest : public testing::Test,
}
void Destroy(Options* options) {
delete db_;
db_ = nullptr;
db_.reset();
ASSERT_OK(DestroyDB(dbname_, *options));
}
Status PureReopen(Options* options, DB** db) {
Status PureReopen(Options* options, std::unique_ptr<DB>* db) {
return DB::Open(*options, dbname_, db);
}
Status ReopenForReadOnly(Options* options) {
delete db_;
db_ = nullptr;
db_.reset();
return DB::OpenForReadOnly(*options, dbname_, &db_);
}
Status TryReopen(Options* options = nullptr) {
delete db_;
db_ = nullptr;
db_.reset();
Options opts;
if (options != nullptr) {
opts = *options;
@@ -495,8 +489,7 @@ TEST_P(PlainTableDBTest, Flush) {
ASSERT_GT(int_num, 0U);
TablePropertiesCollection ptc;
ASSERT_OK(
static_cast<DB*>(dbfull())->GetPropertiesOfAllTables(&ptc));
ASSERT_OK(dbfull()->GetPropertiesOfAllTables(&ptc));
ASSERT_EQ(1U, ptc.size());
auto row = ptc.begin();
auto tp = row->second;
+6 -6
View File
@@ -229,8 +229,8 @@ class SamePrefixTransform : public SliceTransform {
class PrefixTest : public testing::Test {
public:
std::shared_ptr<DB> OpenDb() {
DB* db;
std::unique_ptr<DB> OpenDb() {
std::unique_ptr<DB> db;
options.create_if_missing = true;
options.write_buffer_size = FLAGS_write_buffer_size;
@@ -251,7 +251,7 @@ class PrefixTest : public testing::Test {
Status s = DB::Open(options, kDbName, &db);
EXPECT_OK(s);
return std::shared_ptr<DB>(db);
return db;
}
void FirstOption() { option_config_ = kBegin; }
@@ -304,7 +304,7 @@ class PrefixTest : public testing::Test {
};
TEST(SamePrefixTest, InDomainTest) {
DB* db;
std::unique_ptr<DB> db;
Options options;
options.create_if_missing = true;
options.prefix_extractor.reset(new SamePrefixTransform("HHKB"));
@@ -331,7 +331,7 @@ TEST(SamePrefixTest, InDomainTest) {
ASSERT_EQ(db_iter->value(), "idk");
delete db_iter;
delete db;
db.reset();
ASSERT_OK(DestroyDB(kDbName, Options()));
}
@@ -348,7 +348,7 @@ TEST(SamePrefixTest, InDomainTest) {
ASSERT_TRUE(db_iter->Valid());
ASSERT_OK(db_iter->status());
delete db_iter;
delete db;
db.reset();
ASSERT_OK(DestroyDB(kDbName, Options()));
}
}
+5 -5
View File
@@ -661,14 +661,14 @@ TEST_P(SeqnoTimeTablePropTest, MultiInstancesBasic) {
options.stats_dump_period_sec = 0;
options.stats_persist_period_sec = 0;
auto dbs = std::vector<DB*>(kInstanceNum);
auto dbs = std::vector<std::unique_ptr<DB>>(kInstanceNum);
for (int i = 0; i < kInstanceNum; i++) {
ASSERT_OK(
DB::Open(options, test::PerThreadDBPath(std::to_string(i)), &(dbs[i])));
}
// Make sure the second instance has the worker enabled
auto dbi = static_cast_with_check<DBImpl>(dbs[1]);
auto dbi = static_cast_with_check<DBImpl>(dbs[1].get());
WriteOptions wo;
for (int i = 0; i < 200; i++) {
ASSERT_OK(dbi->Put(wo, Key(i), "value"));
@@ -680,7 +680,7 @@ TEST_P(SeqnoTimeTablePropTest, MultiInstancesBasic) {
for (int i = 0; i < kInstanceNum; i++) {
ASSERT_OK(dbs[i]->Close());
delete dbs[i];
dbs[i].reset();
}
}
@@ -792,8 +792,8 @@ TEST_P(SeqnoTimeTablePropTest, SeqnoToTimeMappingUniversal) {
}
ASSERT_GT(num_seqno_zeroing, 0);
std::vector<KeyVersion> key_versions;
ASSERT_OK(GetAllKeyVersions(db_, {}, {}, std::numeric_limits<size_t>::max(),
&key_versions));
ASSERT_OK(GetAllKeyVersions(
db_.get(), {}, {}, std::numeric_limits<size_t>::max(), &key_versions));
// make sure there're more than 300 keys and first 100 keys are having seqno
// zeroed out, the last 100 key seqno not zeroed out
ASSERT_GT(key_versions.size(), 300);
+5 -5
View File
@@ -714,7 +714,7 @@ TEST_F(DBWideBasicTest, MergePlainKeyValue) {
// snapshot in between to make sure they do not get reconciled during the
// subsequent flush)
write_base();
ManagedSnapshot snapshot(db_);
ManagedSnapshot snapshot(db_.get());
write_merge();
verify();
@@ -958,7 +958,7 @@ TEST_F(DBWideBasicTest, MergeEntity) {
// between to make sure they do not get reconciled during the subsequent
// flush)
write_base();
ManagedSnapshot snapshot(db_);
ManagedSnapshot snapshot(db_.get());
write_merge();
verify_basic();
verify_merge_ops_pre_compaction();
@@ -1033,7 +1033,7 @@ class DBWideMergeV3Test : public DBWideBasicTest {
third_key,
third_columns)); // wide-column base value
snapshots_.emplace_back(db_);
snapshots_.emplace_back(db_.get());
// First round of merge operands
ASSERT_OK(db_->Merge(WriteOptions(), db_->DefaultColumnFamily(), first_key,
@@ -1043,7 +1043,7 @@ class DBWideMergeV3Test : public DBWideBasicTest {
ASSERT_OK(db_->Merge(WriteOptions(), db_->DefaultColumnFamily(), third_key,
third_merge_op1));
snapshots_.emplace_back(db_);
snapshots_.emplace_back(db_.get());
// Second round of merge operands
ASSERT_OK(db_->Merge(WriteOptions(), db_->DefaultColumnFamily(), first_key,
@@ -1053,7 +1053,7 @@ class DBWideMergeV3Test : public DBWideBasicTest {
ASSERT_OK(db_->Merge(WriteOptions(), db_->DefaultColumnFamily(), third_key,
third_merge_op2));
snapshots_.emplace_back(db_);
snapshots_.emplace_back(db_.get());
}
void VerifyKeyValues(const WideColumns& first_expected,
+3 -3
View File
@@ -419,7 +419,7 @@ TEST_F(WriteCallbackTest, WriteCallBackTest) {
WriteOptions write_options;
ReadOptions read_options;
string value;
DB* db;
std::unique_ptr<DB> db;
DBImpl* db_impl;
ASSERT_OK(DestroyDB(dbname, options));
@@ -428,7 +428,7 @@ TEST_F(WriteCallbackTest, WriteCallBackTest) {
Status s = DB::Open(options, dbname, &db);
ASSERT_OK(s);
db_impl = dynamic_cast<DBImpl*>(db);
db_impl = dynamic_cast<DBImpl*>(db.get());
ASSERT_TRUE(db_impl);
WriteBatch wb;
@@ -481,7 +481,7 @@ TEST_F(WriteCallbackTest, WriteCallBackTest) {
ASSERT_TRUE(user_write_cb.write_enqueued_.load());
ASSERT_TRUE(user_write_cb.wal_write_done_.load());
delete db;
db.reset();
ASSERT_OK(DestroyDB(dbname, options));
}
+1 -1
View File
@@ -1047,7 +1047,7 @@ class CfConsistencyStressTest : public StressTest {
assert(thread);
Status status;
DB* db_ptr = secondary_db_ ? secondary_db_ : db_;
DB* db_ptr = secondary_db_ ? secondary_db_.get() : db_;
const auto& cfhs = secondary_db_ ? secondary_cfhs_ : column_families_;
// Take a snapshot to preserve the state of primary db.
+22 -21
View File
@@ -74,7 +74,6 @@ StressTest::StressTest()
new_column_family_name_(1),
num_times_reopened_(0),
db_preload_finished_(false),
secondary_db_(nullptr),
is_db_stopped_(false) {
if (FLAGS_destroy_db_initially) {
const Status s = DbStressDestroyDb(FLAGS_db);
@@ -98,11 +97,10 @@ void StressTest::CleanUp() {
if (db_) {
db_->Close();
}
delete db_;
db_owner_.reset();
db_ = nullptr;
delete secondary_db_;
secondary_db_ = nullptr;
secondary_db_.reset();
}
void StressTest::CleanUpColumnFamilies() {
@@ -753,12 +751,11 @@ void StressTest::PreloadDbAndReopenAsReadOnly(int64_t number_of_keys,
}
if (s.ok()) {
CleanUpColumnFamilies();
delete db_;
db_owner_.reset();
db_ = nullptr;
txn_db_ = nullptr;
optimistic_txn_db_ = nullptr;
delete secondary_db_;
secondary_db_ = nullptr;
secondary_db_.reset();
db_preload_finished_.store(true);
auto now = clock_->NowMicros();
@@ -2506,7 +2503,7 @@ Status StressTest::TestBackupRestore(
from = "BackupEngine::PurgeOldBackups";
}
}
DB* restored_db = nullptr;
std::unique_ptr<DB> restored_db;
std::vector<ColumnFamilyHandle*> restored_cf_handles;
// Not yet implemented: opening restored BlobDB or TransactionDB
@@ -2594,8 +2591,7 @@ Status StressTest::TestBackupRestore(
for (auto* cf_handle : restored_cf_handles) {
restored_db->DestroyColumnFamilyHandle(cf_handle);
}
delete restored_db;
restored_db = nullptr;
restored_db.reset();
}
if (s.ok() && inplace_not_restore) {
// Purge late if inplace open read-only
@@ -2830,7 +2826,7 @@ Status StressTest::TestCheckpoint(ThreadState* thread,
delete checkpoint;
checkpoint = nullptr;
std::vector<ColumnFamilyHandle*> cf_handles;
DB* checkpoint_db = nullptr;
std::unique_ptr<DB> checkpoint_db;
if (s.ok()) {
Options options(options_);
options.best_efforts_recovery = false;
@@ -2894,8 +2890,7 @@ Status StressTest::TestCheckpoint(ThreadState* thread,
delete cfh;
}
cf_handles.clear();
delete checkpoint_db;
checkpoint_db = nullptr;
checkpoint_db.reset();
}
// Temporarily disable error injection for clean-up
@@ -3871,15 +3866,20 @@ void StressTest::Open(SharedState* shared, bool reopen) {
cf_descriptors, &column_families_,
&blob_db);
if (s.ok()) {
db_owner_.reset(blob_db);
db_ = blob_db;
}
} else {
if (db_preload_finished_.load() && FLAGS_read_only) {
s = DB::OpenForReadOnly(DBOptions(options_), FLAGS_db,
cf_descriptors, &column_families_, &db_);
cf_descriptors, &column_families_,
&db_owner_);
} else {
s = DB::Open(DBOptions(options_), FLAGS_db, cf_descriptors,
&column_families_, &db_);
&column_families_, &db_owner_);
}
if (s.ok()) {
db_ = db_owner_.get();
}
}
@@ -3895,10 +3895,9 @@ void StressTest::Open(SharedState* shared, bool reopen) {
s = db_->GetRootDB()->WaitForCompact(WaitForCompactOptions());
if (!s.ok()) {
CleanUpColumnFamilies();
delete db_;
db_owner_.reset();
db_ = nullptr;
delete secondary_db_;
secondary_db_ = nullptr;
secondary_db_.reset();
}
}
if (!s.ok()) {
@@ -3955,6 +3954,7 @@ void StressTest::Open(SharedState* shared, bool reopen) {
}
assert(s.ok());
{
db_owner_.reset(optimistic_txn_db_);
db_ = optimistic_txn_db_;
db_aptr_.store(optimistic_txn_db_, std::memory_order_release);
}
@@ -3990,6 +3990,7 @@ void StressTest::Open(SharedState* shared, bool reopen) {
// Do not swap the order of the following.
{
db_owner_.reset(txn_db_);
db_ = txn_db_;
db_aptr_.store(txn_db_, std::memory_order_release);
}
@@ -4028,6 +4029,7 @@ void StressTest::Open(SharedState* shared, bool reopen) {
} else {
DBWithTTL* db_with_ttl;
s = DBWithTTL::Open(options_, FLAGS_db, &db_with_ttl, FLAGS_ttl);
db_owner_.reset(db_with_ttl);
db_ = db_with_ttl;
}
@@ -4107,12 +4109,11 @@ void StressTest::Reopen(ThreadState* thread) {
}
assert((txn_db_ == nullptr && optimistic_txn_db_ == nullptr) ||
(db_ == txn_db_ || db_ == optimistic_txn_db_));
delete db_;
db_owner_.reset();
db_ = nullptr;
txn_db_ = nullptr;
optimistic_txn_db_ = nullptr;
delete secondary_db_;
secondary_db_ = nullptr;
secondary_db_.reset();
num_times_reopened_++;
auto now = clock_->NowMicros();
+2 -1
View File
@@ -404,6 +404,7 @@ class StressTest {
std::shared_ptr<Cache> cache_;
std::shared_ptr<Cache> compressed_cache_;
std::shared_ptr<const FilterPolicy> filter_policy_;
std::unique_ptr<DB> db_owner_;
DB* db_;
TransactionDB* txn_db_;
OptimisticTransactionDB* optimistic_txn_db_;
@@ -422,7 +423,7 @@ class StressTest {
std::atomic<bool> db_preload_finished_;
std::shared_ptr<SstQueryFilterConfigsManager::Factory> sqfc_factory_;
DB* secondary_db_;
std::unique_ptr<DB> secondary_db_;
std::vector<ColumnFamilyHandle*> secondary_cfhs_;
bool is_db_stopped_;
};
+3 -2
View File
@@ -234,8 +234,9 @@ class NonBatchedOpsStressTest : public StressTest {
Status s = secondary_db_->TryCatchUpWithPrimary();
#ifndef NDEBUG
uint64_t manifest_num = static_cast_with_check<DBImpl>(secondary_db_)
->TEST_Current_Manifest_FileNo();
uint64_t manifest_num =
static_cast_with_check<DBImpl>(secondary_db_.get())
->TEST_Current_Manifest_FileNo();
#else
uint64_t manifest_num = 0;
#endif
+2 -2
View File
@@ -2508,7 +2508,7 @@ TEST_P(EnvFSTestWithParam, OptionsTest) {
}
}
for (int i = 0; i < 2; ++i) {
DB* db;
std::unique_ptr<DB> db;
Status s = DB::Open(opts, dbname, &db);
ASSERT_OK(s);
@@ -2526,7 +2526,7 @@ TEST_P(EnvFSTestWithParam, OptionsTest) {
ASSERT_EQ("b", val);
ASSERT_OK(db->Close());
delete db;
db.reset();
ASSERT_OK(DestroyDB(dbname, opts));
dbname = dbname2_;
+4 -3
View File
@@ -3,6 +3,7 @@
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
#include <cstdio>
#include <memory>
#include <string>
#include <vector>
@@ -32,7 +33,7 @@ int main() {
// open DB
Options options;
options.create_if_missing = true;
DB* db;
std::unique_ptr<DB> db;
Status s = DB::Open(options, kDBPath, &db);
assert(s.ok());
@@ -44,7 +45,7 @@ int main() {
// close DB
s = db->DestroyColumnFamilyHandle(cf);
assert(s.ok());
delete db;
db.reset();
// open DB with two column families
std::vector<ColumnFamilyDescriptor> column_families;
@@ -82,7 +83,7 @@ int main() {
s = db->DestroyColumnFamilyHandle(handle);
assert(s.ok());
}
delete db;
db.reset();
return 0;
}
+7 -4
View File
@@ -6,6 +6,7 @@
// An example code demonstrating how to use CompactFiles, EventListener,
// and GetColumnFamilyMetaData APIs to implement custom compaction algorithm.
#include <memory>
#include <mutex>
#include <string>
@@ -151,10 +152,12 @@ int main() {
options.IncreaseParallelism(5);
options.listeners.emplace_back(new FullCompactor(options));
DB* db = nullptr;
std::unique_ptr<DB> db;
ROCKSDB_NAMESPACE::DestroyDB(kDBPath, options);
Status s = DB::Open(options, kDBPath, &db);
assert(s.ok());
{
Status s = DB::Open(options, kDBPath, &db);
assert(s.ok());
}
assert(db);
// if background compaction is not working, write will stall
@@ -172,7 +175,7 @@ int main() {
}
// close the db.
delete db;
db.reset();
return 0;
}
+2 -3
View File
@@ -63,7 +63,7 @@ std::string kRemoveDirCommand = "rm -rf ";
#endif
int main() {
ROCKSDB_NAMESPACE::DB* raw_db;
std::unique_ptr<ROCKSDB_NAMESPACE::DB> db;
ROCKSDB_NAMESPACE::Status status;
MyFilter filter;
@@ -77,9 +77,8 @@ int main() {
options.create_if_missing = true;
options.merge_operator.reset(new MyMerge);
options.compaction_filter = &filter;
status = ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &raw_db);
status = ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &db);
assert(status.ok());
std::unique_ptr<ROCKSDB_NAMESPACE::DB> db(raw_db);
ROCKSDB_NAMESPACE::WriteOptions wopts;
db->Merge(wopts, "0", "bad"); // This is filtered out
+10 -11
View File
@@ -19,6 +19,7 @@
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <memory>
#include <string>
#include <thread>
#include <vector>
@@ -147,7 +148,7 @@ void CreateDB() {
assert(false);
}
options.create_if_missing = true;
DB* db = nullptr;
std::unique_ptr<DB> db;
s = DB::Open(options, kDBPath, &db);
if (!s.ok()) {
fprintf(stderr, "[process %ld] Failed to open DB: %s\n", my_pid,
@@ -173,7 +174,7 @@ void CreateDB() {
delete h;
}
handles.clear();
delete db;
db.reset();
}
void RunPrimary() {
@@ -181,7 +182,7 @@ void RunPrimary() {
fprintf(stdout, "[process %ld] Primary instance starts\n", my_pid);
CreateDB();
std::srand(time(nullptr));
DB* db = nullptr;
std::unique_ptr<DB> db;
Options options;
options.create_if_missing = false;
std::vector<ColumnFamilyDescriptor> column_families;
@@ -227,8 +228,7 @@ void RunPrimary() {
delete h;
}
handles.clear();
delete db;
db = nullptr;
db.reset();
}
}
if (nullptr != db) {
@@ -236,8 +236,7 @@ void RunPrimary() {
delete h;
}
handles.clear();
delete db;
db = nullptr;
db.reset();
}
fprintf(stdout, "[process %ld] Finished adding keys\n", my_pid);
}
@@ -262,7 +261,7 @@ void RunSecondary() {
exit(0);
}
}
DB* db = nullptr;
std::unique_ptr<DB> db;
Options options;
options.create_if_missing = false;
options.max_open_files = -1;
@@ -344,7 +343,7 @@ void RunSecondary() {
column_families.push_back(ColumnFamilyDescriptor(cf_name, options));
}
std::vector<ColumnFamilyHandle*> handles;
DB* verification_db = nullptr;
std::unique_ptr<DB> verification_db;
s = DB::OpenForReadOnly(options, kDBPath, column_families, &handles,
&verification_db);
assert(s.ok());
@@ -369,8 +368,8 @@ void RunSecondary() {
}
delete iter;
delete iter1;
delete db;
delete verification_db;
db.reset();
verification_db.reset();
}
int main(int argc, char** argv) {
+4 -3
View File
@@ -7,6 +7,7 @@
// rocksdb/utilities/options_util.h to open a rocksdb database without
// remembering all the rocksdb options.
#include <cstdio>
#include <memory>
#include <string>
#include <vector>
@@ -74,7 +75,7 @@ int main() {
cf_descs[1].options.table_factory.reset(NewBlockBasedTableFactory(bbt_opts));
// destroy and open DB
DB* db;
std::unique_ptr<DB> db;
Status s = ROCKSDB_NAMESPACE::DestroyDB(kDBPath,
Options(db_opt, cf_descs[0].options));
assert(s.ok());
@@ -88,7 +89,7 @@ int main() {
// close DB
delete cf;
delete db;
db.reset();
// In the following code, we will reopen the rocksdb instance using
// the options file stored in the db directory.
@@ -128,5 +129,5 @@ int main() {
for (auto* handle : handles) {
delete handle;
}
delete db;
db.reset();
}
+5 -6
View File
@@ -4,6 +4,7 @@
// (found in the LICENSE.Apache file in the root directory).
#include <cstdio>
#include <memory>
#include <string>
#include <vector>
@@ -29,7 +30,7 @@ std::string kDBPath = "/tmp/rocksdb_example";
#endif
int main() {
DB* db;
std::unique_ptr<DB> db;
Options options;
// Optimize RocksDB. This is the easiest way to get RocksDB to perform well
options.IncreaseParallelism();
@@ -52,7 +53,7 @@ int main() {
&backup_engine);
assert(s.ok());
backup_engine->CreateNewBackup(db);
backup_engine->CreateNewBackup(db.get());
assert(s.ok());
std::vector<BackupInfo> backup_info;
@@ -65,9 +66,7 @@ int main() {
db->Put(WriteOptions(), "key2", "value2");
assert(s.ok());
db->Close();
delete db;
db = nullptr;
db.reset();
// restore db to backup 1
BackupEngineReadOnly* backup_engine_ro;
@@ -93,7 +92,7 @@ int main() {
delete backup_engine;
delete backup_engine_ro;
delete db;
db.reset();
return 0;
}
+3 -2
View File
@@ -4,6 +4,7 @@
// (found in the LICENSE.Apache file in the root directory).
#include <cstdio>
#include <memory>
#include <string>
#include "rocksdb/db.h"
@@ -25,7 +26,7 @@ std::string kDBPath = "/tmp/rocksdb_simple_example";
#endif
int main() {
DB* db;
std::unique_ptr<DB> db;
Options options;
// Optimize RocksDB. This is the easiest way to get RocksDB to perform well
options.IncreaseParallelism();
@@ -87,7 +88,7 @@ int main() {
pinnable_val.Reset();
// The Slice pointed by pinnable_val is not valid after this point
delete db;
db.reset();
return 0;
}
+6 -6
View File
@@ -31,11 +31,11 @@ constexpr char db_path[] = "/tmp/testdb";
// enum. The goal is to capture sanitizer bugs, so the code should be
// compiled with a given sanitizer (ASan, UBSan, MSan).
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
ROCKSDB_NAMESPACE::DB* db;
std::unique_ptr<ROCKSDB_NAMESPACE::DB> db;
ROCKSDB_NAMESPACE::Options options;
ROCKSDB_NAMESPACE::Status status;
options.create_if_missing = true;
ROCKSDB_NAMESPACE::Status status =
ROCKSDB_NAMESPACE::DB::Open(options, db_path, &db);
status = ROCKSDB_NAMESPACE::DB::Open(options, db_path, &db);
if (!status.ok()) {
return 0;
}
@@ -88,7 +88,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
}
case kOpenClose: {
db->Close();
delete db;
db.reset();
status = ROCKSDB_NAMESPACE::DB::Open(options, db_path, &db);
if (!status.ok()) {
ROCKSDB_NAMESPACE::DestroyDB(db_path, options);
@@ -104,7 +104,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
"new_cf", &cf);
s = db->DestroyColumnFamilyHandle(cf);
db->Close();
delete db;
db.reset();
// open DB with two column families
std::vector<ROCKSDB_NAMESPACE::ColumnFamilyDescriptor> column_families;
@@ -166,7 +166,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// Cleanup DB
db->Close();
delete db;
db.reset();
ROCKSDB_NAMESPACE::DestroyDB(db_path, options);
return 0;
}
+3 -4
View File
@@ -50,7 +50,7 @@ DEFINE_PROTO_FUZZER(DBOperations& input) {
}
std::map<std::string, std::string> kv;
ROCKSDB_NAMESPACE::DB* db = nullptr;
std::unique_ptr<ROCKSDB_NAMESPACE::DB> db;
ROCKSDB_NAMESPACE::Options options;
options.create_if_missing = true;
CHECK_OK(ROCKSDB_NAMESPACE::DB::Open(options, kDbPath, &db));
@@ -86,8 +86,7 @@ DEFINE_PROTO_FUZZER(DBOperations& input) {
}
}
CHECK_OK(db->Close());
delete db;
db = nullptr;
db.reset();
CHECK_OK(ROCKSDB_NAMESPACE::DB::Open(options, kDbPath, &db));
auto kv_it = kv.begin();
@@ -102,6 +101,6 @@ DEFINE_PROTO_FUZZER(DBOperations& input) {
delete it;
CHECK_OK(db->Close());
delete db;
db.reset();
CHECK_OK(ROCKSDB_NAMESPACE::DestroyDB(kDbPath, options));
}
+7 -94
View File
@@ -131,24 +131,13 @@ using TablePropertiesCollection =
class DB {
public:
// Open the database with the specified "name" for reads and writes.
// Stores a pointer to a heap-allocated database in *dbptr and returns
// OK on success.
// Stores nullptr in *dbptr and returns a non-OK status on error, including
// On success, stores the database in *dbptr and returns OK.
// On error, resets *dbptr and returns a non-OK status, including
// if the DB is already open (read-write) by another DB object. (This
// guarantee depends on options.env->LockFile(), which might not provide
// this guarantee in a custom Env implementation.)
//
// Caller must delete *dbptr when it is no longer needed.
static Status Open(const Options& options, const std::string& name,
std::unique_ptr<DB>* dbptr);
// DEPRECATED: raw pointer variant
static Status Open(const Options& options, const std::string& name,
DB** dbptr) {
std::unique_ptr<DB> smart_ptr;
Status s = Open(options, name, &smart_ptr);
*dbptr = smart_ptr.release();
return s;
}
// Open DB with column families.
// db_options specify database specific options
@@ -162,21 +151,12 @@ class DB {
// If everything is OK, handles will on return be the same size
// as column_families --- handles[i] will be a handle that you
// will use to operate on column family column_family[i].
// Before delete DB, you have to close All column families by calling
// Before destroying the DB, you have to close all column families by calling
// DestroyColumnFamilyHandle() with all the handles.
static Status Open(const DBOptions& db_options, const std::string& name,
const std::vector<ColumnFamilyDescriptor>& column_families,
std::vector<ColumnFamilyHandle*>* handles,
std::unique_ptr<DB>* dbptr);
// DEPRECATED: raw pointer variant
static Status Open(const DBOptions& db_options, const std::string& name,
const std::vector<ColumnFamilyDescriptor>& column_families,
std::vector<ColumnFamilyHandle*>* handles, DB** dbptr) {
std::unique_ptr<DB> smart_ptr;
Status s = Open(db_options, name, column_families, handles, &smart_ptr);
*dbptr = smart_ptr.release();
return s;
}
// OpenForReadOnly() creates a Read-only instance that supports reads alone.
//
@@ -195,16 +175,6 @@ class DB {
static Status OpenForReadOnly(const Options& options, const std::string& name,
std::unique_ptr<DB>* dbptr,
bool error_if_wal_file_exists = false);
// DEPRECATED: raw pointer variant
static Status OpenForReadOnly(const Options& options, const std::string& name,
DB** dbptr,
bool error_if_wal_file_exists = false) {
std::unique_ptr<DB> smart_ptr;
Status s =
OpenForReadOnly(options, name, &smart_ptr, error_if_wal_file_exists);
*dbptr = smart_ptr.release();
return s;
}
// Open the database for read only with column families.
//
@@ -218,18 +188,6 @@ class DB {
const std::vector<ColumnFamilyDescriptor>& column_families,
std::vector<ColumnFamilyHandle*>* handles, std::unique_ptr<DB>* dbptr,
bool error_if_wal_file_exists = false);
// DEPRECATED: raw pointer variant
static Status OpenForReadOnly(
const DBOptions& db_options, const std::string& name,
const std::vector<ColumnFamilyDescriptor>& column_families,
std::vector<ColumnFamilyHandle*>* handles, DB** dbptr,
bool error_if_wal_file_exists = false) {
std::unique_ptr<DB> smart_ptr;
Status s = OpenForReadOnly(db_options, name, column_families, handles,
&smart_ptr, error_if_wal_file_exists);
*dbptr = smart_ptr.release();
return s;
}
// OpenAsSecondary() creates a secondary instance that supports read-only
// operations and supports dynamic catch up with the primary (through a
@@ -251,8 +209,6 @@ class DB {
// The secondary_path argument points to a directory where the secondary
// instance stores its info log.
// The dbptr is an out-arg corresponding to the opened secondary instance.
// The pointer points to a heap-allocated database, and the caller should
// delete it after use.
//
// Return OK on success, non-OK on failures.
//
@@ -265,14 +221,6 @@ class DB {
static Status OpenAsSecondary(const Options& options, const std::string& name,
const std::string& secondary_path,
std::unique_ptr<DB>* dbptr);
// DEPRECATED: raw pointer variant
static Status OpenAsSecondary(const Options& options, const std::string& name,
const std::string& secondary_path, DB** dbptr) {
std::unique_ptr<DB> smart_ptr;
Status s = OpenAsSecondary(options, name, secondary_path, &smart_ptr);
*dbptr = smart_ptr.release();
return s;
}
// Open DB as secondary instance with specified column families
//
@@ -301,9 +249,8 @@ class DB {
// The handles is an out-arg corresponding to the opened database column
// family handles.
// The dbptr is an out-arg corresponding to the opened secondary instance.
// The pointer points to a heap-allocated database, and the caller should
// delete it after use. Before deleting the dbptr, the user should also
// delete the pointers stored in handles vector.
// Before destroying the DB, the user should call
// DestroyColumnFamilyHandle() on all the handles.
//
// Return OK on success, non-OK on failures.
static Status OpenAsSecondary(
@@ -311,18 +258,6 @@ class DB {
const std::string& secondary_path,
const std::vector<ColumnFamilyDescriptor>& column_families,
std::vector<ColumnFamilyHandle*>* handles, std::unique_ptr<DB>* dbptr);
// DEPRECATED: raw pointer variant
static Status OpenAsSecondary(
const DBOptions& db_options, const std::string& name,
const std::string& secondary_path,
const std::vector<ColumnFamilyDescriptor>& column_families,
std::vector<ColumnFamilyHandle*>* handles, DB** dbptr) {
std::unique_ptr<DB> smart_ptr;
Status s = OpenAsSecondary(db_options, name, secondary_path,
column_families, handles, &smart_ptr);
*dbptr = smart_ptr.release();
return s;
}
// EXPERIMENTAL
@@ -389,18 +324,6 @@ class DB {
const std::vector<ColumnFamilyDescriptor>& column_families,
std::vector<ColumnFamilyHandle*>* handles, std::unique_ptr<DB>* dbptr,
std::string trim_ts);
// DEPRECATED: raw pointer variant
static Status OpenAndTrimHistory(
const DBOptions& db_options, const std::string& dbname,
const std::vector<ColumnFamilyDescriptor>& column_families,
std::vector<ColumnFamilyHandle*>* handles, DB** dbptr,
std::string trim_ts) {
std::unique_ptr<DB> smart_ptr;
Status s = OpenAndTrimHistory(db_options, dbname, column_families, handles,
&smart_ptr, trim_ts);
*dbptr = smart_ptr.release();
return s;
}
// Manually, synchronously attempt to resume DB writes after a write failure
// to the underlying filesystem. See
@@ -1063,7 +986,7 @@ class DB {
// call one of the Seek methods on the iterator before using it).
//
// Caller should delete the iterator when it is no longer needed.
// The returned iterator should be deleted before this db is deleted.
// The returned iterator should be deleted before this db is destroyed.
virtual Iterator* NewIterator(const ReadOptions& options,
ColumnFamilyHandle* column_family) = 0;
virtual Iterator* NewIterator(const ReadOptions& options) {
@@ -1071,7 +994,7 @@ class DB {
}
// Returns iterators from a consistent database state across multiple
// column families. Iterators are heap allocated and need to be deleted
// before the db is deleted
// before the db is destroyed
virtual Status NewIterators(
const ReadOptions& options,
const std::vector<ColumnFamilyHandle*>& column_families,
@@ -1791,16 +1714,6 @@ class DB {
virtual int NumberLevels(ColumnFamilyHandle* column_family) = 0;
virtual int NumberLevels() { return NumberLevels(DefaultColumnFamily()); }
// DEPRECATED:
// Maximum level to which a new compacted memtable is pushed if it
// does not create overlap.
virtual int MaxMemCompactionLevel(ColumnFamilyHandle* /*column_family*/) {
return 0;
}
virtual int MaxMemCompactionLevel() {
return MaxMemCompactionLevel(DefaultColumnFamily());
}
// Number of files in level-0 that would stop writes.
virtual int Level0StopWriteTrigger(ColumnFamilyHandle* column_family) = 0;
virtual int Level0StopWriteTrigger() {
+16 -10
View File
@@ -30,18 +30,21 @@ class ToolHooks {
ToolHooks() = default;
virtual ~ToolHooks() = default;
virtual Status Open(const Options& db_options, const std::string& name,
DB** dbptr) = 0;
std::unique_ptr<DB>* dbptr) = 0;
virtual Status Open(
const DBOptions& db_options, const std::string& name,
const std::vector<ColumnFamilyDescriptor>& column_families,
std::vector<ColumnFamilyHandle*>* handles, DB** dbptr) = 0;
std::vector<ColumnFamilyHandle*>* handles,
std::unique_ptr<DB>* dbptr) = 0;
virtual Status OpenForReadOnly(const Options& options,
const std::string& name, DB** dbptr,
const std::string& name,
std::unique_ptr<DB>* dbptr,
bool error_if_wal_file_exists) = 0;
virtual Status OpenForReadOnly(
const Options& options, const std::string& name,
const std::vector<ColumnFamilyDescriptor>& column_families,
std::vector<ColumnFamilyHandle*>* handles, DB** dbptr) = 0;
std::vector<ColumnFamilyHandle*>* handles,
std::unique_ptr<DB>* dbptr) = 0;
virtual Status OpenTransactionDB(const Options& db_options,
const TransactionDBOptions& txn_db_options,
const std::string& dbname,
@@ -62,7 +65,7 @@ class ToolHooks {
virtual Status OpenAsSecondary(const Options& options,
const std::string& name,
const std::string& secondary_path,
DB** dbptr) = 0;
std::unique_ptr<DB>* dbptr) = 0;
virtual Status OpenAsFollower(const Options& options, const std::string& name,
const std::string& leader_path,
std::unique_ptr<DB>* dbptr) = 0;
@@ -77,18 +80,21 @@ class DefaultHooks : public ToolHooks {
DefaultHooks() = default;
~DefaultHooks() override = default;
virtual Status Open(const Options& db_options, const std::string& name,
DB** dbptr) override;
std::unique_ptr<DB>* dbptr) override;
virtual Status Open(
const DBOptions& db_options, const std::string& name,
const std::vector<ColumnFamilyDescriptor>& column_families,
std::vector<ColumnFamilyHandle*>* handles, DB** dbptr) override;
std::vector<ColumnFamilyHandle*>* handles,
std::unique_ptr<DB>* dbptr) override;
virtual Status OpenForReadOnly(const Options& options,
const std::string& name, DB** dbptr,
const std::string& name,
std::unique_ptr<DB>* dbptr,
bool error_if_wal_file_exists) override;
virtual Status OpenForReadOnly(
const Options& options, const std::string& name,
const std::vector<ColumnFamilyDescriptor>& column_families,
std::vector<ColumnFamilyHandle*>* handles, DB** dbptr) override;
std::vector<ColumnFamilyHandle*>* handles,
std::unique_ptr<DB>* dbptr) override;
virtual Status OpenTransactionDB(const Options& db_options,
const TransactionDBOptions& txn_db_options,
const std::string& dbname,
@@ -110,7 +116,7 @@ class DefaultHooks : public ToolHooks {
virtual Status OpenAsSecondary(const Options& options,
const std::string& name,
const std::string& secondary_path,
DB** dbptr) override;
std::unique_ptr<DB>* dbptr) override;
virtual Status OpenAsFollower(const Options& options, const std::string& name,
const std::string& leader_path,
std::unique_ptr<DB>* dbptr) override;
+1 -1
View File
@@ -66,7 +66,7 @@ class DBWithTTL : public StackableDB {
virtual Status GetTtl(ColumnFamilyHandle* h, int32_t* ttl) = 0;
protected:
explicit DBWithTTL(DB* db) : StackableDB(db) {}
explicit DBWithTTL(std::unique_ptr<DB>&& db) : StackableDB(std::move(db)) {}
};
} // namespace ROCKSDB_NAMESPACE
+2 -1
View File
@@ -11,6 +11,7 @@
#include <algorithm>
#include <functional>
#include <map>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
@@ -165,7 +166,7 @@ class LDBCommand {
std::string secondary_path_;
std::string leader_path_;
std::string column_family_name_;
DB* db_;
std::unique_ptr<DB> db_;
DBWithTTL* db_ttl_;
TransactionDB* db_txn_;
std::map<std::string, ColumnFamilyHandle*> cf_handles_;
+5 -1
View File
@@ -6,6 +6,7 @@
#pragma once
#include <map>
#include <memory>
#include <string>
#include <unordered_set>
#include <vector>
@@ -39,8 +40,11 @@ class MemoryUtil {
// only report the usage of the input "cache_set" without
// including those Cache usage inside the input list "dbs"
// of DBs.
//
// Supports vectors of DB* or unique_ptr<DB>.
template <typename DBPtr>
static Status GetApproximateMemoryUsageByType(
const std::vector<DB*>& dbs,
const std::vector<DBPtr>& dbs,
const std::unordered_set<const Cache*> cache_set,
std::map<MemoryUtil::UsageType, uint64_t>* usage_by_type);
};
@@ -123,7 +123,8 @@ class OptimisticTransactionDB : public StackableDB {
protected:
// To Create an OptimisticTransactionDB, call Open()
explicit OptimisticTransactionDB(DB* db) : StackableDB(db) {}
explicit OptimisticTransactionDB(std::unique_ptr<DB>&& db)
: StackableDB(std::move(db)) {}
};
} // namespace ROCKSDB_NAMESPACE
-5
View File
@@ -388,11 +388,6 @@ class StackableDB : public DB {
return db_->NumberLevels(column_family);
}
using DB::MaxMemCompactionLevel;
int MaxMemCompactionLevel(ColumnFamilyHandle* column_family) override {
return db_->MaxMemCompactionLevel(column_family);
}
using DB::Level0StopWriteTrigger;
int Level0StopWriteTrigger(ColumnFamilyHandle* column_family) override {
return db_->Level0StopWriteTrigger(column_family);
+31 -33
View File
@@ -34,11 +34,12 @@
#undef min
#endif
jlong rocksdb_open_helper(JNIEnv* env, jlong jopt_handle, jstring jdb_path,
std::function<ROCKSDB_NAMESPACE::Status(
const ROCKSDB_NAMESPACE::Options&,
const std::string&, ROCKSDB_NAMESPACE::DB**)>
open_fn) {
jlong rocksdb_open_helper(
JNIEnv* env, jlong jopt_handle, jstring jdb_path,
std::function<ROCKSDB_NAMESPACE::Status(
const ROCKSDB_NAMESPACE::Options&, const std::string&,
std::unique_ptr<ROCKSDB_NAMESPACE::DB>*)>
open_fn) {
const char* db_path = env->GetStringUTFChars(jdb_path, nullptr);
if (db_path == nullptr) {
// exception thrown: OutOfMemoryError
@@ -46,13 +47,13 @@ jlong rocksdb_open_helper(JNIEnv* env, jlong jopt_handle, jstring jdb_path,
}
auto* opt = reinterpret_cast<ROCKSDB_NAMESPACE::Options*>(jopt_handle);
ROCKSDB_NAMESPACE::DB* db = nullptr;
std::unique_ptr<ROCKSDB_NAMESPACE::DB> db;
ROCKSDB_NAMESPACE::Status s = open_fn(*opt, db_path, &db);
env->ReleaseStringUTFChars(jdb_path, db_path);
if (s.ok()) {
return GET_CPLUSPLUS_POINTER(db);
return GET_CPLUSPLUS_POINTER(db.release());
} else {
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
return 0;
@@ -69,9 +70,10 @@ jlong Java_org_rocksdb_RocksDB_open__JLjava_lang_String_2(JNIEnv* env, jclass,
jstring jdb_path) {
return rocksdb_open_helper(
env, jopt_handle, jdb_path,
(ROCKSDB_NAMESPACE::Status (*)(
const ROCKSDB_NAMESPACE::Options&, const std::string&,
ROCKSDB_NAMESPACE::DB**))&ROCKSDB_NAMESPACE::DB::Open);
[](const ROCKSDB_NAMESPACE::Options& options, const std::string& db_path,
std::unique_ptr<ROCKSDB_NAMESPACE::DB>* db) {
return ROCKSDB_NAMESPACE::DB::Open(options, db_path, db);
});
}
/*
@@ -87,7 +89,7 @@ jlong Java_org_rocksdb_RocksDB_openROnly__JLjava_lang_String_2Z(
env, jopt_handle, jdb_path,
[error_if_wal_file_exists](const ROCKSDB_NAMESPACE::Options& options,
const std::string& db_path,
ROCKSDB_NAMESPACE::DB** db) {
std::unique_ptr<ROCKSDB_NAMESPACE::DB>* db) {
return ROCKSDB_NAMESPACE::DB::OpenForReadOnly(options, db_path, db,
error_if_wal_file_exists);
});
@@ -100,7 +102,7 @@ jlongArray rocksdb_open_helper(
const ROCKSDB_NAMESPACE::DBOptions&, const std::string&,
const std::vector<ROCKSDB_NAMESPACE::ColumnFamilyDescriptor>&,
std::vector<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>*,
ROCKSDB_NAMESPACE::DB**)>
std::unique_ptr<ROCKSDB_NAMESPACE::DB>*)>
open_fn) {
const char* db_path = env->GetStringUTFChars(jdb_path, nullptr);
if (db_path == nullptr) {
@@ -141,7 +143,7 @@ jlongArray rocksdb_open_helper(
auto* opt = reinterpret_cast<ROCKSDB_NAMESPACE::DBOptions*>(jopt_handle);
std::vector<ROCKSDB_NAMESPACE::ColumnFamilyHandle*> cf_handles;
ROCKSDB_NAMESPACE::DB* db = nullptr;
std::unique_ptr<ROCKSDB_NAMESPACE::DB> db;
ROCKSDB_NAMESPACE::Status s =
open_fn(*opt, db_path, column_families, &cf_handles, &db);
@@ -157,7 +159,7 @@ jlongArray rocksdb_open_helper(
const jsize resultsLen = 1 + len_cols; // db handle + column family handles
std::unique_ptr<jlong[]> results =
std::unique_ptr<jlong[]>(new jlong[resultsLen]);
results[0] = GET_CPLUSPLUS_POINTER(db);
results[0] = GET_CPLUSPLUS_POINTER(db.release());
for (int i = 1; i <= len_cols; i++) {
results[i] = GET_CPLUSPLUS_POINTER(cf_handles[i - 1]);
}
@@ -196,7 +198,7 @@ jlongArray Java_org_rocksdb_RocksDB_openROnly__JLjava_lang_String_2_3_3B_3JZ(
const std::vector<ROCKSDB_NAMESPACE::ColumnFamilyDescriptor>&
column_families,
std::vector<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>* handles,
ROCKSDB_NAMESPACE::DB** db) {
std::unique_ptr<ROCKSDB_NAMESPACE::DB>* db) {
return ROCKSDB_NAMESPACE::DB::OpenForReadOnly(
options, db_path, column_families, handles, db,
error_if_wal_file_exists);
@@ -213,11 +215,15 @@ jlongArray Java_org_rocksdb_RocksDB_open__JLjava_lang_String_2_3_3B_3J(
jobjectArray jcolumn_names, jlongArray jcolumn_options) {
return rocksdb_open_helper(
env, jopt_handle, jdb_path, jcolumn_names, jcolumn_options,
(ROCKSDB_NAMESPACE::Status (*)(
const ROCKSDB_NAMESPACE::DBOptions&, const std::string&,
const std::vector<ROCKSDB_NAMESPACE::ColumnFamilyDescriptor>&,
std::vector<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>*,
ROCKSDB_NAMESPACE::DB**))&ROCKSDB_NAMESPACE::DB::Open);
[](const ROCKSDB_NAMESPACE::DBOptions& options,
const std::string& db_path,
const std::vector<ROCKSDB_NAMESPACE::ColumnFamilyDescriptor>&
column_families,
std::vector<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>* handles,
std::unique_ptr<ROCKSDB_NAMESPACE::DB>* db) {
return ROCKSDB_NAMESPACE::DB::Open(options, db_path, column_families,
handles, db);
});
}
/*
@@ -239,7 +245,7 @@ jlong Java_org_rocksdb_RocksDB_openAsSecondary__JLjava_lang_String_2Ljava_lang_S
env, jopt_handle, jdb_path,
[secondary_db_path](const ROCKSDB_NAMESPACE::Options& options,
const std::string& db_path,
ROCKSDB_NAMESPACE::DB** db) {
std::unique_ptr<ROCKSDB_NAMESPACE::DB>* db) {
return ROCKSDB_NAMESPACE::DB::OpenAsSecondary(options, db_path,
secondary_db_path, db);
});
@@ -275,7 +281,7 @@ Java_org_rocksdb_RocksDB_openAsSecondary__JLjava_lang_String_2Ljava_lang_String_
const std::vector<ROCKSDB_NAMESPACE::ColumnFamilyDescriptor>&
column_families,
std::vector<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>* handles,
ROCKSDB_NAMESPACE::DB** db) {
std::unique_ptr<ROCKSDB_NAMESPACE::DB>* db) {
return ROCKSDB_NAMESPACE::DB::OpenAsSecondary(
options, db_path, secondary_db_path, column_families, handles, db);
});
@@ -3044,17 +3050,9 @@ jint Java_org_rocksdb_RocksDB_numberLevels(JNIEnv*, jclass, jlong jdb_handle,
* Signature: (JJ)I
*/
jint Java_org_rocksdb_RocksDB_maxMemCompactionLevel(JNIEnv*, jclass,
jlong jdb_handle,
jlong jcf_handle) {
auto* db = reinterpret_cast<ROCKSDB_NAMESPACE::DB*>(jdb_handle);
ROCKSDB_NAMESPACE::ColumnFamilyHandle* cf_handle;
if (jcf_handle == 0) {
cf_handle = db->DefaultColumnFamily();
} else {
cf_handle =
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
}
return static_cast<jint>(db->MaxMemCompactionLevel(cf_handle));
jlong /*jdb_handle*/,
jlong /*jcf_handle*/) {
return 0;
}
/*
+1 -2
View File
@@ -647,7 +647,7 @@ TEST_F(AutoRollLoggerTest, LogHeaderTest) {
}
TEST_F(AutoRollLoggerTest, LogFileExistence) {
ROCKSDB_NAMESPACE::DB* db;
std::unique_ptr<ROCKSDB_NAMESPACE::DB> db;
ROCKSDB_NAMESPACE::Options options;
#ifdef OS_WIN
// Replace all slashes in the path so windows CompSpec does not
@@ -664,7 +664,6 @@ TEST_F(AutoRollLoggerTest, LogFileExistence) {
options.create_if_missing = true;
ASSERT_OK(ROCKSDB_NAMESPACE::DB::Open(options, kTestDir, &db));
ASSERT_OK(default_env->FileExists(kLogFile));
delete db;
}
TEST_F(AutoRollLoggerTest, FileCreateFailure) {
+2 -2
View File
@@ -83,7 +83,7 @@ TEST_P(MemoryAllocatorTest, DatabaseBlockCache) {
auto cache = NewLRUCache(1024 * 1024, 6, false, 0.0, allocator_);
table_options.block_cache = cache;
options.table_factory.reset(NewBlockBasedTableFactory(table_options));
DB* db = nullptr;
std::unique_ptr<DB> db;
Status s = DB::Open(options, dbname, &db);
ASSERT_OK(s);
ASSERT_NE(db, nullptr);
@@ -115,7 +115,7 @@ TEST_P(MemoryAllocatorTest, DatabaseBlockCache) {
// Close database
s = db->Close();
ASSERT_OK(s);
delete db;
db.reset();
ASSERT_OK(DestroyDB(dbname, options));
}
+4 -12
View File
@@ -138,13 +138,11 @@ static void SetupDB(benchmark::State& state, Options& options,
db_path + kFilePathSeparator + test_name + std::to_string(getpid());
DestroyDB(db_name, options);
DB* db_ptr = nullptr;
s = DB::Open(options, db_name, &db_ptr);
s = DB::Open(options, db_name, db);
if (!s.ok()) {
state.SkipWithError(s.ToString().c_str());
return;
}
db->reset(db_ptr);
}
static void TeardownDB(benchmark::State& state, const std::unique_ptr<DB>& db,
@@ -181,12 +179,10 @@ static void DBOpen(benchmark::State& state) {
for (auto _ : state) {
{
DB* db_ptr = nullptr;
Status s = DB::Open(options, db_name, &db_ptr);
Status s = DB::Open(options, db_name, &db);
if (!s.ok()) {
state.SkipWithError(s.ToString().c_str());
}
db.reset(db_ptr);
}
state.PauseTiming();
auto wo = WriteOptions();
@@ -231,12 +227,10 @@ static void DBClose(benchmark::State& state) {
for (auto _ : state) {
state.PauseTiming();
{
DB* db_ptr = nullptr;
Status s = DB::Open(options, db_name, &db_ptr);
Status s = DB::Open(options, db_name, &db);
if (!s.ok()) {
state.SkipWithError(s.ToString().c_str());
}
db.reset(db_ptr);
}
auto wo = WriteOptions();
Status s;
@@ -727,13 +721,11 @@ static void SimpleGetWithPerfContext(benchmark::State& state) {
DestroyDB(db_name, options);
{
DB* db_ptr = nullptr;
s = DB::Open(options, db_name, &db_ptr);
s = DB::Open(options, db_name, &db);
if (!s.ok()) {
state.SkipWithError(s.ToString().c_str());
return;
}
db.reset(db_ptr);
}
// load db
auto wo = WriteOptions();
+2 -2
View File
@@ -164,7 +164,7 @@ TEST_F(SstFileReaderTest, ReadFileWithGlobalSeqno) {
Options options;
options.create_if_missing = true;
std::string db_name = test::PerThreadDBPath("test_db");
DB* db;
std::unique_ptr<DB> db;
ASSERT_OK(DB::Open(options, db_name, &db));
// Bump sequence number.
ASSERT_OK(db->Put(WriteOptions(), keys[0], "foo"));
@@ -186,7 +186,7 @@ TEST_F(SstFileReaderTest, ReadFileWithGlobalSeqno) {
}
}
ASSERT_FALSE(ingested_file.empty());
delete db;
db.reset();
// Verify the file can be open and read by SstFileReader.
CheckFile(db_name + ingested_file, keys, true /* check_global_seqno */);
+2 -3
View File
@@ -84,7 +84,7 @@ void TableReaderBenchmark(Options& opts, EnvOptions& env_options,
Env* env = Env::Default();
auto* clock = env->GetSystemClock().get();
TableBuilder* tb = nullptr;
DB* db = nullptr;
std::unique_ptr<DB> db;
Status s;
const ImmutableOptions ioptions(opts);
const ColumnFamilyOptions cfo(opts);
@@ -257,8 +257,7 @@ void TableReaderBenchmark(Options& opts, EnvOptions& env_options,
if (!through_db) {
env->DeleteFile(file_name);
} else {
delete db;
db = nullptr;
db.reset();
DestroyDB(dbname, opts);
}
}
+16 -20
View File
@@ -583,18 +583,16 @@ class DBConstructor : public Constructor {
public:
explicit DBConstructor(const Comparator* cmp)
: Constructor(cmp), comparator_(cmp) {
db_ = nullptr;
NewDB();
}
~DBConstructor() override { delete db_; }
~DBConstructor() override {}
Status FinishImpl(const Options& /*options*/,
const ImmutableOptions& /*ioptions*/,
const MutableCFOptions& /*moptions*/,
const BlockBasedTableOptions& /*table_options*/,
const InternalKeyComparator& /*internal_comparator*/,
const stl_wrappers::KVMap& kv_map) override {
delete db_;
db_ = nullptr;
db_.reset();
NewDB();
for (const auto& kv : kv_map) {
WriteBatch batch;
@@ -609,7 +607,7 @@ class DBConstructor : public Constructor {
return new InternalIteratorFromIterator(db_->NewIterator(ReadOptions()));
}
DB* db() const override { return db_; }
DB* db() const override { return db_.get(); }
private:
void NewDB() {
@@ -628,7 +626,7 @@ class DBConstructor : public Constructor {
}
const Comparator* comparator_;
DB* db_;
std::unique_ptr<DB> db_;
};
enum TestType {
@@ -5368,7 +5366,7 @@ TEST_F(PrefixTest, PrefixAndWholeKeyTest) {
const std::string kDBPath = test::PerThreadDBPath("table_prefix_test");
options.table_factory.reset(NewBlockBasedTableFactory(bbto));
ASSERT_OK(DestroyDB(kDBPath, options));
ROCKSDB_NAMESPACE::DB* db;
std::unique_ptr<ROCKSDB_NAMESPACE::DB> db;
ASSERT_OK(ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &db));
// Create a bunch of keys with 10 filters.
@@ -5382,7 +5380,7 @@ TEST_F(PrefixTest, PrefixAndWholeKeyTest) {
// Trigger compaction.
ASSERT_OK(db->CompactRange(CompactRangeOptions(), nullptr, nullptr));
delete db;
db.reset();
// In the second round, turn whole_key_filtering off and expect
// rocksdb still works.
}
@@ -5688,7 +5686,7 @@ TEST_P(BlockBasedTableTest, FixBlockAlignMismatchedFileChecksums) {
const std::string kDBPath =
test::PerThreadDBPath("block_align_padded_bytes_verify_file_checksums");
ASSERT_OK(DestroyDB(kDBPath, options));
DB* db;
std::unique_ptr<DB> db;
ASSERT_OK(DB::Open(options, kDBPath, &db));
ASSERT_OK(db->Put(WriteOptions(), "k1", "v1"));
ASSERT_OK(db->Flush(FlushOptions()));
@@ -5696,7 +5694,7 @@ TEST_P(BlockBasedTableTest, FixBlockAlignMismatchedFileChecksums) {
// aligning blocks are used to generate the checksum to compare against the
// one not generated by padded bytes
ASSERT_OK(db->VerifyFileChecksums(ReadOptions()));
delete db;
db.reset();
}
class NoBufferAlignmenttWritableFile : public FSWritableFileOwnerWrapper {
@@ -5751,7 +5749,7 @@ TEST_P(BlockBasedTableTest,
const std::string kDBPath = test::PerThreadDBPath(
"block_align_flush_during_flush_verify_file_checksums");
ASSERT_OK(DestroyDB(kDBPath, options));
DB* db;
std::unique_ptr<DB> db;
ASSERT_OK(DB::Open(options, kDBPath, &db));
ASSERT_OK(db->Put(WriteOptions(), "k1", "k2"));
@@ -5760,7 +5758,7 @@ TEST_P(BlockBasedTableTest,
// Before the fix, VerifyFileChecksums() will fail as incorrect padded bytes
// were used to generate checksum upon file creation
ASSERT_OK(db->VerifyFileChecksums(ReadOptions()));
delete db;
db.reset();
}
TEST_P(BlockBasedTableTest, PropertiesBlockRestartPointTest) {
@@ -6093,27 +6091,25 @@ TEST_P(BlockBasedTableTest, BadOptions) {
options.table_factory.reset(NewBlockBasedTableFactory(bbto));
ASSERT_OK(DestroyDB(kDBPath, options));
std::unique_ptr<DB> db;
{
ROCKSDB_NAMESPACE::DB* _db;
ASSERT_NOK(ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &_db));
std::unique_ptr<ROCKSDB_NAMESPACE::DB> db;
ASSERT_NOK(ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &db));
bbto.block_size = 4096;
options.compression = kSnappyCompression;
options.table_factory.reset(NewBlockBasedTableFactory(bbto));
ASSERT_NOK(ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &_db));
ASSERT_NOK(ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &db));
options.compression = kNoCompression;
options.bottommost_compression = kSnappyCompression;
ASSERT_NOK(ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &_db));
ASSERT_NOK(ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &db));
options.bottommost_compression = kNoCompression;
options.compression_per_level.emplace_back(kSnappyCompression);
ASSERT_NOK(ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &_db));
ASSERT_NOK(ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &db));
options.compression_per_level.clear();
ASSERT_OK(ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &_db));
db.reset(_db);
ASSERT_OK(ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &db));
}
}
+39 -19
View File
@@ -2058,6 +2058,7 @@ static void AppendWithSpace(std::string* str, Slice msg) {
struct DBWithColumnFamilies {
std::vector<ColumnFamilyHandle*> cfh;
std::unique_ptr<DB> db_owner;
DB* db;
OptimisticTransactionDB* opt_txn_db;
std::atomic<size_t> num_created; // Need to be updated after all the
@@ -2087,13 +2088,9 @@ struct DBWithColumnFamilies {
std::for_each(cfh.begin(), cfh.end(),
[](ColumnFamilyHandle* cfhi) { delete cfhi; });
cfh.clear();
if (opt_txn_db) {
delete opt_txn_db;
opt_txn_db = nullptr;
} else {
delete db;
db = nullptr;
}
db_owner.reset();
db = nullptr;
opt_txn_db = nullptr;
}
ColumnFamilyHandle* GetCfh(int64_t rand_num) {
@@ -3412,8 +3409,8 @@ class Benchmark {
void DeleteDBs() {
db_.DeleteDBs();
for (const DBWithColumnFamilies& dbwcf : multi_dbs_) {
delete dbwcf.db;
for (auto& dbwcf : multi_dbs_) {
dbwcf.DeleteDBs();
}
}
@@ -3518,11 +3515,13 @@ class Benchmark {
void VerifyDBFromDB(std::string& truth_db_name) {
DBWithColumnFamilies truth_db;
auto s = DB::OpenForReadOnly(open_options_, truth_db_name, &truth_db.db);
auto s =
DB::OpenForReadOnly(open_options_, truth_db_name, &truth_db.db_owner);
if (!s.ok()) {
fprintf(stderr, "open error: %s\n", s.ToString().c_str());
db_bench_exit(1);
}
truth_db.db = truth_db.db_owner.get();
ReadOptions ro;
ro.total_order_seek = true;
std::unique_ptr<Iterator> truth_iter(truth_db.db->NewIterator(ro));
@@ -3903,7 +3902,7 @@ class Benchmark {
}
Options options = open_options_;
for (size_t i = 0; i < multi_dbs_.size(); i++) {
delete multi_dbs_[i].db;
multi_dbs_[i].DeleteDBs();
if (!open_options_.wal_dir.empty()) {
options.wal_dir = GetPathForMultiple(open_options_.wal_dir, i);
}
@@ -5136,11 +5135,15 @@ class Benchmark {
}
if (FLAGS_readonly) {
s = hooks.OpenForReadOnly(options, db_name, column_families, &db->cfh,
&db->db);
&db->db_owner);
if (s.ok()) {
db->db = db->db_owner.get();
}
} else if (FLAGS_optimistic_transaction_db) {
s = hooks.OpenOptimisticTransactionDB(options, db_name, column_families,
&db->cfh, &db->opt_txn_db);
if (s.ok()) {
db->db_owner.reset(db->opt_txn_db);
db->db = db->opt_txn_db->GetBaseDB();
}
} else if (FLAGS_transaction_db) {
@@ -5154,20 +5157,29 @@ class Benchmark {
s = hooks.OpenTransactionDB(options, txn_db_options, db_name,
column_families, &db->cfh, &ptr);
if (s.ok()) {
db->db_owner.reset(ptr);
db->db = ptr;
}
} else {
s = hooks.Open(options, db_name, column_families, &db->cfh, &db->db);
s = hooks.Open(options, db_name, column_families, &db->cfh,
&db->db_owner);
if (s.ok()) {
db->db = db->db_owner.get();
}
}
db->cfh.resize(FLAGS_num_column_families);
db->num_created = num_hot;
db->num_hot = num_hot;
db->cfh_idx_to_prob = std::move(cfh_idx_to_prob);
} else if (FLAGS_readonly) {
s = hooks.OpenForReadOnly(options, db_name, &db->db, false);
s = hooks.OpenForReadOnly(options, db_name, &db->db_owner, false);
if (s.ok()) {
db->db = db->db_owner.get();
}
} else if (FLAGS_optimistic_transaction_db) {
s = hooks.OpenOptimisticTransactionDB(options, db_name, &db->opt_txn_db);
if (s.ok()) {
db->db_owner.reset(db->opt_txn_db);
db->db = db->opt_txn_db->GetBaseDB();
}
} else if (FLAGS_transaction_db) {
@@ -5183,6 +5195,7 @@ class Benchmark {
s = hooks.OpenTransactionDB(options, txn_db_options, db_name, &ptr);
}
if (s.ok()) {
db->db_owner.reset(ptr);
db->db = ptr;
}
} else if (FLAGS_use_blob_db) {
@@ -5195,6 +5208,7 @@ class Benchmark {
blob_db::BlobDB* ptr = nullptr;
s = hooks.Open(options, blob_db_options, db_name, &ptr);
if (s.ok()) {
db->db_owner.reset(ptr);
db->db = ptr;
}
} else if (FLAGS_use_secondary_db) {
@@ -5205,7 +5219,10 @@ class Benchmark {
FLAGS_secondary_path = default_secondary_path;
}
s = hooks.OpenAsSecondary(options, db_name, FLAGS_secondary_path,
&db->db);
&db->db_owner);
if (s.ok()) {
db->db = db->db_owner.get();
}
if (s.ok() && FLAGS_secondary_update_interval > 0) {
secondary_update_thread_.reset(new port::Thread(
[this](int interval, DBWithColumnFamilies* _db) {
@@ -5225,13 +5242,16 @@ class Benchmark {
FLAGS_secondary_update_interval, db));
}
} else if (FLAGS_open_as_follower) {
std::unique_ptr<DB> dbptr;
s = hooks.OpenAsFollower(options, db_name, FLAGS_leader_path, &dbptr);
s = hooks.OpenAsFollower(options, db_name, FLAGS_leader_path,
&db->db_owner);
if (s.ok()) {
db->db = dbptr.release();
db->db = db->db_owner.get();
}
} else {
s = hooks.Open(options, db_name, &db->db);
s = hooks.Open(options, db_name, &db->db_owner);
if (s.ok()) {
db->db = db->db_owner.get();
}
}
if (FLAGS_report_open_timing) {
std::cout << "OpenDb: "
+2 -2
View File
@@ -83,7 +83,7 @@ int main(int argc, const char** argv) {
options.create_if_missing = true;
options.WAL_ttl_seconds = FLAGS_wal_ttl_seconds;
options.WAL_size_limit_MB = FLAGS_wal_size_limit_MB;
DB* db;
std::unique_ptr<DB> db;
DestroyDB(default_db_path, options);
Status s = DB::Open(options, default_db_path, &db);
@@ -94,7 +94,7 @@ int main(int argc, const char** argv) {
}
DataPumpThread dataPump;
dataPump.db = db;
dataPump.db = db.get();
env->StartThread(DataPumpThreadBody, &dataPump);
std::unique_ptr<TransactionLogIterator> iter;
+2 -4
View File
@@ -41,9 +41,8 @@ class SanityTest {
if (!s.ok()) {
return s;
}
DB* db = nullptr;
std::unique_ptr<DB> db;
s = DB::Open(options, dbname, &db);
std::unique_ptr<DB> db_guard(db);
if (!s.ok()) {
return s;
}
@@ -58,10 +57,9 @@ class SanityTest {
return db->Flush(FlushOptions());
}
Status Verify() {
DB* db = nullptr;
std::unique_ptr<DB> db;
std::string dbname = path_ + Name();
Status s = DB::Open(GetOptions(), dbname, &db);
std::unique_ptr<DB> db_guard(db);
if (!s.ok()) {
return s;
}
+4 -8
View File
@@ -16,7 +16,6 @@ namespace ROCKSDB_NAMESPACE {
bool DbDumpTool::Run(const DumpOptions& dump_options,
ROCKSDB_NAMESPACE::Options options) {
ROCKSDB_NAMESPACE::DB* dbptr;
ROCKSDB_NAMESPACE::Status status;
std::unique_ptr<ROCKSDB_NAMESPACE::WritableFile> dumpfile;
char hostname[1024];
@@ -31,16 +30,15 @@ bool DbDumpTool::Run(const DumpOptions& dump_options,
// Open the database
options.create_if_missing = false;
std::unique_ptr<ROCKSDB_NAMESPACE::DB> db;
status = ROCKSDB_NAMESPACE::DB::OpenForReadOnly(options, dump_options.db_path,
&dbptr);
&db);
if (!status.ok()) {
std::cerr << "Unable to open database '" << dump_options.db_path
<< "' for reading: " << status.ToString() << std::endl;
return false;
}
const std::unique_ptr<ROCKSDB_NAMESPACE::DB> db(dbptr);
status = env->NewWritableFile(dump_options.dump_location, &dumpfile,
ROCKSDB_NAMESPACE::EnvOptions());
if (!status.ok()) {
@@ -131,7 +129,6 @@ bool DbDumpTool::Run(const DumpOptions& dump_options,
bool DbUndumpTool::Run(const UndumpOptions& undump_options,
ROCKSDB_NAMESPACE::Options options) {
ROCKSDB_NAMESPACE::DB* dbptr;
ROCKSDB_NAMESPACE::Status status;
ROCKSDB_NAMESPACE::Env* env;
std::unique_ptr<ROCKSDB_NAMESPACE::SequentialFile> dumpfile;
@@ -180,15 +177,14 @@ bool DbUndumpTool::Run(const UndumpOptions& undump_options,
}
options.create_if_missing = true;
status = ROCKSDB_NAMESPACE::DB::Open(options, undump_options.db_path, &dbptr);
std::unique_ptr<ROCKSDB_NAMESPACE::DB> db;
status = ROCKSDB_NAMESPACE::DB::Open(options, undump_options.db_path, &db);
if (!status.ok()) {
std::cerr << "Unable to open database '" << undump_options.db_path
<< "' for writing: " << status.ToString() << std::endl;
return false;
}
const std::unique_ptr<ROCKSDB_NAMESPACE::DB> db(dbptr);
uint32_t last_keysize = 64;
size_t last_valsize = 1 << 20;
std::unique_ptr<char[]> keyscratch(new char[last_keysize]);
+2 -3
View File
@@ -50,8 +50,7 @@ class IOTracerParserTest : public testing::Test {
if (db_ != nullptr) {
Options options;
options.env = env_;
delete db_;
db_ = nullptr;
db_.reset();
EXPECT_OK(DestroyDB(dbname_, options));
}
EXPECT_OK(env_->DeleteDir(test_path_));
@@ -97,7 +96,7 @@ class IOTracerParserTest : public testing::Test {
ASSERT_EQ(0, ROCKSDB_NAMESPACE::io_tracer_parser(argc, argv));
}
DB* db_;
std::unique_ptr<DB> db_;
Env* env_;
EnvOptions env_options_;
std::string trace_file_path_;
+12 -15
View File
@@ -595,7 +595,7 @@ void LDBCommand::OpenDB() {
st = TransactionDB::Open(options_, txn_db_options, db_path_,
column_families_, &handles_opened, &db_txn_);
}
db_ = db_txn_;
db_.reset(db_txn_);
} else if (is_db_ttl_) {
// ldb doesn't yet support TTL DB with multiple column families
if (!column_family_name_.empty() || !column_families_.empty()) {
@@ -611,7 +611,7 @@ void LDBCommand::OpenDB() {
} else {
st = DBWithTTL::Open(options_, db_path_, &db_ttl_);
}
db_ = db_ttl_;
db_.reset(db_ttl_);
} else {
if (!secondary_path_.empty() && !leader_path_.empty()) {
exec_state_ = LDBCommandExecuteResult::Failed(
@@ -631,9 +631,7 @@ void LDBCommand::OpenDB() {
} else if (!secondary_path_.empty()) {
st = DB::OpenAsSecondary(options_, db_path_, secondary_path_, &db_);
} else {
std::unique_ptr<DB> dbptr;
st = DB::OpenAsFollower(options_, db_path_, leader_path_, &dbptr);
db_ = dbptr.release();
st = DB::OpenAsFollower(options_, db_path_, leader_path_, &db_);
}
} else {
if (secondary_path_.empty() && leader_path_.empty()) {
@@ -643,10 +641,8 @@ void LDBCommand::OpenDB() {
st = DB::OpenAsSecondary(options_, db_path_, secondary_path_,
column_families_, &handles_opened, &db_);
} else {
std::unique_ptr<DB> dbptr;
st = DB::OpenAsFollower(options_, db_path_, leader_path_,
column_families_, &handles_opened, &dbptr);
db_ = dbptr.release();
column_families_, &handles_opened, &db_);
}
}
}
@@ -691,8 +687,9 @@ void LDBCommand::CloseDB() {
}
Status s = db_->Close();
s.PermitUncheckedError();
delete db_;
db_ = nullptr;
db_.reset();
db_ttl_ = nullptr;
db_txn_ = nullptr;
}
}
@@ -2227,9 +2224,9 @@ void InternalDumpCommand::DoCommand() {
// Cast as DBImpl to get internal iterator
std::vector<KeyVersion> key_versions;
Status st =
GetAllKeyVersions(db_, GetCfHandle(), has_from_ ? from_ : OptSlice{},
has_to_ ? to_ : OptSlice{}, max_keys_, &key_versions);
Status st = GetAllKeyVersions(
db_.get(), GetCfHandle(), has_from_ ? from_ : OptSlice{},
has_to_ ? to_ : OptSlice{}, max_keys_, &key_versions);
if (!st.ok()) {
exec_state_ = LDBCommandExecuteResult::Failed(st.ToString());
return;
@@ -4501,7 +4498,7 @@ void CheckPointCommand::DoCommand() {
return;
}
Checkpoint* checkpoint;
Status status = Checkpoint::Create(db_, &checkpoint);
Status status = Checkpoint::Create(db_.get(), &checkpoint);
status = checkpoint->CreateCheckpoint(checkpoint_dir_);
if (status.ok()) {
fprintf(stdout, "OK\n");
@@ -4656,7 +4653,7 @@ void BackupCommand::DoCommand() {
exec_state_ = LDBCommandExecuteResult::Failed(status.ToString());
return;
}
status = backup_engine->CreateNewBackup(db_);
status = backup_engine->CreateNewBackup(db_.get());
if (status.ok()) {
fprintf(stdout, "create new backup OK\n");
} else {
+41 -47
View File
@@ -7,6 +7,7 @@
#include <cinttypes>
#include <iomanip>
#include <memory>
#include "db/db_test_util.h"
#include "db/version_edit.h"
@@ -99,7 +100,7 @@ TEST_F(LdbCmdTest, MemEnv) {
opts.env = env.get();
opts.create_if_missing = true;
DB* db = nullptr;
std::unique_ptr<DB> db;
std::string dbname = test::PerThreadDBPath(env.get(), "ldb_cmd_test");
ASSERT_OK(DB::Open(opts, dbname, &db));
@@ -113,7 +114,7 @@ TEST_F(LdbCmdTest, MemEnv) {
fopts.wait = true;
ASSERT_OK(db->Flush(fopts));
delete db;
db.reset();
char arg1[] = "./ldb";
char arg2[1024];
@@ -285,7 +286,7 @@ TEST_F(LdbCmdTest, DumpFileChecksumNoChecksum) {
opts.env = env.get();
opts.create_if_missing = true;
DB* db = nullptr;
std::unique_ptr<DB> db;
std::string dbname = test::PerThreadDBPath(env.get(), "ldb_cmd_test");
ASSERT_OK(DB::Open(opts, dbname, &db));
@@ -322,7 +323,7 @@ TEST_F(LdbCmdTest, DumpFileChecksumNoChecksum) {
}
ASSERT_OK(db->Flush(fopts));
ASSERT_OK(db->Close());
delete db;
db.reset();
char arg1[] = "./ldb";
char arg2[1024];
@@ -337,7 +338,7 @@ TEST_F(LdbCmdTest, DumpFileChecksumNoChecksum) {
ASSERT_OK(DB::Open(opts, dbname, &db));
// Verify each sst file checksum value and checksum name
FileChecksumTestHelper fct_helper(opts, db, dbname);
FileChecksumTestHelper fct_helper(opts, db.get(), dbname);
ASSERT_OK(fct_helper.VerifyEachFileChecksum());
// Manually trigger compaction
@@ -350,11 +351,11 @@ TEST_F(LdbCmdTest, DumpFileChecksumNoChecksum) {
CompactRangeOptions options;
ASSERT_OK(db->CompactRange(options, &begin, &end));
// Verify each sst file checksum after compaction
FileChecksumTestHelper fct_helper_ac(opts, db, dbname);
FileChecksumTestHelper fct_helper_ac(opts, db.get(), dbname);
ASSERT_OK(fct_helper_ac.VerifyEachFileChecksum());
ASSERT_OK(db->Close());
delete db;
db.reset();
ASSERT_EQ(0,
LDBCommandRunner::RunCommand(4, argv, opts, LDBOptions(), nullptr));
@@ -364,7 +365,7 @@ TEST_F(LdbCmdTest, DumpFileChecksumNoChecksum) {
// Verify the checksum information in memory is the same as that in Manifest;
std::vector<LiveFileMetaData> live_files;
db->GetLiveFilesMetaData(&live_files);
delete db;
db.reset();
ASSERT_OK(fct_helper_ac.VerifyChecksumInManifest(live_files));
}
@@ -376,7 +377,7 @@ TEST_F(LdbCmdTest, BlobDBDumpFileChecksumNoChecksum) {
opts.create_if_missing = true;
opts.enable_blob_files = true;
DB* db = nullptr;
std::unique_ptr<DB> db;
std::string dbname = test::PerThreadDBPath(env.get(), "ldb_cmd_test");
ASSERT_OK(DB::Open(opts, dbname, &db));
@@ -413,7 +414,7 @@ TEST_F(LdbCmdTest, BlobDBDumpFileChecksumNoChecksum) {
}
ASSERT_OK(db->Flush(fopts));
ASSERT_OK(db->Close());
delete db;
db.reset();
char arg1[] = "./ldb";
std::string arg2_str = "--db=" + dbname;
@@ -427,7 +428,7 @@ TEST_F(LdbCmdTest, BlobDBDumpFileChecksumNoChecksum) {
ASSERT_OK(DB::Open(opts, dbname, &db));
// Verify each sst and blob file checksum value and checksum name
FileChecksumTestHelper fct_helper(opts, db, dbname);
FileChecksumTestHelper fct_helper(opts, db.get(), dbname);
ASSERT_OK(fct_helper.VerifyEachFileChecksum());
// Manually trigger compaction
@@ -443,11 +444,11 @@ TEST_F(LdbCmdTest, BlobDBDumpFileChecksumNoChecksum) {
CompactRangeOptions options;
ASSERT_OK(db->CompactRange(options, &begin, &end));
// Verify each sst file checksum after compaction
FileChecksumTestHelper fct_helper_ac(opts, db, dbname);
FileChecksumTestHelper fct_helper_ac(opts, db.get(), dbname);
ASSERT_OK(fct_helper_ac.VerifyEachFileChecksum());
ASSERT_OK(db->Close());
delete db;
db.reset();
ASSERT_EQ(0,
LDBCommandRunner::RunCommand(4, argv, opts, LDBOptions(), nullptr));
@@ -461,7 +462,7 @@ TEST_F(LdbCmdTest, DumpFileChecksumCRC32) {
opts.create_if_missing = true;
opts.file_checksum_gen_factory = GetFileChecksumGenCrc32cFactory();
DB* db = nullptr;
std::unique_ptr<DB> db;
std::string dbname = test::PerThreadDBPath(env.get(), "ldb_cmd_test");
ASSERT_OK(DB::Open(opts, dbname, &db));
@@ -498,7 +499,7 @@ TEST_F(LdbCmdTest, DumpFileChecksumCRC32) {
}
ASSERT_OK(db->Flush(fopts));
ASSERT_OK(db->Close());
delete db;
db.reset();
char arg1[] = "./ldb";
char arg2[1024];
@@ -513,7 +514,7 @@ TEST_F(LdbCmdTest, DumpFileChecksumCRC32) {
ASSERT_OK(DB::Open(opts, dbname, &db));
// Verify each sst file checksum value and checksum name
FileChecksumTestHelper fct_helper(opts, db, dbname);
FileChecksumTestHelper fct_helper(opts, db.get(), dbname);
ASSERT_OK(fct_helper.VerifyEachFileChecksum());
// Manually trigger compaction
@@ -526,11 +527,11 @@ TEST_F(LdbCmdTest, DumpFileChecksumCRC32) {
CompactRangeOptions options;
ASSERT_OK(db->CompactRange(options, &begin, &end));
// Verify each sst file checksum after compaction
FileChecksumTestHelper fct_helper_ac(opts, db, dbname);
FileChecksumTestHelper fct_helper_ac(opts, db.get(), dbname);
ASSERT_OK(fct_helper_ac.VerifyEachFileChecksum());
ASSERT_OK(db->Close());
delete db;
db.reset();
ASSERT_EQ(0,
LDBCommandRunner::RunCommand(4, argv, opts, LDBOptions(), nullptr));
@@ -543,7 +544,7 @@ TEST_F(LdbCmdTest, DumpFileChecksumCRC32) {
ASSERT_OK(fct_helper_ac.VerifyChecksumInManifest(live_files));
ASSERT_OK(db->Close());
delete db;
db.reset();
}
TEST_F(LdbCmdTest, BlobDBDumpFileChecksumCRC32) {
@@ -555,7 +556,7 @@ TEST_F(LdbCmdTest, BlobDBDumpFileChecksumCRC32) {
opts.file_checksum_gen_factory = GetFileChecksumGenCrc32cFactory();
opts.enable_blob_files = true;
DB* db = nullptr;
std::unique_ptr<DB> db;
std::string dbname = test::PerThreadDBPath(env.get(), "ldb_cmd_test");
ASSERT_OK(DB::Open(opts, dbname, &db));
@@ -592,7 +593,7 @@ TEST_F(LdbCmdTest, BlobDBDumpFileChecksumCRC32) {
}
ASSERT_OK(db->Flush(fopts));
ASSERT_OK(db->Close());
delete db;
db.reset();
char arg1[] = "./ldb";
std::string arg2_str = "--db=" + dbname;
@@ -606,7 +607,7 @@ TEST_F(LdbCmdTest, BlobDBDumpFileChecksumCRC32) {
ASSERT_OK(DB::Open(opts, dbname, &db));
// Verify each sst and blob file checksum value and checksum name
FileChecksumTestHelper fct_helper(opts, db, dbname);
FileChecksumTestHelper fct_helper(opts, db.get(), dbname);
ASSERT_OK(fct_helper.VerifyEachFileChecksum());
// Manually trigger compaction
@@ -622,11 +623,11 @@ TEST_F(LdbCmdTest, BlobDBDumpFileChecksumCRC32) {
CompactRangeOptions options;
ASSERT_OK(db->CompactRange(options, &begin, &end));
// Verify each sst file checksum after compaction
FileChecksumTestHelper fct_helper_ac(opts, db, dbname);
FileChecksumTestHelper fct_helper_ac(opts, db.get(), dbname);
ASSERT_OK(fct_helper_ac.VerifyEachFileChecksum());
ASSERT_OK(db->Close());
delete db;
db.reset();
ASSERT_EQ(0,
LDBCommandRunner::RunCommand(4, argv, opts, LDBOptions(), nullptr));
@@ -678,7 +679,7 @@ TEST_F(LdbCmdTest, ListFileTombstone) {
opts.env = env.get();
opts.create_if_missing = true;
DB* db = nullptr;
std::unique_ptr<DB> db;
std::string dbname = test::PerThreadDBPath(env.get(), "ldb_cmd_test");
ASSERT_OK(DB::Open(opts, dbname, &db));
@@ -694,7 +695,7 @@ TEST_F(LdbCmdTest, ListFileTombstone) {
ASSERT_OK(db->DeleteRange(wopts, db->DefaultColumnFamily(), "bar", "foo2"));
ASSERT_OK(db->Flush(fopts));
delete db;
db.reset();
{
char arg1[] = "./ldb";
@@ -771,7 +772,7 @@ TEST_F(LdbCmdTest, DisableConsistencyChecks) {
std::string dbname = test::PerThreadDBPath(env.get(), "ldb_cmd_test");
{
DB* db = nullptr;
std::unique_ptr<DB> db;
ASSERT_OK(DB::Open(opts, dbname, &db));
WriteOptions wopts;
@@ -785,8 +786,6 @@ TEST_F(LdbCmdTest, DisableConsistencyChecks) {
ASSERT_OK(db->Put(wopts, "foo2", "3"));
ASSERT_OK(db->Put(wopts, "bar2", "4"));
ASSERT_OK(db->Flush(fopts));
delete db;
}
{
@@ -890,7 +889,7 @@ TEST_F(LdbCmdTest, LoadCFOptionsAndOverride) {
opts.env = env.get();
opts.create_if_missing = true;
DB* db = nullptr;
std::unique_ptr<DB> db;
std::string dbname = test::PerThreadDBPath(env.get(), "ldb_cmd_test");
ASSERT_OK(DestroyDB(dbname, opts));
ASSERT_OK(DB::Open(opts, dbname, &db));
@@ -901,7 +900,7 @@ TEST_F(LdbCmdTest, LoadCFOptionsAndOverride) {
ASSERT_OK(db->CreateColumnFamily(cf_opts, "cf1", &cf_handle));
delete cf_handle;
delete db;
db.reset();
char arg1[] = "./ldb";
char arg2[1024];
@@ -933,7 +932,7 @@ TEST_F(LdbCmdTest, UnsafeRemoveSstFile) {
opts.level0_file_num_compaction_trigger = 10;
opts.create_if_missing = true;
DB* db = nullptr;
std::unique_ptr<DB> db;
std::string dbname = test::PerThreadDBPath(Env::Default(), "ldb_cmd_test");
ASSERT_OK(DestroyDB(dbname, opts));
ASSERT_OK(DB::Open(opts, dbname, &db));
@@ -957,8 +956,7 @@ TEST_F(LdbCmdTest, UnsafeRemoveSstFile) {
uint64_t to_remove = numbers[1];
// Close for unsafe_remove_sst_file
delete db;
db = nullptr;
db.reset();
char arg1[] = "./ldb";
char arg2[1024];
@@ -1007,8 +1005,7 @@ TEST_F(LdbCmdTest, UnsafeRemoveSstFile) {
// Close for unsafe_remove_sst_file
delete cf_handle;
delete db;
db = nullptr;
db.reset();
snprintf(arg4, sizeof(arg4), "%" PRIu64, to_remove);
ASSERT_EQ(0,
@@ -1049,8 +1046,7 @@ TEST_F(LdbCmdTest, UnsafeRemoveSstFile) {
for (auto& h : handles) {
delete h;
}
delete db;
db = nullptr;
db.reset();
snprintf(arg4, sizeof(arg4), "%" PRIu64, to_remove);
ASSERT_EQ(0,
@@ -1066,7 +1062,7 @@ TEST_F(LdbCmdTest, UnsafeRemoveSstFile) {
for (auto& h : handles) {
delete h;
}
delete db;
db.reset();
}
TEST_F(LdbCmdTest, FileTemperatureUpdateManifest) {
@@ -1078,7 +1074,7 @@ TEST_F(LdbCmdTest, FileTemperatureUpdateManifest) {
opts.create_if_missing = true;
opts.env = env.get();
DB* db = nullptr;
std::unique_ptr<DB> db;
std::string dbname = test::PerThreadDBPath(env.get(), "ldb_cmd_test");
ASSERT_OK(DestroyDB(dbname, opts));
ASSERT_OK(DB::Open(opts, dbname, &db));
@@ -1102,8 +1098,7 @@ TEST_F(LdbCmdTest, FileTemperatureUpdateManifest) {
}
// Close & reopen
delete db;
db = nullptr;
db.reset();
test_fs->PopRequestedSstFileTemperatures();
ASSERT_OK(DB::Open(opts, dbname, &db));
@@ -1122,8 +1117,7 @@ TEST_F(LdbCmdTest, FileTemperatureUpdateManifest) {
}
// Close for update_manifest
delete db;
db = nullptr;
db.reset();
char arg1[] = "./ldb";
char arg2[1024];
@@ -1151,7 +1145,7 @@ TEST_F(LdbCmdTest, FileTemperatureUpdateManifest) {
for (auto& r : requests) {
ASSERT_EQ(r.second, number_to_temp[r.first]);
}
delete db;
db.reset();
}
TEST_F(LdbCmdTest, RenameDbAndLoadOptions) {
@@ -1231,7 +1225,7 @@ TEST_F(LdbCmdTest, CustomComparator) {
opts.comparator = &my_comparator;
std::string dbname = test::PerThreadDBPath(env, "ldb_cmd_test");
DB* db = nullptr;
std::unique_ptr<DB> db;
std::vector<ColumnFamilyDescriptor> cfds = {
{kDefaultColumnFamilyName, opts}, {"cf1", opts}, {"cf2", opts}};
@@ -1243,7 +1237,7 @@ TEST_F(LdbCmdTest, CustomComparator) {
for (auto& h : handles) {
ASSERT_OK(db->DestroyColumnFamilyHandle(h));
}
delete db;
db.reset();
char arg1[] = "./ldb";
std::string arg2 = "--db=" + dbname;
+5 -6
View File
@@ -21,7 +21,7 @@ class ReduceLevelTest : public testing::Test {
ReduceLevelTest() {
dbname_ = test::PerThreadDBPath("db_reduce_levels_test");
EXPECT_OK(DestroyDB(dbname_, Options()));
db_ = nullptr;
db_.reset();
}
Status OpenDB(bool create_if_missing, int levels);
@@ -46,12 +46,12 @@ class ReduceLevelTest : public testing::Test {
if (db_ == nullptr) {
return Status::InvalidArgument("DB not opened.");
}
DBImpl* db_impl = static_cast_with_check<DBImpl>(db_);
DBImpl* db_impl = static_cast_with_check<DBImpl>(db_.get());
return db_impl->TEST_FlushMemTable();
}
void MoveL0FileToLevel(int level) {
DBImpl* db_impl = static_cast_with_check<DBImpl>(db_);
DBImpl* db_impl = static_cast_with_check<DBImpl>(db_.get());
for (int i = 0; i < level; ++i) {
ASSERT_OK(db_impl->TEST_CompactRange(i, nullptr, nullptr));
}
@@ -59,8 +59,7 @@ class ReduceLevelTest : public testing::Test {
void CloseDB() {
if (db_ != nullptr) {
delete db_;
db_ = nullptr;
db_.reset();
}
}
@@ -75,7 +74,7 @@ class ReduceLevelTest : public testing::Test {
private:
std::string dbname_;
DB* db_;
std::unique_ptr<DB> db_;
};
Status ReduceLevelTest::OpenDB(bool create_if_missing, int num_levels) {
+6 -5
View File
@@ -16,19 +16,20 @@
namespace ROCKSDB_NAMESPACE {
Status DefaultHooks::Open(const Options& db_options, const std::string& name,
DB** dbptr) {
std::unique_ptr<DB>* dbptr) {
return DB::Open(db_options, name, dbptr);
};
Status DefaultHooks::Open(
const DBOptions& db_options, const std::string& name,
const std::vector<ColumnFamilyDescriptor>& column_families,
std::vector<ColumnFamilyHandle*>* handles, DB** dbptr) {
std::vector<ColumnFamilyHandle*>* handles, std::unique_ptr<DB>* dbptr) {
return DB::Open(db_options, name, column_families, handles, dbptr);
};
Status DefaultHooks::OpenForReadOnly(const Options& options,
const std::string& name, DB** dbptr,
const std::string& name,
std::unique_ptr<DB>* dbptr,
bool error_if_wal_file_exists = false) {
return DB::OpenForReadOnly(options, name, dbptr, error_if_wal_file_exists);
};
@@ -36,7 +37,7 @@ Status DefaultHooks::OpenForReadOnly(const Options& options,
Status DefaultHooks::OpenForReadOnly(
const Options& options, const std::string& name,
const std::vector<ColumnFamilyDescriptor>& column_families,
std::vector<ColumnFamilyHandle*>* handles, DB** dbptr) {
std::vector<ColumnFamilyHandle*>* handles, std::unique_ptr<DB>* dbptr) {
return DB::OpenForReadOnly(options, name, column_families, handles, dbptr);
};
Status DefaultHooks::OpenTransactionDB(
@@ -72,7 +73,7 @@ Status DefaultHooks::OpenOptimisticTransactionDB(
Status DefaultHooks::OpenAsSecondary(const Options& options,
const std::string& name,
const std::string& secondary_path,
DB** dbptr) {
std::unique_ptr<DB>* dbptr) {
return DB::OpenAsSecondary(options, name, secondary_path, dbptr);
}
Status DefaultHooks::OpenAsFollower(const Options& options,
+4 -4
View File
@@ -69,7 +69,7 @@ class TraceAnalyzerTest : public testing::Test {
ro.iterate_lower_bound = &lower_bound;
WriteOptions wo;
TraceOptions trace_opt;
DB* db_ = nullptr;
std::unique_ptr<DB> db_;
std::string value;
std::unique_ptr<TraceWriter> trace_writer;
Iterator* single_iter = nullptr;
@@ -125,7 +125,7 @@ class TraceAnalyzerTest : public testing::Test {
ASSERT_OK(env_->NewWritableFile(whole_path, &whole_f, env_options_));
std::string whole_str = "0x61\n0x62\n0x63\n0x64\n0x65\n0x66\n";
ASSERT_OK(whole_f->Append(whole_str));
delete db_;
db_.reset();
ASSERT_OK(DestroyDB(dbname_, options));
}
@@ -786,7 +786,7 @@ TEST_F(TraceAnalyzerTest, Iterator) {
}
TEST_F(TraceAnalyzerTest, ExistsPreviousTraceWriteError) {
DB* db_ = nullptr;
std::unique_ptr<DB> db_;
Options options;
options.create_if_missing = true;
@@ -823,7 +823,7 @@ TEST_F(TraceAnalyzerTest, ExistsPreviousTraceWriteError) {
ASSERT_TRUE(s.ToString().find("Tracing has seen error") != std::string::npos);
ASSERT_TRUE(s.ToString().find("Injected") != std::string::npos);
delete db_;
db_.reset();
ASSERT_OK(DestroyDB(dbname_, options));
}
+1 -3
View File
@@ -145,13 +145,11 @@ class WriteStress {
}
// open DB
DB* db;
Status s = DB::Open(options, FLAGS_db, &db);
Status s = DB::Open(options, FLAGS_db, &db_);
if (!s.ok()) {
fprintf(stderr, "Can't open database: %s\n", s.ToString().c_str());
std::abort();
}
db_.reset(db);
}
void WriteThread() {
@@ -0,0 +1,2 @@
* Remove deprecated raw `DB*` variants of `DB::Open` and related functions. Some other minor public APIs were updated as a result
* Remove deprecated `DB::MaxMemCompactionLevel()`
+5 -7
View File
@@ -49,7 +49,7 @@ class SliceTransformDBTest : public testing::Test {
private:
std::string dbname_;
Env* env_;
DB* db_;
std::unique_ptr<DB> db_;
public:
SliceTransformDBTest() : env_(Env::Default()), db_(nullptr) {
@@ -58,11 +58,11 @@ class SliceTransformDBTest : public testing::Test {
}
~SliceTransformDBTest() override {
delete db_;
db_.reset();
EXPECT_OK(DestroyDB(dbname_, last_options_));
}
DB* db() { return db_; }
DB* db() { return db_.get(); }
// Return the current option configuration.
Options* GetOptions() { return &last_options_; }
@@ -74,14 +74,12 @@ class SliceTransformDBTest : public testing::Test {
}
void Destroy() {
delete db_;
db_ = nullptr;
db_.reset();
ASSERT_OK(DestroyDB(dbname_, last_options_));
}
Status TryReopen() {
delete db_;
db_ = nullptr;
db_.reset();
last_options_.create_if_missing = true;
return DB::Open(last_options_, dbname_, &db_);
+64 -75
View File
@@ -758,8 +758,8 @@ class BackupEngineTest : public testing::Test {
ASSERT_OK(CreateLoggerFromOptions(dbname_, logger_options, &logger_));
}
DB* OpenDB() {
DB* db;
std::unique_ptr<DB> OpenDB() {
std::unique_ptr<DB> db;
EXPECT_OK(DB::Open(options_, dbname_, &db));
return db;
}
@@ -770,13 +770,11 @@ class BackupEngineTest : public testing::Test {
// Open DB
test_db_fs_->SetLimitWrittenFiles(1000000);
DB* db;
if (read_only) {
ASSERT_OK(DB::OpenForReadOnly(options_, dbname_, &db));
ASSERT_OK(DB::OpenForReadOnly(options_, dbname_, &db_));
} else {
ASSERT_OK(DB::Open(options_, dbname_, &db));
ASSERT_OK(DB::Open(options_, dbname_, &db_));
}
db_.reset(db);
}
void InitializeDBAndBackupEngine(bool dummy = false) {
@@ -784,14 +782,12 @@ class BackupEngineTest : public testing::Test {
test_db_fs_->SetLimitWrittenFiles(1000000);
test_db_fs_->SetDummySequentialFile(dummy);
DB* db;
if (dummy) {
dummy_db_ = new DummyDB(options_, dbname_);
db = dummy_db_;
db_.reset(dummy_db_);
} else {
ASSERT_OK(DB::Open(options_, dbname_, &db));
ASSERT_OK(DB::Open(options_, dbname_, &db_));
}
db_.reset(db);
}
virtual void OpenDBAndBackupEngine(
@@ -914,13 +910,13 @@ class BackupEngineTest : public testing::Test {
ASSERT_OK(backup_engine_->RestoreDBFromLatestBackup(dbname_, dbname_,
restore_options));
}
DB* db = OpenDB();
auto db = OpenDB();
// Check DB contents
AssertExists(db, start_exist, end_exist);
AssertExists(db.get(), start_exist, end_exist);
if (end != 0) {
AssertEmpty(db, end_exist, end);
AssertEmpty(db.get(), end_exist, end);
}
delete db;
db.reset();
if (opened_backup_engine) {
CloseBackupEngine();
}
@@ -1063,6 +1059,7 @@ class BackupEngineTest : public testing::Test {
// all the dbs!
DummyDB* dummy_db_; // owned as db_ when present
std::unique_ptr<DB> db_;
DBImpl* dbfull() { return static_cast_with_check<DBImpl>(db_.get()); }
std::unique_ptr<BackupEngine> backup_engine_;
// options
@@ -1203,7 +1200,7 @@ TEST_F(BackupEngineTest, IncrementalRestore) {
// Since we started with a blank db, restore copied all the files.
test_db_fs_->AssertWrittenFiles(all_files);
db_.reset(OpenDB());
db_ = OpenDB();
// Check DB contents.
AssertExists(db_.get(), 0, keys_iteration * 2);
@@ -1255,7 +1252,7 @@ TEST_F(BackupEngineTest, IncrementalRestore) {
test_db_fs_->AssertWrittenFiles(should_have_written);
// Check DB contents.
db_.reset(OpenDB());
db_ = OpenDB();
AssertExists(db_.get(), 0, keys_iteration * 2);
db_.reset(); // Close DB.
@@ -1307,7 +1304,7 @@ TEST_F(BackupEngineTest, IncrementalRestore) {
// 'Hole' has been patched, 'in-policy' db files were retained.
test_db_fs_->AssertWrittenFiles(should_have_written);
db_.reset(OpenDB());
db_ = OpenDB();
Status s = db_->VerifyChecksum();
// Check DB contents.
@@ -1424,9 +1421,9 @@ TEST_P(BackupEngineTestWithParam, OfflineIntegrationTest) {
DestroyDBWithoutCheck(dbname_, options_);
// ---- make sure it's empty ----
DB* db = OpenDB();
AssertEmpty(db, 0, fill_up_to);
delete db;
auto db = OpenDB();
AssertEmpty(db.get(), 0, fill_up_to);
db.reset();
// ---- restore the DB ----
OpenBackupEngine();
@@ -1478,9 +1475,9 @@ TEST_P(BackupEngineTestWithParam, OnlineIntegrationTest) {
DestroyDBWithoutCheck(dbname_, options_);
// ---- make sure it's empty ----
DB* db = OpenDB();
AssertEmpty(db, 0, max_key);
delete db;
auto db = OpenDB();
AssertEmpty(db.get(), 0, max_key);
db.reset();
// ---- restore every backup and verify all the data is there ----
OpenBackupEngine();
@@ -2091,10 +2088,9 @@ TEST_F(BackupEngineTest, FlushCompactDuringBackupCheckpoint) {
"BackupEngineTest::FlushCompactDuringBackupCheckpoint:Before");
FillDB(db_.get(), keys_iteration, 2 * keys_iteration);
ASSERT_OK(db_->Flush(FlushOptions()));
DBImpl* dbi = static_cast<DBImpl*>(db_.get());
ASSERT_OK(dbi->TEST_WaitForFlushMemTable());
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
ASSERT_OK(db_->CompactRange(CompactRangeOptions(), nullptr, nullptr));
ASSERT_OK(dbi->TEST_WaitForCompact());
ASSERT_OK(dbfull()->TEST_WaitForCompact());
TEST_SYNC_POINT(
"BackupEngineTest::FlushCompactDuringBackupCheckpoint:After");
}};
@@ -2141,7 +2137,7 @@ TEST_F(BackupEngineTest, BackupOptions) {
// Must reset() before reset(OpenDB()) again.
// Calling OpenDB() while *db_ is existing will cause LOCK issue
db_.reset();
db_.reset(OpenDB());
db_ = OpenDB();
ASSERT_OK(backup_engine_->CreateNewBackup(db_.get(), true));
ASSERT_OK(ROCKSDB_NAMESPACE::GetLatestOptionsFileName(db_->GetName(),
options_.env, &name));
@@ -2169,13 +2165,12 @@ TEST_F(BackupEngineTest, SetOptionsBackupRaceCondition) {
ROCKSDB_NAMESPACE::port::Thread setoptions_thread{[this]() {
TEST_SYNC_POINT(
"BackupEngineTest::SetOptionsBackupRaceCondition:BeforeSetOptions");
DBImpl* dbi = static_cast<DBImpl*>(db_.get());
// Change arbitrary option to trigger OPTIONS file deletion
ASSERT_OK(dbi->SetOptions(dbi->DefaultColumnFamily(),
ASSERT_OK(db_->SetOptions(db_->DefaultColumnFamily(),
{{"paranoid_file_checks", "false"}}));
ASSERT_OK(dbi->SetOptions(dbi->DefaultColumnFamily(),
ASSERT_OK(db_->SetOptions(db_->DefaultColumnFamily(),
{{"paranoid_file_checks", "true"}}));
ASSERT_OK(dbi->SetOptions(dbi->DefaultColumnFamily(),
ASSERT_OK(db_->SetOptions(db_->DefaultColumnFamily(),
{{"paranoid_file_checks", "false"}}));
TEST_SYNC_POINT(
"BackupEngineTest::SetOptionsBackupRaceCondition:AfterSetOptions");
@@ -2433,14 +2428,13 @@ TEST_F(BackupEngineTest, TableFileCorruptionBeforeIncremental) {
engine_options_->share_files_with_checksum_naming = option;
}
OpenDBAndBackupEngine(true, false, share);
DBImpl* dbi = static_cast<DBImpl*>(db_.get());
// A small SST file
ASSERT_OK(dbi->Put(WriteOptions(), "x", "y"));
ASSERT_OK(dbi->Flush(FlushOptions()));
ASSERT_OK(db_->Put(WriteOptions(), "x", "y"));
ASSERT_OK(db_->Flush(FlushOptions()));
// And a bigger one
ASSERT_OK(dbi->Put(WriteOptions(), "y", Random(42).RandomString(500)));
ASSERT_OK(dbi->Flush(FlushOptions()));
ASSERT_OK(dbi->TEST_WaitForFlushMemTable());
ASSERT_OK(db_->Put(WriteOptions(), "y", Random(42).RandomString(500)));
ASSERT_OK(db_->Flush(FlushOptions()));
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
CloseAndReopenDB(/*read_only*/ true);
std::vector<FileAttributes> table_files;
@@ -2485,9 +2479,8 @@ TEST_F(BackupEngineTest, TableFileCorruptionBeforeIncremental) {
db_.reset();
ASSERT_OK(backup_engine_->RestoreDBFromBackup(2, dbname_, dbname_));
{
DB* db = OpenDB();
auto db = OpenDB();
s = db->VerifyChecksum();
delete db;
}
if (option != kLegacyCrc32cAndFileSize && !corrupt_before_first_backup) {
// Second backup is OK because it used (uncorrupt) file from first
@@ -2529,11 +2522,10 @@ TEST_F(BackupEngineTest, TableFileCorruptionBeforeIncremental) {
TEST_F(BackupEngineTest, PropertiesBlockCorruptionIncremental) {
OpenDBAndBackupEngine(true, false, kShareWithChecksum);
DBImpl* dbi = static_cast<DBImpl*>(db_.get());
// A small SST file
ASSERT_OK(dbi->Put(WriteOptions(), "x", "y"));
ASSERT_OK(dbi->Flush(FlushOptions()));
ASSERT_OK(dbi->TEST_WaitForFlushMemTable());
ASSERT_OK(db_->Put(WriteOptions(), "x", "y"));
ASSERT_OK(db_->Flush(FlushOptions()));
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable());
ASSERT_OK(backup_engine_->CreateNewBackup(db_.get()));
@@ -3350,9 +3342,9 @@ TEST_F(BackupEngineTest, ReadOnlyBackupEngine) {
std::vector<std::string> should_have_written;
test_backup_fs_->AssertWrittenFiles(should_have_written);
DB* db = OpenDB();
AssertExists(db, 0, 200);
delete db;
auto db = OpenDB();
AssertExists(db.get(), 0, 200);
db.reset();
}
TEST_F(BackupEngineTest, OpenBackupAsReadOnlyDB) {
@@ -3385,7 +3377,7 @@ TEST_F(BackupEngineTest, OpenBackupAsReadOnlyDB) {
// Caution: DBOptions only holds a raw pointer to Env, so something else
// must keep it alive.
// Case 1: Keeping BackupEngine open suffices to keep Env alive
DB* db = nullptr;
std::unique_ptr<DB> db;
Options opts = options_;
// Ensure some key defaults are set
opts.wal_dir = "";
@@ -3397,11 +3389,10 @@ TEST_F(BackupEngineTest, OpenBackupAsReadOnlyDB) {
backup_info = BackupInfo();
ASSERT_OK(DB::OpenForReadOnly(opts, name, &db));
AssertExists(db, 0, 100);
AssertEmpty(db, 100, 200);
AssertExists(db.get(), 0, 100);
AssertEmpty(db.get(), 100, 200);
delete db;
db = nullptr;
db.reset();
// Case 2: Keeping BackupInfo alive rather than BackupEngine also suffices
ASSERT_OK(backup_engine_->GetBackupInfo(/*id*/ 2U, &backup_info,
@@ -3413,12 +3404,14 @@ TEST_F(BackupEngineTest, OpenBackupAsReadOnlyDB) {
// Note: keeping backup_info alive
ASSERT_OK(DB::OpenForReadOnly(opts, name, &db));
AssertExists(db, 0, 200);
delete db;
db = nullptr;
AssertExists(db.get(), 0, 200);
db.reset();
// Now try opening read-write and make sure it fails, for safety.
ASSERT_TRUE(DB::Open(opts, name, &db).IsIOError());
{
std::unique_ptr<DB> dbptr;
ASSERT_TRUE(DB::Open(opts, name, &dbptr).IsIOError());
}
}
TEST_F(BackupEngineTest, ProgressCallbackDuringBackup) {
@@ -3565,16 +3558,15 @@ TEST_F(BackupEngineTest, ChangeManifestDuringBackupCreation) {
// The last manifest roll would've already been cleaned up by the full scan
// that happens when CreateNewBackup invokes EnableFileDeletions. We need to
// trigger another roll to verify non-full scan purges stale manifests.
DBImpl* db_impl = static_cast_with_check<DBImpl>(db_.get());
std::string prev_manifest_path =
DescriptorFileName(dbname_, db_impl->TEST_Current_Manifest_FileNo());
DescriptorFileName(dbname_, dbfull()->TEST_Current_Manifest_FileNo());
FillDB(db_.get(), 0, 100, kAutoFlushOnly);
ASSERT_OK(db_chroot_env_->FileExists(prev_manifest_path));
ASSERT_OK(db_->Flush(FlushOptions()));
// Even though manual flush completed above, the background thread may not
// have finished its cleanup work. `TEST_WaitForBackgroundWork()` will wait
// until all the background thread's work has completed, including cleanup.
ASSERT_OK(db_impl->TEST_WaitForBackgroundWork());
ASSERT_OK(dbfull()->TEST_WaitForBackgroundWork());
ASSERT_TRUE(db_chroot_env_->FileExists(prev_manifest_path).IsNotFound());
CloseDBAndBackupEngine();
@@ -3940,7 +3932,7 @@ TEST_F(BackupEngineTest, Concurrency) {
// by doing it async and ensuring we either get OK or InvalidArgument
restore_verify_threads[i] =
std::thread([this, &db_opts, restore_db_dir, to_restore] {
DB* restored;
std::unique_ptr<DB> restored;
Status s;
for (;;) {
s = DB::Open(db_opts, restore_db_dir, &restored);
@@ -3956,10 +3948,9 @@ TEST_F(BackupEngineTest, Concurrency) {
}
}
int factor = std::min(static_cast<int>(to_restore), max_factor);
AssertExists(restored, 0, factor * keys_iteration);
AssertEmpty(restored, factor * keys_iteration,
AssertExists(restored.get(), 0, factor * keys_iteration);
AssertEmpty(restored.get(), factor * keys_iteration,
(factor + 1) * keys_iteration);
delete restored;
});
// (Ok now) Restore one of the backups, or "latest"
@@ -4418,14 +4409,13 @@ TEST_F(BackupEngineTest, FileTemperatures) {
kShareWithChecksum);
// generate a bottommost file (combined from 2) and a non-bottommost file
DBImpl* dbi = static_cast_with_check<DBImpl>(db_.get());
ASSERT_OK(db_->Put(WriteOptions(), "a", "val"));
ASSERT_OK(db_->Put(WriteOptions(), "c", "val"));
ASSERT_OK(db_->Flush(FlushOptions()));
ASSERT_OK(db_->Put(WriteOptions(), "b", "val"));
ASSERT_OK(db_->Put(WriteOptions(), "d", "val"));
ASSERT_OK(db_->Flush(FlushOptions()));
ASSERT_OK(dbi->TEST_WaitForCompact());
ASSERT_OK(dbfull()->TEST_WaitForCompact());
ASSERT_OK(db_->Put(WriteOptions(), "e", "val"));
ASSERT_OK(db_->Flush(FlushOptions()));
@@ -4583,7 +4573,7 @@ TEST_F(BackupEngineTest, ExcludeFiles) {
// Ensure each backup is same set of files
db_.reset();
DB* db = nullptr;
std::unique_ptr<DB> db;
ASSERT_OK(DB::OpenForReadOnly(options_, dbname_, &db));
// A callback that throws should cleanly fail the backup creation.
@@ -4593,12 +4583,12 @@ TEST_F(BackupEngineTest, ExcludeFiles) {
MaybeExcludeBackupFile* /*files_end*/) {
throw 42;
};
ASSERT_TRUE(backup_engine_->CreateNewBackup(cbo, db).IsAborted());
ASSERT_TRUE(backup_engine_->CreateNewBackup(cbo, db.get()).IsAborted());
cbo.exclude_files_callback = [](MaybeExcludeBackupFile* /*files_begin*/,
MaybeExcludeBackupFile* /*files_end*/) {
throw std::out_of_range("blah");
};
ASSERT_TRUE(backup_engine_->CreateNewBackup(cbo, db).IsAborted());
ASSERT_TRUE(backup_engine_->CreateNewBackup(cbo, db.get()).IsAborted());
// Include files only in given bucket, based on modulus and remainder
constexpr int modulus = 4;
@@ -4619,22 +4609,21 @@ TEST_F(BackupEngineTest, ExcludeFiles) {
BackupID first_id{};
BackupID last_alt_id{};
remainder = 0;
ASSERT_OK(backup_engine_->CreateNewBackup(cbo, db, &first_id));
ASSERT_OK(backup_engine_->CreateNewBackup(cbo, db.get(), &first_id));
AssertBackupInfoConsistency(/*allow excluded*/ true);
remainder = 1;
ASSERT_OK(alt_backup_engine->CreateNewBackup(cbo, db));
ASSERT_OK(alt_backup_engine->CreateNewBackup(cbo, db.get()));
AssertBackupInfoConsistency(/*allow excluded*/ true);
remainder = 2;
ASSERT_OK(backup_engine_->CreateNewBackup(cbo, db));
ASSERT_OK(backup_engine_->CreateNewBackup(cbo, db.get()));
AssertBackupInfoConsistency(/*allow excluded*/ true);
remainder = 3;
ASSERT_OK(alt_backup_engine->CreateNewBackup(cbo, db, &last_alt_id));
ASSERT_OK(alt_backup_engine->CreateNewBackup(cbo, db.get(), &last_alt_id));
AssertBackupInfoConsistency(/*allow excluded*/ true);
// Close DB
ASSERT_OK(db->Close());
delete db;
db = nullptr;
db.reset();
auto backup_engine = backup_engine_.get();
for (auto be_pair : {std::make_pair(backup_engine, alt_backup_engine),
@@ -4652,8 +4641,8 @@ TEST_F(BackupEngineTest, ExcludeFiles) {
// Check DB contents
db = OpenDB();
AssertExists(db, 0, keys_iteration);
delete db;
AssertExists(db.get(), 0, keys_iteration);
db.reset();
}
// Should still work after close and re-open
+8 -4
View File
@@ -113,9 +113,8 @@ Status BlobDBImpl::CloseImpl() {
// Close base DB before BlobDBImpl destructs to stop event listener and
// compaction filter call.
Status s = db_->Close();
// delete db_ anyway even if close failed.
delete db_;
// Reset pointers to avoid StackableDB delete the pointer again.
// Reset ownership to free the underlying DB.
shared_db_ptr_.reset();
db_ = nullptr;
db_impl_ = nullptr;
if (!s.ok()) {
@@ -202,7 +201,12 @@ Status BlobDBImpl::Open(std::vector<ColumnFamilyHandle*>* handles) {
// Open base db.
ColumnFamilyDescriptor cf_descriptor(kDefaultColumnFamilyName, cf_options_);
s = DB::Open(db_options_, dbname_, {cf_descriptor}, handles, &db_);
std::unique_ptr<DB> db;
s = DB::Open(db_options_, dbname_, {cf_descriptor}, handles, &db);
if (s.ok()) {
shared_db_ptr_ = std::move(db);
db_ = shared_db_ptr_.get();
}
if (!s.ok()) {
return s;
}
+4 -6
View File
@@ -829,16 +829,15 @@ TEST_F(BlobDBTest, MigrateFromPlainRocksDB) {
// Write to plain rocksdb.
Options options;
options.create_if_missing = true;
DB* db = nullptr;
std::unique_ptr<DB> db;
ASSERT_OK(DB::Open(options, dbname_, &db));
for (size_t i = 0; i < kNumIteration; i++) {
auto key_index = rnd.Next() % kNumKey;
std::string key = "key" + std::to_string(key_index);
PutRandom(db, key, &rnd, &data);
PutRandom(db.get(), key, &rnd, &data);
}
VerifyDB(db, data);
delete db;
db = nullptr;
VerifyDB(db.get(), data);
db.reset();
// Open as blob db. Verify it can read existing data.
Open();
@@ -868,7 +867,6 @@ TEST_F(BlobDBTest, MigrateFromPlainRocksDB) {
ASSERT_EQ(data[key], value);
}
}
delete db;
}
// Test to verify that a NoSpace IOError Status is returned on reaching
@@ -25,7 +25,7 @@ const std::string kDbName = test::PerThreadDBPath("cassandra_functional_test");
class CassandraStore {
public:
explicit CassandraStore(std::shared_ptr<DB> db)
explicit CassandraStore(UnownedPtr<DB> db)
: db_(db), write_option_(), get_option_() {
assert(db);
}
@@ -87,7 +87,7 @@ class CassandraStore {
}
private:
std::shared_ptr<DB> db_;
UnownedPtr<DB> db_;
WriteOptions write_option_;
ReadOptions get_option_;
@@ -122,8 +122,7 @@ class CassandraFunctionalTest : public testing::Test {
DestroyDB(kDbName, Options())); // Start each test with a fresh DB
}
std::shared_ptr<DB> OpenDb() {
DB* db;
std::unique_ptr<DB> OpenDb() {
Options options;
options.create_if_missing = true;
options.merge_operator.reset(
@@ -131,8 +130,9 @@ class CassandraFunctionalTest : public testing::Test {
auto* cf_factory = new TestCompactionFilterFactory(
purge_ttl_on_expiration_, gc_grace_period_in_seconds_);
options.compaction_filter_factory.reset(cf_factory);
std::unique_ptr<DB> db;
EXPECT_OK(DB::Open(options, kDbName, &db));
return std::shared_ptr<DB>(db);
return db;
}
bool purge_ttl_on_expiration_ = false;
@@ -142,7 +142,8 @@ class CassandraFunctionalTest : public testing::Test {
// THE TEST CASES BEGIN HERE
TEST_F(CassandraFunctionalTest, SimpleMergeTest) {
CassandraStore store(OpenDb());
auto db = OpenDb();
CassandraStore store(db.get());
int64_t now = time(nullptr);
store.Append(
@@ -190,7 +191,8 @@ constexpr int64_t kTestTimeoutSecs = 600;
TEST_F(CassandraFunctionalTest,
CompactionShouldConvertExpiredColumnsToTombstone) {
CassandraStore store(OpenDb());
auto db = OpenDb();
CassandraStore store(db.get());
int64_t now = time(nullptr);
store.Append(
@@ -232,7 +234,8 @@ TEST_F(CassandraFunctionalTest,
TEST_F(CassandraFunctionalTest,
CompactionShouldPurgeExpiredColumnsIfPurgeTtlIsOn) {
purge_ttl_on_expiration_ = true;
CassandraStore store(OpenDb());
auto db = OpenDb();
CassandraStore store(db.get());
int64_t now = time(nullptr);
store.Append(
@@ -271,7 +274,8 @@ TEST_F(CassandraFunctionalTest,
TEST_F(CassandraFunctionalTest,
CompactionShouldRemoveRowWhenAllColumnsExpiredIfPurgeTtlIsOn) {
purge_ttl_on_expiration_ = true;
CassandraStore store(OpenDb());
auto db = OpenDb();
CassandraStore store(db.get());
int64_t now = time(nullptr);
store.Append("k1", CreateTestRowValue({
@@ -296,7 +300,8 @@ TEST_F(CassandraFunctionalTest,
TEST_F(CassandraFunctionalTest,
CompactionShouldRemoveTombstoneExceedingGCGracePeriod) {
purge_ttl_on_expiration_ = true;
CassandraStore store(OpenDb());
auto db = OpenDb();
CassandraStore store(db.get());
int64_t now = time(nullptr);
store.Append("k1",
@@ -327,7 +332,8 @@ TEST_F(CassandraFunctionalTest,
TEST_F(CassandraFunctionalTest, CompactionShouldRemoveTombstoneFromPut) {
purge_ttl_on_expiration_ = true;
CassandraStore store(OpenDb());
auto db = OpenDb();
CassandraStore store(db.get());
int64_t now = time(nullptr);
store.Put("k1",
+46 -61
View File
@@ -46,7 +46,7 @@ class CheckpointTest : public testing::Test {
std::string dbname_;
std::string alternative_wal_dir_;
Env* env_;
DB* db_;
std::unique_ptr<DB> db_;
Options last_options_;
std::vector<ColumnFamilyHandle*> handles_;
std::string snapshot_name_;
@@ -65,7 +65,7 @@ class CheckpointTest : public testing::Test {
EXPECT_OK(DestroyDB(dbname_, delete_options));
// Destroy it for not alternative WAL dir is used.
EXPECT_OK(DestroyDB(dbname_, options));
db_ = nullptr;
db_.reset();
snapshot_name_ = test::PerThreadDBPath(env_, "snapshot");
std::string snapshot_tmp_name = snapshot_name_ + ".tmp";
EXPECT_OK(DestroyDB(snapshot_name_, options));
@@ -102,6 +102,8 @@ class CheckpointTest : public testing::Test {
DestroyDir(env_, export_path_).PermitUncheckedError();
}
DBImpl* dbfull() { return static_cast_with_check<DBImpl>(db_.get()); }
// Return the current option configuration.
Options CurrentOptions() {
Options options;
@@ -170,8 +172,7 @@ class CheckpointTest : public testing::Test {
delete h;
}
handles_.clear();
delete db_;
db_ = nullptr;
db_.reset();
}
void DestroyAndReopen(const Options& options) {
@@ -268,14 +269,12 @@ class CheckpointTest : public testing::Test {
TEST_F(CheckpointTest, GetSnapshotLink) {
for (uint64_t log_size_for_flush : {0, 1000000}) {
Options options;
DB* snapshotDB;
ReadOptions roptions;
std::string result;
Checkpoint* checkpoint;
options = CurrentOptions();
delete db_;
db_ = nullptr;
db_.reset();
ASSERT_OK(DestroyDB(dbname_, options));
// Create a database
@@ -284,7 +283,7 @@ TEST_F(CheckpointTest, GetSnapshotLink) {
std::string key = std::string("foo");
ASSERT_OK(Put(key, "v1"));
// Take a snapshot
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->CreateCheckpoint(snapshot_name_, log_size_for_flush));
ASSERT_OK(Put(key, "v2"));
ASSERT_EQ("v2", Get(key));
@@ -292,13 +291,12 @@ TEST_F(CheckpointTest, GetSnapshotLink) {
ASSERT_EQ("v2", Get(key));
// Open snapshot and verify contents while DB is running
options.create_if_missing = false;
std::unique_ptr<DB> snapshotDB;
ASSERT_OK(DB::Open(options, snapshot_name_, &snapshotDB));
ASSERT_OK(snapshotDB->Get(roptions, key, &result));
ASSERT_EQ("v1", result);
delete snapshotDB;
snapshotDB = nullptr;
delete db_;
db_ = nullptr;
snapshotDB.reset();
db_.reset();
// Destroy original DB
ASSERT_OK(DestroyDB(dbname_, options));
@@ -308,8 +306,7 @@ TEST_F(CheckpointTest, GetSnapshotLink) {
dbname_ = snapshot_name_;
ASSERT_OK(DB::Open(options, dbname_, &db_));
ASSERT_EQ("v1", Get(key));
delete db_;
db_ = nullptr;
db_.reset();
ASSERT_OK(DestroyDB(dbname_, options));
delete checkpoint;
@@ -335,7 +332,7 @@ TEST_F(CheckpointTest, CheckpointWithBlob) {
// Create a checkpoint
Checkpoint* checkpoint = nullptr;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
std::unique_ptr<Checkpoint> checkpoint_guard(checkpoint);
@@ -360,11 +357,9 @@ TEST_F(CheckpointTest, CheckpointWithBlob) {
// Make sure the checkpoint can be opened and the blob value read
options.create_if_missing = false;
DB* checkpoint_db = nullptr;
std::unique_ptr<DB> checkpoint_db;
ASSERT_OK(DB::Open(options, snapshot_name_, &checkpoint_db));
std::unique_ptr<DB> checkpoint_db_guard(checkpoint_db);
PinnableSlice value;
ASSERT_OK(checkpoint_db->Get(
ReadOptions(), checkpoint_db->DefaultColumnFamily(), key, &value));
@@ -393,7 +388,7 @@ TEST_F(CheckpointTest, ExportColumnFamilyWithLinks) {
ASSERT_OK(Put(key, "v1"));
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
// Export the Tables and verify
ASSERT_OK(checkpoint->ExportColumnFamily(db_->DefaultColumnFamily(),
@@ -427,7 +422,7 @@ TEST_F(CheckpointTest, ExportColumnFamilyWithLinks) {
ASSERT_OK(db_->Put(WriteOptions(), cfh_reverse_comp_, key, "v1"));
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
// Export the Tables and verify
ASSERT_OK(checkpoint->ExportColumnFamily(cfh_reverse_comp_, export_path_,
@@ -449,7 +444,7 @@ TEST_F(CheckpointTest, ExportColumnFamilyNegativeTest) {
ASSERT_OK(Put(key, "v1"));
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
// Export onto existing directory
ASSERT_OK(env_->CreateDirIfMissing(export_path_));
@@ -482,7 +477,6 @@ TEST_F(CheckpointTest, CheckpointCF) {
ASSERT_OK(Put(4, "four", "four"));
ASSERT_OK(Put(5, "five", "five"));
DB* snapshotDB;
ReadOptions roptions;
std::string result;
std::vector<ColumnFamilyHandle*> cphandles;
@@ -490,7 +484,7 @@ TEST_F(CheckpointTest, CheckpointCF) {
// Take a snapshot
ROCKSDB_NAMESPACE::port::Thread t([&]() {
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->CreateCheckpoint(snapshot_name_));
delete checkpoint;
});
@@ -519,6 +513,7 @@ TEST_F(CheckpointTest, CheckpointCF) {
for (size_t i = 0; i < cfs.size(); ++i) {
column_families.emplace_back(cfs[i], options);
}
std::unique_ptr<DB> snapshotDB;
ASSERT_OK(DB::Open(options, snapshot_name_, column_families, &cphandles,
&snapshotDB));
ASSERT_OK(snapshotDB->Get(roptions, cphandles[0], "Default", &result));
@@ -530,8 +525,7 @@ TEST_F(CheckpointTest, CheckpointCF) {
delete h;
}
cphandles.clear();
delete snapshotDB;
snapshotDB = nullptr;
snapshotDB.reset();
}
TEST_F(CheckpointTest, CheckpointCFNoFlush) {
@@ -545,7 +539,6 @@ TEST_F(CheckpointTest, CheckpointCFNoFlush) {
ASSERT_OK(Flush());
ASSERT_OK(Put(2, "two", "two"));
DB* snapshotDB;
ReadOptions roptions;
std::string result;
std::vector<ColumnFamilyHandle*> cphandles;
@@ -558,7 +551,7 @@ TEST_F(CheckpointTest, CheckpointCFNoFlush) {
});
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->CreateCheckpoint(snapshot_name_, 1000000));
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
@@ -577,6 +570,7 @@ TEST_F(CheckpointTest, CheckpointCFNoFlush) {
for (size_t i = 0; i < cfs.size(); ++i) {
column_families.emplace_back(cfs[i], options);
}
std::unique_ptr<DB> snapshotDB;
ASSERT_OK(DB::Open(options, snapshot_name_, column_families, &cphandles,
&snapshotDB));
ASSERT_OK(snapshotDB->Get(roptions, cphandles[0], "Default", &result));
@@ -589,8 +583,7 @@ TEST_F(CheckpointTest, CheckpointCFNoFlush) {
delete h;
}
cphandles.clear();
delete snapshotDB;
snapshotDB = nullptr;
snapshotDB.reset();
}
TEST_F(CheckpointTest, CurrentFileModifiedWhileCheckpointing) {
@@ -615,7 +608,7 @@ TEST_F(CheckpointTest, CurrentFileModifiedWhileCheckpointing) {
ROCKSDB_NAMESPACE::port::Thread t([&]() {
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->CreateCheckpoint(snapshot_name_));
delete checkpoint;
});
@@ -627,12 +620,10 @@ TEST_F(CheckpointTest, CurrentFileModifiedWhileCheckpointing) {
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
DB* snapshotDB;
// Successful Open() implies that CURRENT pointed to the manifest in the
// checkpoint.
std::unique_ptr<DB> snapshotDB;
ASSERT_OK(DB::Open(options, snapshot_name_, &snapshotDB));
delete snapshotDB;
snapshotDB = nullptr;
}
TEST_F(CheckpointTest, CurrentFileModifiedWhileCheckpointing2PC) {
@@ -752,7 +743,7 @@ TEST_F(CheckpointTest, CurrentFileModifiedWhileCheckpointing2PC) {
TEST_F(CheckpointTest, CheckpointInvalidDirectoryName) {
for (std::string checkpoint_dir : {"", "/", "////"}) {
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_TRUE(
checkpoint->CreateCheckpoint(checkpoint_dir).IsInvalidArgument());
delete checkpoint;
@@ -765,7 +756,7 @@ TEST_F(CheckpointTest, CheckpointWithParallelWrites) {
ASSERT_OK(Put("key1", "val1"));
port::Thread thread([this]() { ASSERT_OK(Put("key2", "val2")); });
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->CreateCheckpoint(snapshot_name_));
delete checkpoint;
thread.join();
@@ -816,24 +807,24 @@ TEST_P(CheckpointTestWithWalParams, CheckpointWithUnsyncedDataDropped) {
// * one active WAL, not synced
// with a single thread, so that we have at least one that can be hard
// linked, etc.
ASSERT_OK(static_cast_with_check<DBImpl>(db_)->PauseBackgroundWork());
ASSERT_OK(static_cast_with_check<DBImpl>(db_)->TEST_SwitchMemtable());
ASSERT_OK(dbfull()->PauseBackgroundWork());
ASSERT_OK(dbfull()->TEST_SwitchMemtable());
ASSERT_OK(db_->SyncWAL());
}
ASSERT_OK(Put("key2", "val2"));
if (GetLogSizeForFlush() > 0) {
ASSERT_OK(static_cast_with_check<DBImpl>(db_)->TEST_SwitchMemtable());
ASSERT_OK(dbfull()->TEST_SwitchMemtable());
}
ASSERT_OK(Put("key3", "val3"));
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->CreateCheckpoint(snapshot_name_, GetLogSizeForFlush()));
delete checkpoint;
ASSERT_OK(fault_fs->DropUnsyncedFileData());
// make sure it's openable even though whatever data that wasn't synced got
// dropped.
options.env = env_;
DB* snapshot_db;
std::unique_ptr<DB> snapshot_db;
ASSERT_OK(DB::Open(options, snapshot_name_, &snapshot_db));
ReadOptions read_opts;
std::string get_result;
@@ -843,9 +834,8 @@ TEST_P(CheckpointTestWithWalParams, CheckpointWithUnsyncedDataDropped) {
ASSERT_EQ("val2", get_result);
ASSERT_OK(snapshot_db->Get(read_opts, "key3", &get_result));
ASSERT_EQ("val3", get_result);
delete snapshot_db;
delete db_;
db_ = nullptr;
snapshot_db.reset();
db_.reset();
}
TEST_F(CheckpointTest, CheckpointReadOnlyDB) {
@@ -855,18 +845,17 @@ TEST_F(CheckpointTest, CheckpointReadOnlyDB) {
Options options = CurrentOptions();
ASSERT_OK(ReadOnlyReopen(options));
Checkpoint* checkpoint = nullptr;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->CreateCheckpoint(snapshot_name_));
delete checkpoint;
checkpoint = nullptr;
Close();
DB* snapshot_db = nullptr;
std::unique_ptr<DB> snapshot_db;
ASSERT_OK(DB::Open(options, snapshot_name_, &snapshot_db));
ReadOptions read_opts;
std::string get_result;
ASSERT_OK(snapshot_db->Get(read_opts, "foo", &get_result));
ASSERT_EQ("foo_value", get_result);
delete snapshot_db;
}
TEST_F(CheckpointTest, CheckpointWithLockWAL) {
@@ -876,7 +865,7 @@ TEST_F(CheckpointTest, CheckpointWithLockWAL) {
ASSERT_OK(db_->LockWAL());
Checkpoint* checkpoint = nullptr;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->CreateCheckpoint(snapshot_name_));
delete checkpoint;
checkpoint = nullptr;
@@ -884,13 +873,12 @@ TEST_F(CheckpointTest, CheckpointWithLockWAL) {
ASSERT_OK(db_->UnlockWAL());
Close();
DB* snapshot_db = nullptr;
std::unique_ptr<DB> snapshot_db;
ASSERT_OK(DB::Open(options, snapshot_name_, &snapshot_db));
ReadOptions read_opts;
std::string get_result;
ASSERT_OK(snapshot_db->Get(read_opts, "foo", &get_result));
ASSERT_EQ("foo_value", get_result);
delete snapshot_db;
}
TEST_F(CheckpointTest, CheckpointReadOnlyDBWithMultipleColumnFamilies) {
@@ -905,7 +893,7 @@ TEST_F(CheckpointTest, CheckpointReadOnlyDBWithMultipleColumnFamilies) {
{kDefaultColumnFamilyName, "pikachu", "eevee"}, options);
ASSERT_OK(s);
Checkpoint* checkpoint = nullptr;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->CreateCheckpoint(snapshot_name_));
delete checkpoint;
checkpoint = nullptr;
@@ -915,7 +903,7 @@ TEST_F(CheckpointTest, CheckpointReadOnlyDBWithMultipleColumnFamilies) {
{kDefaultColumnFamilyName, options},
{"pikachu", options},
{"eevee", options}};
DB* snapshot_db = nullptr;
std::unique_ptr<DB> snapshot_db;
std::vector<ColumnFamilyHandle*> snapshot_handles;
s = DB::Open(options, snapshot_name_, column_families, &snapshot_handles,
&snapshot_db);
@@ -932,7 +920,6 @@ TEST_F(CheckpointTest, CheckpointReadOnlyDBWithMultipleColumnFamilies) {
delete snapshot_h;
}
snapshot_handles.clear();
delete snapshot_db;
}
TEST_F(CheckpointTest, CheckpointWithDbPath) {
@@ -942,7 +929,7 @@ TEST_F(CheckpointTest, CheckpointWithDbPath) {
ASSERT_OK(Put("key1", "val1"));
ASSERT_OK(Flush());
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
// Currently not supported
ASSERT_TRUE(checkpoint->CreateCheckpoint(snapshot_name_).IsNotSupported());
delete checkpoint;
@@ -964,7 +951,7 @@ TEST_F(CheckpointTest, CheckpointWithArchievedLog) {
ASSERT_OK(Put("key2", std::string(1024, 'a')));
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
TEST_SYNC_POINT("CheckpointTest:CheckpointWithArchievedLog");
ASSERT_OK(checkpoint->CreateCheckpoint(snapshot_name_, 1024 * 1024));
// unflushed log size < 1024 * 1024 < total file size including archived log,
@@ -973,7 +960,7 @@ TEST_F(CheckpointTest, CheckpointWithArchievedLog) {
delete checkpoint;
checkpoint = nullptr;
DB* snapshot_db;
std::unique_ptr<DB> snapshot_db;
ASSERT_OK(DB::Open(options, snapshot_name_, &snapshot_db));
ReadOptions read_opts;
std::string get_result;
@@ -982,7 +969,6 @@ TEST_F(CheckpointTest, CheckpointWithArchievedLog) {
get_result.clear();
ASSERT_OK(snapshot_db->Get(read_opts, "key2", &get_result));
ASSERT_EQ(std::string(1024, 'a'), get_result);
delete snapshot_db;
}
class CheckpointDestroyTest : public CheckpointTest,
@@ -1013,7 +999,7 @@ TEST_P(CheckpointDestroyTest, DisableEnableSlowDeletion) {
ASSERT_EQ(NumTableFilesAtLevel(1), 2);
Checkpoint* checkpoint;
ASSERT_OK(Checkpoint::Create(db_, &checkpoint));
ASSERT_OK(Checkpoint::Create(db_.get(), &checkpoint));
ASSERT_OK(checkpoint->CreateCheckpoint(snapshot_name_));
delete checkpoint;
@@ -1023,7 +1009,7 @@ TEST_P(CheckpointDestroyTest, DisableEnableSlowDeletion) {
ASSERT_EQ(NumTableFilesAtLevel(0), 0);
ASSERT_EQ(NumTableFilesAtLevel(1), 2);
DB* snapshot_db;
std::unique_ptr<DB> snapshot_db;
ASSERT_OK(DB::Open(options, snapshot_name_, &snapshot_db));
ReadOptions read_opts;
std::string get_result;
@@ -1031,11 +1017,10 @@ TEST_P(CheckpointDestroyTest, DisableEnableSlowDeletion) {
ASSERT_EQ("a", get_result);
ASSERT_OK(snapshot_db->Get(read_opts, "bar", &get_result));
ASSERT_EQ("val9", get_result);
delete snapshot_db;
snapshot_db.reset();
// Make sure original obsolete files for hard linked files are all deleted.
DBImpl* db_impl = static_cast_with_check<DBImpl>(db_);
db_impl->TEST_DeleteObsoleteFiles();
dbfull()->TEST_DeleteObsoleteFiles();
auto sfm = static_cast_with_check<SstFileManagerImpl>(
options.sst_file_manager.get());
ASSERT_NE(nullptr, sfm);

Some files were not shown because too many files have changed in this diff Show More