From 5e2c4fe766064ce4b37af325b9039081c16fe95e Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Mon, 3 Feb 2014 17:48:07 -0800 Subject: [PATCH] Get rid of DBImpl::user_comparator() Summary: user_comparator() is a Column Family property, not DBImpl Test Plan: make check Reviewers: dhruba, haobo, kailiu, sdong CC: leveldb Differential Revision: https://reviews.facebook.net/D15855 --- db/db_impl.cc | 34 +++++++++++++++++----------------- db/db_impl.h | 8 ++------ db/db_impl_readonly.cc | 2 +- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index 763b89276..f32ab72d7 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -261,7 +261,6 @@ DBImpl::DBImpl(const Options& options, const std::string& dbname) options_(SanitizeOptions(dbname, &internal_comparator_, &internal_filter_policy_, options)), internal_filter_policy_(options.filter_policy), - owns_info_log_(options_.info_log != options.info_log), db_lock_(nullptr), mutex_(options.use_adaptive_mutex), shutting_down_(nullptr), @@ -377,7 +376,7 @@ uint64_t DBImpl::TEST_Current_Manifest_FileNo() { Status DBImpl::NewDB() { VersionEdit new_db; - new_db.SetComparatorName(user_comparator()->Name()); + new_db.SetComparatorName(internal_comparator_.user_comparator()->Name()); new_db.SetLogNumber(0); new_db.SetNextFile(2); new_db.SetLastSequence(0); @@ -989,7 +988,7 @@ Status DBImpl::RecoverLogFile(uint64_t log_number, SequenceNumber* max_sequence, auto iter = version_edits.find(cfd->GetID()); assert(iter != version_edits.end()); VersionEdit* edit = &iter->second; - status = WriteLevel0TableForRecovery(cfd->mem(), edit); + status = WriteLevel0TableForRecovery(cfd, cfd->mem(), edit); // we still want to clear the memtable, even if the recovery failed cfd->CreateNewMemtable(); if (!status.ok()) { @@ -1020,7 +1019,7 @@ Status DBImpl::RecoverLogFile(uint64_t log_number, SequenceNumber* max_sequence, // flush the final memtable (if non-empty) if (cfd->mem()->GetFirstSequenceNumber() != 0) { - status = WriteLevel0TableForRecovery(cfd->mem(), edit); + status = WriteLevel0TableForRecovery(cfd, cfd->mem(), edit); } // we still want to clear the memtable, even if the recovery failed cfd->CreateNewMemtable(); @@ -1051,7 +1050,8 @@ Status DBImpl::RecoverLogFile(uint64_t log_number, SequenceNumber* max_sequence, return status; } -Status DBImpl::WriteLevel0TableForRecovery(MemTable* mem, VersionEdit* edit) { +Status DBImpl::WriteLevel0TableForRecovery(ColumnFamilyData* cfd, MemTable* mem, + VersionEdit* edit) { mutex_.AssertHeld(); const uint64_t start_micros = env_->NowMicros(); FileMetaData meta; @@ -1068,9 +1068,8 @@ Status DBImpl::WriteLevel0TableForRecovery(MemTable* mem, VersionEdit* edit) { { mutex_.Unlock(); s = BuildTable(dbname_, env_, options_, storage_options_, - table_cache_.get(), iter, &meta, - user_comparator(), newest_snapshot, - earliest_seqno_in_memtable, + table_cache_.get(), iter, &meta, cfd->user_comparator(), + newest_snapshot, earliest_seqno_in_memtable, GetCompressionFlush(options_)); LogFlush(options_.info_log); mutex_.Lock(); @@ -1134,9 +1133,9 @@ Status DBImpl::WriteLevel0Table(ColumnFamilyData* cfd, (unsigned long)meta.number); s = BuildTable(dbname_, env_, options_, storage_options_, - table_cache_.get(), iter, &meta, - user_comparator(), newest_snapshot, - earliest_seqno_in_memtable, GetCompressionFlush(options_)); + table_cache_.get(), iter, &meta, cfd->user_comparator(), + newest_snapshot, earliest_seqno_in_memtable, + GetCompressionFlush(options_)); LogFlush(options_.info_log); delete iter; Log(options_.info_log, "Level-0 flush table #%lu: %lu bytes %s", @@ -2339,7 +2338,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact, SequenceNumber visible_in_snapshot = kMaxSequenceNumber; std::string compaction_filter_value; std::vector delete_key; // for compaction filter - MergeHelper merge(user_comparator(), options_.merge_operator.get(), + MergeHelper merge(cfd->user_comparator(), options_.merge_operator.get(), options_.info_log.get(), false /* internal key corruption is expected */); auto compaction_filter = cfd->options()->compaction_filter; @@ -2390,8 +2389,8 @@ Status DBImpl::DoCompactionWork(CompactionState* compact, visible_in_snapshot = kMaxSequenceNumber; } else { if (!has_current_user_key || - user_comparator()->Compare(ikey.user_key, - Slice(current_user_key)) != 0) { + cfd->user_comparator()->Compare(ikey.user_key, + Slice(current_user_key)) != 0) { // First occurrence of this user key current_user_key.assign(ikey.user_key.data(), ikey.user_key.size()); has_current_user_key = true; @@ -2759,7 +2758,7 @@ std::pair DBImpl::GetTailingIteratorPair( Iterator* mutable_iter = super_version->mem->NewIterator(options); // create a DBIter that only uses memtable content; see NewIterator() - mutable_iter = NewDBIterator(&dbname_, env_, options_, user_comparator(), + mutable_iter = NewDBIterator(&dbname_, env_, options_, cfd->user_comparator(), mutable_iter, kMaxSequenceNumber); std::vector list; @@ -2769,8 +2768,9 @@ std::pair DBImpl::GetTailingIteratorPair( NewMergingIterator(&cfd->internal_comparator(), &list[0], list.size()); // create a DBIter that only uses memtable content; see NewIterator() - immutable_iter = NewDBIterator(&dbname_, env_, options_, user_comparator(), - immutable_iter, kMaxSequenceNumber); + immutable_iter = + NewDBIterator(&dbname_, env_, options_, cfd->user_comparator(), + immutable_iter, kMaxSequenceNumber); // register cleanups mutable_iter->RegisterCleanup(CleanupIteratorState, diff --git a/db/db_impl.h b/db/db_impl.h index 7fb18880b..e886256ce 100644 --- a/db/db_impl.h +++ b/db/db_impl.h @@ -253,10 +253,6 @@ class DBImpl : public DB { const InternalKeyComparator internal_comparator_; const Options options_; // options_.comparator == &internal_comparator_ - const Comparator* user_comparator() const { - return internal_comparator_.user_comparator(); - } - Iterator* NewInternalIterator(const ReadOptions&, ColumnFamilyData* cfd, SuperVersion* super_version); @@ -294,7 +290,8 @@ class DBImpl : public DB { // database is opened) and is heavyweight because it holds the mutex // for the entire period. The second method WriteLevel0Table supports // concurrent flush memtables to storage. - Status WriteLevel0TableForRecovery(MemTable* mem, VersionEdit* edit); + Status WriteLevel0TableForRecovery(ColumnFamilyData* cfd, MemTable* mem, + VersionEdit* edit); Status WriteLevel0Table(ColumnFamilyData* cfd, std::vector& mems, VersionEdit* edit, uint64_t* filenumber); @@ -375,7 +372,6 @@ class DBImpl : public DB { // Constant after construction const InternalFilterPolicy internal_filter_policy_; - bool owns_info_log_; // table_cache_ provides its own synchronization unique_ptr table_cache_; diff --git a/db/db_impl_readonly.cc b/db/db_impl_readonly.cc index 82d4b8cb0..84383833d 100644 --- a/db/db_impl_readonly.cc +++ b/db/db_impl_readonly.cc @@ -79,7 +79,7 @@ Iterator* DBImplReadOnly::NewIterator(const ReadOptions& options, SequenceNumber latest_snapshot = versions_->LastSequence(); Iterator* internal_iter = NewInternalIterator(options, cfd, super_version); return NewDBIterator( - &dbname_, env_, options_, user_comparator(), internal_iter, + &dbname_, env_, options_, cfd->user_comparator(), internal_iter, (options.snapshot != nullptr ? reinterpret_cast(options.snapshot)->number_ : latest_snapshot));