Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cache/cache_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ class CacheTest : public testing::TestWithParam<std::string> {
&CacheTest::Deleter);
}

void Erase(std::shared_ptr<Cache> cache, int key) {
cache->Erase(EncodeKey(key));
bool Erase(std::shared_ptr<Cache> cache, int key) {
return cache->Erase(EncodeKey(key));
}

int Lookup(int key) { return Lookup(cache_, key); }
Expand All @@ -125,15 +125,15 @@ class CacheTest : public testing::TestWithParam<std::string> {
Insert(cache_, key, value, charge);
}

void Erase(int key) { Erase(cache_, key); }
bool Erase(int key) { return Erase(cache_, key); }

int Lookup2(int key) { return Lookup(cache2_, key); }

void Insert2(int key, int value, int charge = 1) {
Insert(cache2_, key, value, charge);
}

void Erase2(int key) { Erase(cache2_, key); }
bool Erase2(int key) { return Erase(cache2_, key); }
};
CacheTest* CacheTest::current_;

Expand Down
7 changes: 4 additions & 3 deletions cache/clock_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class ClockCacheShard : public CacheShard {
virtual bool Ref(Cache::Handle* handle) override;
virtual bool Release(Cache::Handle* handle,
bool force_erase = false) override;
virtual void Erase(const Slice& key, uint32_t hash) override;
virtual bool Erase(const Slice& key, uint32_t hash) override;
bool EraseAndConfirm(const Slice& key, uint32_t hash,
CleanupContext* context);
virtual size_t GetUsage() const override;
Expand Down Expand Up @@ -647,10 +647,11 @@ bool ClockCacheShard::Release(Cache::Handle* h, bool force_erase) {
return erased;
}

void ClockCacheShard::Erase(const Slice& key, uint32_t hash) {
bool ClockCacheShard::Erase(const Slice& key, uint32_t hash) {
CleanupContext context;
EraseAndConfirm(key, hash, &context);
bool ret = EraseAndConfirm(key, hash, &context);
Cleanup(context);
return ret;
}

bool ClockCacheShard::EraseAndConfirm(const Slice& key, uint32_t hash,
Expand Down
3 changes: 2 additions & 1 deletion cache/lirs_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ Status LIRSCacheShard::Insert(const Slice& key, uint32_t hash, void* value,
return s;
}

void LIRSCacheShard::Erase(const Slice& key, uint32_t hash) {
bool LIRSCacheShard::Erase(const Slice& key, uint32_t hash) {
LIRSHandle* e;
bool last_reference = false;
{
Expand All @@ -430,6 +430,7 @@ void LIRSCacheShard::Erase(const Slice& key, uint32_t hash) {
if (last_reference) {
e->Free();
}
return e != nullptr;
}

size_t LIRSCacheShard::GetUsage() const {
Expand Down
2 changes: 1 addition & 1 deletion cache/lirs_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ALIGN_AS(CACHE_LINE_SIZE) LIRSCacheShard : public CacheShard {
virtual bool Ref(Cache::Handle* handle) override;
virtual bool Release(Cache::Handle* handle,
bool force_erase = false) override;
virtual void Erase(const Slice& key, uint32_t hash) override;
virtual bool Erase(const Slice& key, uint32_t hash) override;

virtual size_t GetUsage() const override;
virtual size_t GetPinnedUsage() const override;
Expand Down
3 changes: 2 additions & 1 deletion cache/lru_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ Status LRUCacheShardTemplate<CacheMonitor>::Insert(
}

template <class CacheMonitor>
void LRUCacheShardTemplate<CacheMonitor>::Erase(const Slice& key,
bool LRUCacheShardTemplate<CacheMonitor>::Erase(const Slice& key,
uint32_t hash) {
LRUHandle* e;
bool last_reference = false;
Expand All @@ -462,6 +462,7 @@ void LRUCacheShardTemplate<CacheMonitor>::Erase(const Slice& key,
if (last_reference) {
e->Free();
}
return e != nullptr;
}

template <class CacheMonitor>
Expand Down
2 changes: 1 addition & 1 deletion cache/lru_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class ALIGN_AS(CACHE_LINE_SIZE) LRUCacheShardTemplate : public CacheMonitor,
virtual bool Ref(Cache::Handle* handle) override;
virtual bool Release(Cache::Handle* handle,
bool force_erase = false) override;
virtual void Erase(const Slice& key, uint32_t hash) override;
virtual bool Erase(const Slice& key, uint32_t hash) override;

// Although in some platforms the update of size_t is atomic, to make sure
// GetUsage() and GetPinnedUsage() work correctly under any platform, we'll
Expand Down
2 changes: 1 addition & 1 deletion cache/lru_cache_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class LRUCacheTest : public testing::Test,
return cache_->Lookup(key, 0 /*hash*/);
}

void Erase(const std::string& key) { cache_->Erase(key, 0 /*hash*/); }
bool Erase(const std::string& key) { return cache_->Erase(key, 0 /*hash*/); }

void ValidateLRUList(std::vector<std::string> keys,
size_t num_high_pri_pool_keys = 0) {
Expand Down
4 changes: 2 additions & 2 deletions cache/sharded_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ bool ShardedCache::Release(Handle* handle, bool force_erase) {
return GetShard(Shard(hash))->Release(handle, force_erase);
}

void ShardedCache::Erase(const Slice& key) {
bool ShardedCache::Erase(const Slice& key) {
uint32_t hash = HashSlice(key);
GetShard(Shard(hash))->Erase(key, hash);
return GetShard(Shard(hash))->Erase(key, hash);
}

uint64_t ShardedCache::NewId() {
Expand Down
4 changes: 2 additions & 2 deletions cache/sharded_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CacheShard {
virtual Cache::Handle* Lookup(const Slice& key, uint32_t hash) = 0;
virtual bool Ref(Cache::Handle* handle) = 0;
virtual bool Release(Cache::Handle* handle, bool force_erase = false) = 0;
virtual void Erase(const Slice& key, uint32_t hash) = 0;
virtual bool Erase(const Slice& key, uint32_t hash) = 0;
virtual void SetCapacity(size_t capacity) = 0;
virtual void SetStrictCapacityLimit(bool strict_capacity_limit) = 0;
virtual size_t GetUsage() const = 0;
Expand Down Expand Up @@ -68,7 +68,7 @@ class ShardedCache : public Cache {
virtual Handle* Lookup(const Slice& key, Statistics* stats) override;
virtual bool Ref(Handle* handle) override;
virtual bool Release(Handle* handle, bool force_erase = false) override;
virtual void Erase(const Slice& key) override;
virtual bool Erase(const Slice& key) override;
virtual uint64_t NewId() override;
virtual size_t GetCapacity() const override;
virtual bool HasStrictCapacityLimit() const override;
Expand Down
2 changes: 1 addition & 1 deletion db/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ Status BuildTable(
ro.fill_cache = false;
for (auto& meta : *meta_vec) {
std::unique_ptr<InternalIterator> it(table_cache->NewIterator(
ro, env_options, internal_comparator, meta, empty_dependence_map,
ro, env_options, meta, empty_dependence_map,
nullptr /* range_del_agg */,
mutable_cf_options.prefix_extractor.get(), nullptr,
(internal_stats == nullptr) ? nullptr
Expand Down
32 changes: 16 additions & 16 deletions db/column_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ ColumnFamilyData::ColumnFamilyData(
uint32_t id, const std::string& name, Version* _dummy_versions,
Cache* _table_cache, WriteBufferManager* write_buffer_manager,
const ColumnFamilyOptions& cf_options, const ImmutableDBOptions& db_options,
const EnvOptions& env_options, ColumnFamilySet* column_family_set)
const EnvOptions* env_options, ColumnFamilySet* column_family_set)
: id_(id),
name_(name),
dummy_versions_(_dummy_versions),
Expand All @@ -424,9 +424,10 @@ ColumnFamilyData::ColumnFamilyData(
dropped_(false),
optimize_filters_for_hits_(cf_options.optimize_filters_for_hits),
internal_comparator_(cf_options.comparator),
initial_cf_options_(SanitizeOptions(db_options, cf_options)),
ioptions_(db_options, initial_cf_options_),
mutable_cf_options_(initial_cf_options_, db_options.env),
table_cache_(new TableCache(SanitizeOptions(db_options, cf_options),
db_options, env_options, _table_cache)),
ioptions_(table_cache_->ioptions()),
mutable_cf_options_(table_cache_->initial_cf_options(), db_options.env),
is_delete_range_supported_(
cf_options.table_factory->IsDeleteRangeSupported()),
write_buffer_manager_(write_buffer_manager),
Expand All @@ -453,17 +454,16 @@ ColumnFamilyData::ColumnFamilyData(
if (_dummy_versions != nullptr) {
internal_stats_.reset(
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(new LevelCompactionPicker(
table_cache_.get(), env_options, ioptions_, &internal_comparator_));
table_cache_.get(), *env_options, ioptions_, &internal_comparator_));
#ifndef ROCKSDB_LITE
} else if (ioptions_.compaction_style == kCompactionStyleUniversal) {
compaction_picker_.reset(new UniversalCompactionPicker(
table_cache_.get(), env_options, ioptions_, &internal_comparator_));
table_cache_.get(), *env_options, ioptions_, &internal_comparator_));
} else if (ioptions_.compaction_style == kCompactionStyleNone) {
compaction_picker_.reset(new NullCompactionPicker(
table_cache_.get(), env_options, ioptions_, &internal_comparator_));
table_cache_.get(), *env_options, ioptions_, &internal_comparator_));
ROCKS_LOG_WARN(ioptions_.info_log,
"Column family %s does not use any background compaction. "
"Compactions can only be done via CompactFiles\n",
Expand All @@ -475,14 +475,14 @@ ColumnFamilyData::ColumnFamilyData(
"Column family %s will use kCompactionStyleLevel.\n",
ioptions_.compaction_style, GetName().c_str());
compaction_picker_.reset(new LevelCompactionPicker(
table_cache_.get(), env_options, ioptions_, &internal_comparator_));
table_cache_.get(), *env_options, ioptions_, &internal_comparator_));
}

if (column_family_set_->NumberOfColumnFamilies() < 10) {
ROCKS_LOG_INFO(ioptions_.info_log,
"--------------- Options for column family [%s]:\n",
name.c_str());
initial_cf_options_.Dump(ioptions_.info_log);
initial_cf_options().Dump(ioptions_.info_log);
} else {
ROCKS_LOG_INFO(ioptions_.info_log, "\t(skipping printing options)\n");
}
Expand Down Expand Up @@ -561,7 +561,7 @@ void ColumnFamilyData::SetDropped() {
}

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

uint64_t ColumnFamilyData::OldestLogToKeep() {
Expand Down Expand Up @@ -1262,7 +1262,7 @@ Status ColumnFamilyData::SetOptions(
if (s.ok()) {
new_mutable_cf_options = MutableCFOptions(
SanitizeOptions(db_options,
BuildColumnFamilyOptions(initial_cf_options_,
BuildColumnFamilyOptions(initial_cf_options(),
new_mutable_cf_options)),
db_options.env);
optimize_filters_for_hits_.store(
Expand All @@ -1277,7 +1277,7 @@ Status ColumnFamilyData::SetOptions(

// REQUIRES: DB mutex held
Env::WriteLifeTimeHint ColumnFamilyData::CalculateSSTWriteHint(int level) {
if (initial_cf_options_.compaction_style != kCompactionStyleLevel) {
Comment thread
oujiaxin marked this conversation as resolved.
if (initial_cf_options().compaction_style != kCompactionStyleLevel) {
return Env::WLTH_NOT_SET;
}
if (level == 0) {
Expand Down Expand Up @@ -1323,7 +1323,7 @@ Directory* ColumnFamilyData::GetDataDir(size_t path_id) const {

ColumnFamilySet::ColumnFamilySet(const std::string& dbname,
const ImmutableDBOptions* db_options,
const EnvOptions& env_options,
const EnvOptions* env_options,
Cache* table_cache,
WriteBufferManager* write_buffer_manager,
WriteController* write_controller)
Expand All @@ -1334,7 +1334,7 @@ ColumnFamilySet::ColumnFamilySet(const std::string& dbname,
default_cfd_cache_(nullptr),
db_name_(dbname),
db_options_(db_options),
env_options_(env_options),
env_options_(*env_options),
table_cache_(table_cache),
write_buffer_manager_(write_buffer_manager),
write_controller_(write_controller) {
Expand Down Expand Up @@ -1405,7 +1405,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
19 changes: 10 additions & 9 deletions db/column_family.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ class ColumnFamilyData {
FlushReason GetFlushReason() const { return flush_reason_; }
// thread-safe
const EnvOptions* soptions() const;
const ImmutableCFOptions* ioptions() const { return &ioptions_; }
const ImmutableCFOptions* ioptions() const {
return &table_cache_->ioptions();
}
// REQUIRES: DB mutex held
// This returns the MutableCFOptions used by current SuperVersion
// You should use this API to reference MutableCFOptions most of the time.
Expand Down Expand Up @@ -268,6 +270,7 @@ class ColumnFamilyData {
bool needs_dup_key_check, SequenceNumber earliest_seq);

TableCache* table_cache() const { return table_cache_.get(); }
std::shared_ptr<TableCache>& table_cache_shared_ptr() { return table_cache_; }

// See documentation in compaction_picker.h
// REQUIRES: DB mutex held
Expand Down Expand Up @@ -409,8 +412,8 @@ class ColumnFamilyData {

bool initialized() const { return initialized_.load(); }

const ColumnFamilyOptions& initial_cf_options() {
return initial_cf_options_;
const ColumnFamilyOptions& initial_cf_options() const {
return table_cache_->initial_cf_options();
}

Env::WriteLifeTimeHint CalculateSSTWriteHint(int level);
Expand All @@ -426,7 +429,7 @@ class ColumnFamilyData {
WriteBufferManager* write_buffer_manager,
const ColumnFamilyOptions& options,
const ImmutableDBOptions& db_options,
const EnvOptions& env_options,
const EnvOptions* env_options,
ColumnFamilySet* column_family_set);

uint32_t id_;
Expand All @@ -440,14 +443,12 @@ class ColumnFamilyData {
std::atomic<bool> optimize_filters_for_hits_; // for read output mutex

const InternalKeyComparator internal_comparator_;
const ColumnFamilyOptions initial_cf_options_;
const ImmutableCFOptions ioptions_;
std::shared_ptr<TableCache> table_cache_;
const ImmutableCFOptions& ioptions_;
MutableCFOptions mutable_cf_options_;

const bool is_delete_range_supported_;

std::unique_ptr<TableCache> table_cache_;

std::unique_ptr<InternalStats> internal_stats_;

WriteBufferManager* write_buffer_manager_;
Expand Down Expand Up @@ -552,7 +553,7 @@ class ColumnFamilySet {

ColumnFamilySet(const std::string& dbname,
const ImmutableDBOptions* db_options,
const EnvOptions& env_options, Cache* table_cache,
const EnvOptions* env_options, Cache* table_cache,
WriteBufferManager* write_buffer_manager,
WriteController* write_controller);
~ColumnFamilySet();
Expand Down
2 changes: 1 addition & 1 deletion db/compaction_iterator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class FakeCompaction : public CompactionIterator::CompactionProxy {
std::vector<size_t>* /*level_ptrs*/) const override {
return is_bottommost_level || key_not_exists_beyond_output_level;
}
virtual SeparationType separation_type() const {
virtual SeparationType separation_type() const override {
return kCompactionIgnoreSeparate;
}
virtual bool need_rebuild(uint64_t fn) { return false; }
Expand Down
19 changes: 9 additions & 10 deletions db/compaction_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,8 @@ struct CompactionJob::SubcompactionState {
const DependenceMap& depend_map, Arena* arena,
TableReader** table_reader_ptr) {
return table_cache->NewIterator(
ReadOptions(), job->env_options_, icmp, *file_metadata, depend_map,
nullptr, compaction->mutable_cf_options()->prefix_extractor.get(),
ReadOptions(), job->env_options_, *file_metadata, depend_map, nullptr,
compaction->mutable_cf_options()->prefix_extractor.get(),
table_reader_ptr, nullptr, false, arena, true, -1);
};
InternalKey internal_begin, internal_end;
Expand Down Expand Up @@ -531,7 +531,7 @@ struct CompactionJob::SubcompactionState {
compaction->column_family_data()->table_cache();
Cache::Handle* handle = nullptr;
auto s = table_cache->FindTable(
job->env_options_, icmp, meta->fd, &handle,
job->env_options_, meta->fd, &handle,
compaction->mutable_cf_options()->prefix_extractor.get());
if (!s.ok()) {
return s;
Expand Down Expand Up @@ -1349,9 +1349,8 @@ Status CompactionJob::VerifyFiles() {
ReadOptions ro;
ro.fill_cache = false;
InternalIterator* iter = cfd->table_cache()->NewIterator(
ro, env_options_, cfd->internal_comparator(), *files_meta[file_idx],
empty_dependence_map, nullptr /* range_del_agg */, prefix_extractor,
nullptr,
ro, env_options_, *files_meta[file_idx], empty_dependence_map,
nullptr /* range_del_agg */, prefix_extractor, nullptr,
output_level == -1
? nullptr
: cfd->internal_stats()->GetFileReadHist(output_level),
Expand Down Expand Up @@ -2705,8 +2704,8 @@ Status CompactionJob::InstallCompactionResults(
ReadOptions ro;
ro.fill_cache = false;
InternalIterator* iter = cfd->table_cache()->NewIterator(
ro, env_options_, cfd->internal_comparator(), o.file_meta,
empty_dependence_map, nullptr /* range_del_agg */,
ro, env_options_, o.file_meta, empty_dependence_map,
nullptr /* range_del_agg */,
mutable_cf_options.prefix_extractor.get(), nullptr,
cfd->internal_stats()->GetFileReadHist(compaction->output_level()),
false, nullptr /* arena */, false /* skip_filters */,
Expand Down Expand Up @@ -2788,8 +2787,8 @@ Status CompactionJob::InstallCompactionResults(
ReadOptions ro;
ro.fill_cache = false;
InternalIterator* iter = cfd->table_cache()->NewIterator(
ro, env_options_, cfd->internal_comparator(), file_meta,
empty_dependence_map, nullptr /* range_del_agg */,
ro, env_options_, file_meta, empty_dependence_map,
nullptr /* range_del_agg */,
mutable_cf_options.prefix_extractor.get(), nullptr,
cfd->internal_stats()->GetFileReadHist(compaction->output_level()),
false, nullptr /* arena */, false /* skip_filters */,
Expand Down
Loading