Skip to content

Commit

Permalink
Split DBOptions into ImmutableDBOptions and MutableDBOptions
Browse files Browse the repository at this point in the history
Summary: Use ImmutableDBOptions/MutableDBOptions internally and DBOptions only for user-facing APIs. MutableDBOptions is barely a placeholder for now. I'll start to move options to MutableDBOptions in following diffs.

Test Plan:
  make all check

Reviewers: yhchiang, IslamAbdelRahman, sdong

Reviewed By: sdong

Subscribers: andrewkr, dhruba, leveldb

Differential Revision: https://reviews.facebook.net/D64065
  • Loading branch information
Yi Wu committed Sep 23, 2016
1 parent 4bc8c88 commit 9ed928e
Show file tree
Hide file tree
Showing 46 changed files with 1,019 additions and 513 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ set(SOURCES
util/comparator.cc
util/concurrent_arena.cc
util/crc32c.cc
util/db_options.cc
util/delete_scheduler.cc
util/dynamic_bloom.cc
util/env.cc
Expand Down
36 changes: 18 additions & 18 deletions db/column_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ const Comparator* ColumnFamilyHandleImpl::GetComparator() const {
}

void GetIntTblPropCollectorFactory(
const ColumnFamilyOptions& cf_options,
const ImmutableCFOptions& ioptions,
std::vector<std::unique_ptr<IntTblPropCollectorFactory>>*
int_tbl_prop_collector_factories) {
auto& collector_factories = cf_options.table_properties_collector_factories;
for (size_t i = 0; i < cf_options.table_properties_collector_factories.size();
auto& collector_factories = ioptions.table_properties_collector_factories;
for (size_t i = 0; i < ioptions.table_properties_collector_factories.size();
++i) {
assert(collector_factories[i]);
int_tbl_prop_collector_factories->emplace_back(
Expand Down Expand Up @@ -138,7 +138,7 @@ Status CheckConcurrentWritesSupported(const ColumnFamilyOptions& cf_options) {
return Status::OK();
}

ColumnFamilyOptions SanitizeOptions(const DBOptions& db_options,
ColumnFamilyOptions SanitizeOptions(const ImmutableDBOptions& db_options,
const InternalKeyComparator* icmp,
const ColumnFamilyOptions& src) {
ColumnFamilyOptions result = src;
Expand Down Expand Up @@ -340,7 +340,7 @@ void SuperVersionUnrefHandle(void* ptr) {
ColumnFamilyData::ColumnFamilyData(
uint32_t id, const std::string& name, Version* _dummy_versions,
Cache* _table_cache, WriteBufferManager* write_buffer_manager,
const ColumnFamilyOptions& cf_options, const DBOptions* db_options,
const ColumnFamilyOptions& cf_options, const ImmutableDBOptions& db_options,
const EnvOptions& env_options, ColumnFamilySet* column_family_set)
: id_(id),
name_(name),
Expand All @@ -349,14 +349,14 @@ ColumnFamilyData::ColumnFamilyData(
refs_(0),
dropped_(false),
internal_comparator_(cf_options.comparator),
options_(*db_options,
SanitizeOptions(*db_options, &internal_comparator_, cf_options)),
ioptions_(options_),
mutable_cf_options_(options_),
initial_cf_options_(
SanitizeOptions(db_options, &internal_comparator_, cf_options)),
ioptions_(db_options, initial_cf_options_),
mutable_cf_options_(initial_cf_options_),
write_buffer_manager_(write_buffer_manager),
mem_(nullptr),
imm_(options_.min_write_buffer_number_to_merge,
options_.max_write_buffer_number_to_maintain),
imm_(ioptions_.min_write_buffer_number_to_merge,
ioptions_.max_write_buffer_number_to_maintain),
super_version_(nullptr),
super_version_number_(0),
local_sv_(new ThreadLocalPtr(&SuperVersionUnrefHandle)),
Expand All @@ -370,12 +370,12 @@ ColumnFamilyData::ColumnFamilyData(
Ref();

// Convert user defined table properties collector factories to internal ones.
GetIntTblPropCollectorFactory(options_, &int_tbl_prop_collector_factories_);
GetIntTblPropCollectorFactory(ioptions_, &int_tbl_prop_collector_factories_);

// if _dummy_versions is nullptr, then this is a dummy column family.
if (_dummy_versions != nullptr) {
internal_stats_.reset(
new InternalStats(ioptions_.num_levels, db_options->env, this));
new InternalStats(ioptions_.num_levels, db_options.env, this));
table_cache_.reset(new TableCache(ioptions_, env_options, _table_cache));
if (ioptions_.compaction_style == kCompactionStyleLevel) {
compaction_picker_.reset(
Expand Down Expand Up @@ -407,7 +407,7 @@ ColumnFamilyData::ColumnFamilyData(
if (column_family_set_->NumberOfColumnFamilies() < 10) {
Log(InfoLogLevel::INFO_LEVEL, ioptions_.info_log,
"--------------- Options for column family [%s]:\n", name.c_str());
options_.DumpCFOptions(ioptions_.info_log);
initial_cf_options_.Dump(ioptions_.info_log);
} else {
Log(InfoLogLevel::INFO_LEVEL, ioptions_.info_log,
"\t(skipping printing options)\n");
Expand Down Expand Up @@ -485,7 +485,7 @@ void ColumnFamilyData::SetDropped() {
}

ColumnFamilyOptions ColumnFamilyData::GetLatestCFOptions() const {
return BuildColumnFamilyOptions(options_, mutable_cf_options_);
return BuildColumnFamilyOptions(initial_cf_options_, mutable_cf_options_);
}

const double kSlowdownRatio = 1.2;
Expand Down Expand Up @@ -869,14 +869,14 @@ Status ColumnFamilyData::SetOptions(
#endif // ROCKSDB_LITE

ColumnFamilySet::ColumnFamilySet(const std::string& dbname,
const DBOptions* db_options,
const ImmutableDBOptions* db_options,
const EnvOptions& env_options,
Cache* table_cache,
WriteBufferManager* write_buffer_manager,
WriteController* write_controller)
: max_column_family_(0),
dummy_cfd_(new ColumnFamilyData(0, "", nullptr, nullptr, nullptr,
ColumnFamilyOptions(), db_options,
ColumnFamilyOptions(), *db_options,
env_options, nullptr)),
default_cfd_cache_(nullptr),
db_name_(dbname),
Expand Down Expand Up @@ -948,7 +948,7 @@ ColumnFamilyData* ColumnFamilySet::CreateColumnFamily(
assert(column_families_.find(name) == column_families_.end());
ColumnFamilyData* new_cfd = new ColumnFamilyData(
id, name, dummy_versions, table_cache_, write_buffer_manager_, options,
db_options_, env_options_, this);
*db_options_, env_options_, this);
column_families_.insert({name, id});
column_family_data_.insert({id, new_cfd});
max_column_family_ = std::max(max_column_family_, id);
Expand Down
14 changes: 8 additions & 6 deletions db/column_family.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ extern Status CheckCompressionSupported(const ColumnFamilyOptions& cf_options);
extern Status CheckConcurrentWritesSupported(
const ColumnFamilyOptions& cf_options);

extern ColumnFamilyOptions SanitizeOptions(const DBOptions& db_options,
extern ColumnFamilyOptions SanitizeOptions(const ImmutableDBOptions& db_options,
const InternalKeyComparator* icmp,
const ColumnFamilyOptions& src);
// Wrap user defined table proproties collector factories `from cf_options`
// into internal ones in int_tbl_prop_collector_factories. Add a system internal
// one too.
extern void GetIntTblPropCollectorFactory(
const ColumnFamilyOptions& cf_options,
const ImmutableCFOptions& ioptions,
std::vector<std::unique_ptr<IntTblPropCollectorFactory>>*
int_tbl_prop_collector_factories);

Expand Down Expand Up @@ -328,7 +328,8 @@ class ColumnFamilyData {
Version* dummy_versions, Cache* table_cache,
WriteBufferManager* write_buffer_manager,
const ColumnFamilyOptions& options,
const DBOptions* db_options, const EnvOptions& env_options,
const ImmutableDBOptions& db_options,
const EnvOptions& env_options,
ColumnFamilySet* column_family_set);

uint32_t id_;
Expand All @@ -343,7 +344,7 @@ class ColumnFamilyData {
std::vector<std::unique_ptr<IntTblPropCollectorFactory>>
int_tbl_prop_collector_factories_;

const Options options_;
const ColumnFamilyOptions initial_cf_options_;
const ImmutableCFOptions ioptions_;
MutableCFOptions mutable_cf_options_;

Expand Down Expand Up @@ -439,7 +440,8 @@ class ColumnFamilySet {
ColumnFamilyData* current_;
};

ColumnFamilySet(const std::string& dbname, const DBOptions* db_options,
ColumnFamilySet(const std::string& dbname,
const ImmutableDBOptions* db_options,
const EnvOptions& env_options, Cache* table_cache,
WriteBufferManager* write_buffer_manager,
WriteController* write_controller);
Expand Down Expand Up @@ -496,7 +498,7 @@ class ColumnFamilySet {
ColumnFamilyData* default_cfd_cache_;

const std::string db_name_;
const DBOptions* const db_options_;
const ImmutableDBOptions* const db_options_;
const EnvOptions env_options_;
Cache* table_cache_;
WriteBufferManager* write_buffer_manager_;
Expand Down
4 changes: 2 additions & 2 deletions db/column_family_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2178,8 +2178,8 @@ TEST_F(ColumnFamilyTest, SanitizeOptions) {
original.write_buffer_size =
l * 4 * 1024 * 1024 + i * 1024 * 1024 + j * 1024 + k;

ColumnFamilyOptions result =
SanitizeOptions(db_options, nullptr, original);
ColumnFamilyOptions result = SanitizeOptions(
ImmutableDBOptions(db_options), nullptr, original);
ASSERT_TRUE(result.level0_stop_writes_trigger >=
result.level0_slowdown_writes_trigger);
ASSERT_TRUE(result.level0_slowdown_writes_trigger >=
Expand Down
4 changes: 2 additions & 2 deletions db/compacted_db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ Status CompactedDBImpl::Open(const Options& options,
std::unique_ptr<CompactedDBImpl> db(new CompactedDBImpl(db_options, dbname));
Status s = db->Init(options);
if (s.ok()) {
Log(INFO_LEVEL, db->db_options_.info_log,
Log(INFO_LEVEL, db->immutable_db_options_.info_log,
"Opened the db as fully compacted mode");
LogFlush(db->db_options_.info_log);
LogFlush(db->immutable_db_options_.info_log);
*dbptr = db.release();
}
return s;
Expand Down
6 changes: 3 additions & 3 deletions db/compaction_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ void CompactionJob::AggregateStatistics() {
}

CompactionJob::CompactionJob(
int job_id, Compaction* compaction, const DBOptions& db_options,
int job_id, Compaction* compaction, const ImmutableDBOptions& db_options,
const EnvOptions& env_options, VersionSet* versions,
std::atomic<bool>* shutting_down, LogBuffer* log_buffer,
Directory* db_directory, Directory* output_directory, Statistics* stats,
Expand Down Expand Up @@ -539,7 +539,7 @@ Status CompactionJob::Run() {
thread.join();
}

if (output_directory_ && !db_options_.disableDataSync) {
if (output_directory_ && !db_options_.disable_data_sync) {
output_directory_->Fsync();
}

Expand Down Expand Up @@ -963,7 +963,7 @@ Status CompactionJob::FinishCompactionOutputFile(
sub_compact->total_bytes += current_bytes;

// Finish and check for file errors
if (s.ok() && !db_options_.disableDataSync) {
if (s.ok() && !db_options_.disable_data_sync) {
StopWatch sw(env_, stats_, COMPACTION_OUTFILE_SYNC_MICROS);
s = sub_compact->outfile->Sync(db_options_.use_fsync);
}
Expand Down
6 changes: 4 additions & 2 deletions db/compaction_job.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "rocksdb/transaction_log.h"
#include "table/scoped_arena_iterator.h"
#include "util/autovector.h"
#include "util/db_options.h"
#include "util/event_logger.h"
#include "util/stop_watch.h"
#include "util/thread_local.h"
Expand All @@ -52,7 +53,8 @@ class Arena;

class CompactionJob {
public:
CompactionJob(int job_id, Compaction* compaction, const DBOptions& db_options,
CompactionJob(int job_id, Compaction* compaction,
const ImmutableDBOptions& db_options,
const EnvOptions& env_options, VersionSet* versions,
std::atomic<bool>* shutting_down, LogBuffer* log_buffer,
Directory* db_directory, Directory* output_directory,
Expand Down Expand Up @@ -120,7 +122,7 @@ class CompactionJob {

// DBImpl state
const std::string& dbname_;
const DBOptions& db_options_;
const ImmutableDBOptions& db_options_;
const EnvOptions& env_options_;

Env* env_;
Expand Down
7 changes: 4 additions & 3 deletions db/compaction_job_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class CompactionJobTest : public testing::Test {
CompactionJobTest()
: env_(Env::Default()),
dbname_(test::TmpDir() + "/compaction_job_test"),
mutable_cf_options_(Options()),
db_options_(),
mutable_cf_options_(cf_options_),
table_cache_(NewLRUCache(50000, 16)),
write_buffer_manager_(db_options_.db_write_buffer_size),
versions_(new VersionSet(dbname_, &db_options_, env_options_,
Expand Down Expand Up @@ -280,11 +281,11 @@ class CompactionJobTest : public testing::Test {
Env* env_;
std::string dbname_;
EnvOptions env_options_;
ImmutableDBOptions db_options_;
ColumnFamilyOptions cf_options_;
MutableCFOptions mutable_cf_options_;
std::shared_ptr<Cache> table_cache_;
WriteController write_controller_;
DBOptions db_options_;
ColumnFamilyOptions cf_options_;
WriteBufferManager write_buffer_manager_;
std::unique_ptr<VersionSet> versions_;
InstrumentedMutex mutex_;
Expand Down
12 changes: 6 additions & 6 deletions db/db_filesnapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ Status DBImpl::DisableFileDeletions() {
InstrumentedMutexLock l(&mutex_);
++disable_delete_obsolete_files_;
if (disable_delete_obsolete_files_ == 1) {
Log(InfoLogLevel::INFO_LEVEL, db_options_.info_log,
Log(InfoLogLevel::INFO_LEVEL, immutable_db_options_.info_log,
"File Deletions Disabled");
} else {
Log(InfoLogLevel::WARN_LEVEL, db_options_.info_log,
Log(InfoLogLevel::WARN_LEVEL, immutable_db_options_.info_log,
"File Deletions Disabled, but already disabled. Counter: %d",
disable_delete_obsolete_files_);
}
Expand All @@ -59,12 +59,12 @@ Status DBImpl::EnableFileDeletions(bool force) {
--disable_delete_obsolete_files_;
}
if (disable_delete_obsolete_files_ == 0) {
Log(InfoLogLevel::INFO_LEVEL, db_options_.info_log,
Log(InfoLogLevel::INFO_LEVEL, immutable_db_options_.info_log,
"File Deletions Enabled");
should_purge_files = true;
FindObsoleteFiles(&job_context, true);
} else {
Log(InfoLogLevel::WARN_LEVEL, db_options_.info_log,
Log(InfoLogLevel::WARN_LEVEL, immutable_db_options_.info_log,
"File Deletions Enable, but not really enabled. Counter: %d",
disable_delete_obsolete_files_);
}
Expand All @@ -73,7 +73,7 @@ Status DBImpl::EnableFileDeletions(bool force) {
PurgeObsoleteFiles(job_context);
}
job_context.Clean();
LogFlush(db_options_.info_log);
LogFlush(immutable_db_options_.info_log);
return Status::OK();
}

Expand Down Expand Up @@ -110,7 +110,7 @@ Status DBImpl::GetLiveFiles(std::vector<std::string>& ret,

if (!status.ok()) {
mutex_.Unlock();
Log(InfoLogLevel::ERROR_LEVEL, db_options_.info_log,
Log(InfoLogLevel::ERROR_LEVEL, immutable_db_options_.info_log,
"Cannot Flush data %s\n", status.ToString().c_str());
return status;
}
Expand Down
Loading

0 comments on commit 9ed928e

Please sign in to comment.