[CF] Add full_options_ to ColumnFamilyData

Summary:
Lots of code expects Options on construction/function call. My original idea was to split Options argument into ColumnFamilyOptions and DBOptions (the latter only if needed). However, this will require huge code changes very deep in the stack.

The better idea is to have ColumnFamilyData hold both ColumnFamilyOptions and Options. ColumnFamilyData::Options would be constructed from DBOptions (same for each column family) and ColumnFamilyOptions (different for each column family)

Now when we construct a class or call any method that requires Options, we can just push him ColumnFamilyData::Options and be sure that it's using column-family-specific settings.

Test Plan: make check

Reviewers: dhruba, haobo, kailiu, sdong

CC: leveldb

Differential Revision: https://reviews.facebook.net/D15927
main
Igor Canadi 11 years ago
parent 328ac7ee02
commit 6e56ab5702
  1. 11
      db/column_family.cc
  2. 6
      db/column_family.h
  3. 5
      db/repair.cc
  4. 22
      db/table_cache.cc
  5. 6
      db/table_cache.h

@ -142,6 +142,7 @@ ColumnFamilyData::ColumnFamilyData(const std::string& dbname, uint32_t id,
internal_filter_policy_(options.filter_policy), internal_filter_policy_(options.filter_policy),
options_(SanitizeOptions(&internal_comparator_, &internal_filter_policy_, options_(SanitizeOptions(&internal_comparator_, &internal_filter_policy_,
options)), options)),
full_options_(DBOptions(*db_options), options_),
mem_(nullptr), mem_(nullptr),
imm_(options.min_write_buffer_number_to_merge), imm_(options.min_write_buffer_number_to_merge),
super_version_(nullptr), super_version_(nullptr),
@ -150,12 +151,12 @@ ColumnFamilyData::ColumnFamilyData(const std::string& dbname, uint32_t id,
prev_(nullptr), prev_(nullptr),
log_number_(0), log_number_(0),
need_slowdown_for_num_level0_files_(false) { need_slowdown_for_num_level0_files_(false) {
// if db_options is nullptr, then this is a dummy column family. // if dummy_versions is nullptr, then this is a dummy column family.
if (db_options != nullptr) { if (dummy_versions != nullptr) {
internal_stats_.reset(new InternalStats(options.num_levels, db_options->env, internal_stats_.reset(new InternalStats(options.num_levels, db_options->env,
db_options->statistics.get())); db_options->statistics.get()));
table_cache_.reset(new TableCache(dbname, db_options, &options_, table_cache_.reset(
storage_options, table_cache)); new TableCache(dbname, &full_options_, storage_options, table_cache));
if (options_.compaction_style == kCompactionStyleUniversal) { if (options_.compaction_style == kCompactionStyleUniversal) {
compaction_picker_.reset(new UniversalCompactionPicker( compaction_picker_.reset(new UniversalCompactionPicker(
&options_, &internal_comparator_, db_options->info_log.get())); &options_, &internal_comparator_, db_options->info_log.get()));
@ -241,7 +242,7 @@ ColumnFamilySet::ColumnFamilySet(const std::string& dbname,
Cache* table_cache) Cache* table_cache)
: max_column_family_(0), : max_column_family_(0),
dummy_cfd_(new ColumnFamilyData(dbname, 0, "", nullptr, nullptr, dummy_cfd_(new ColumnFamilyData(dbname, 0, "", nullptr, nullptr,
ColumnFamilyOptions(), nullptr, ColumnFamilyOptions(), db_options,
storage_options_)), storage_options_)),
db_name_(dbname), db_name_(dbname),
db_options_(db_options), db_options_(db_options),

@ -73,7 +73,8 @@ class ColumnFamilyData {
void SetLogNumber(uint64_t log_number) { log_number_ = log_number; } void SetLogNumber(uint64_t log_number) { log_number_ = log_number; }
uint64_t GetLogNumber() const { return log_number_; } uint64_t GetLogNumber() const { return log_number_; }
ColumnFamilyOptions* options() { return &options_; } const ColumnFamilyOptions* options() const { return &options_; }
const Options* full_options() const { return &full_options_; }
InternalStats* internal_stats(); InternalStats* internal_stats();
MemTableList* imm() { return &imm_; } MemTableList* imm() { return &imm_; }
@ -137,7 +138,8 @@ class ColumnFamilyData {
const InternalKeyComparator internal_comparator_; const InternalKeyComparator internal_comparator_;
const InternalFilterPolicy internal_filter_policy_; const InternalFilterPolicy internal_filter_policy_;
ColumnFamilyOptions options_; ColumnFamilyOptions const options_;
Options const full_options_;
std::unique_ptr<TableCache> table_cache_; std::unique_ptr<TableCache> table_cache_;

@ -55,15 +55,14 @@ class Repairer {
icmp_(options.comparator), icmp_(options.comparator),
ipolicy_(options.filter_policy), ipolicy_(options.filter_policy),
options_(SanitizeOptions(dbname, &icmp_, &ipolicy_, options)), options_(SanitizeOptions(dbname, &icmp_, &ipolicy_, options)),
cf_options_(ColumnFamilyOptions(options_)),
raw_table_cache_( raw_table_cache_(
// TableCache can be small since we expect each table to be opened // TableCache can be small since we expect each table to be opened
// once. // once.
NewLRUCache(10, options_.table_cache_numshardbits, NewLRUCache(10, options_.table_cache_numshardbits,
options_.table_cache_remove_scan_count_limit)), options_.table_cache_remove_scan_count_limit)),
next_file_number_(1) { next_file_number_(1) {
table_cache_ = new TableCache(dbname_, &options_, &cf_options_, table_cache_ = new TableCache(dbname_, &options_, storage_options_,
storage_options_, raw_table_cache_.get()); raw_table_cache_.get());
edit_ = new VersionEdit(); edit_ = new VersionEdit();
} }

@ -35,13 +35,11 @@ static Slice GetSliceForFileNumber(uint64_t* file_number) {
} }
// TODO(icanadi) Options -> DBOptions // TODO(icanadi) Options -> DBOptions
TableCache::TableCache(const std::string& dbname, const Options* db_options, TableCache::TableCache(const std::string& dbname, const Options* options,
const ColumnFamilyOptions* cf_options,
const EnvOptions& storage_options, Cache* const cache) const EnvOptions& storage_options, Cache* const cache)
: env_(db_options->env), : env_(options->env),
dbname_(dbname), dbname_(dbname),
db_options_(db_options), options_(options),
cf_options_(cf_options),
storage_options_(storage_options), storage_options_(storage_options),
cache_(cache) {} cache_(cache) {}
@ -66,21 +64,19 @@ Status TableCache::FindTable(const EnvOptions& toptions,
unique_ptr<RandomAccessFile> file; unique_ptr<RandomAccessFile> file;
unique_ptr<TableReader> table_reader; unique_ptr<TableReader> table_reader;
s = env_->NewRandomAccessFile(fname, &file, toptions); s = env_->NewRandomAccessFile(fname, &file, toptions);
RecordTick(db_options_->statistics.get(), NO_FILE_OPENS); RecordTick(options_->statistics.get(), NO_FILE_OPENS);
if (s.ok()) { if (s.ok()) {
if (db_options_->advise_random_on_open) { if (options_->advise_random_on_open) {
file->Hint(RandomAccessFile::RANDOM); file->Hint(RandomAccessFile::RANDOM);
} }
StopWatch sw(env_, db_options_->statistics.get(), TABLE_OPEN_IO_MICROS); StopWatch sw(env_, options_->statistics.get(), TABLE_OPEN_IO_MICROS);
// TODO(icanadi) terrible hack. fix this s = options_->table_factory->GetTableReader(
Options options(DBOptions(*db_options_), *cf_options_); *options_, toptions, std::move(file), file_size, &table_reader);
s = cf_options_->table_factory->GetTableReader(
options, toptions, std::move(file), file_size, &table_reader);
} }
if (!s.ok()) { if (!s.ok()) {
assert(table_reader == nullptr); assert(table_reader == nullptr);
RecordTick(db_options_->statistics.get(), NO_FILE_ERRORS); RecordTick(options_->statistics.get(), NO_FILE_ERRORS);
// We do not cache error results so that if the error is transient, // We do not cache error results so that if the error is transient,
// or somebody repairs the file, we recover automatically. // or somebody repairs the file, we recover automatically.
} else { } else {

@ -24,8 +24,7 @@ class Env;
class TableCache { class TableCache {
public: public:
TableCache(const std::string& dbname, const Options* db_options, TableCache(const std::string& dbname, const Options* options,
const ColumnFamilyOptions* cf_options,
const EnvOptions& storage_options, Cache* cache); const EnvOptions& storage_options, Cache* cache);
~TableCache(); ~TableCache();
@ -67,8 +66,7 @@ class TableCache {
private: private:
Env* const env_; Env* const env_;
const std::string dbname_; const std::string dbname_;
const Options* db_options_; const Options* options_;
const ColumnFamilyOptions* cf_options_;
const EnvOptions& storage_options_; const EnvOptions& storage_options_;
Cache* const cache_; Cache* const cache_;

Loading…
Cancel
Save