Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion db/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "db/range_del_aggregator.h"
#include "db/table_cache.h"
#include "db/version_edit.h"
#include "db/version_set.h"
#include "monitoring/iostats_context_imp.h"
#include "monitoring/thread_status_util.h"
#include "rocksdb/env.h"
Expand Down Expand Up @@ -457,7 +458,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
63 changes: 33 additions & 30 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 @@ -449,21 +450,21 @@ ColumnFamilyData::ColumnFamilyData(
last_memtable_id_(0) {
Ref();

table_cache_->bind_life_cycle();

// 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));
table_cache_.reset(new TableCache(ioptions_, env_options, _table_cache));
table_cache_->InitInternalStats(this);
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 +476,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 +562,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 @@ -754,7 +755,7 @@ WriteStallCondition ColumnFamilyData::RecalculateWriteStallConditions(
if (write_stall_condition == WriteStallCondition::kStopped &&
write_stall_cause == WriteStallCause::kMemtableLimit) {
write_controller_token_ = write_controller->GetStopToken();
internal_stats_->AddCFStats(InternalStats::MEMTABLE_LIMIT_STOPS, 1);
internal_stats()->AddCFStats(InternalStats::MEMTABLE_LIMIT_STOPS, 1);
ROCKS_LOG_WARN(
ioptions_.info_log,
"[%s] Stopping writes because we have %d immutable memtables "
Expand All @@ -764,9 +765,9 @@ WriteStallCondition ColumnFamilyData::RecalculateWriteStallConditions(
} else if (write_stall_condition == WriteStallCondition::kStopped &&
write_stall_cause == WriteStallCause::kL0FileCountLimit) {
write_controller_token_ = write_controller->GetStopToken();
internal_stats_->AddCFStats(InternalStats::L0_FILE_COUNT_LIMIT_STOPS, 1);
internal_stats()->AddCFStats(InternalStats::L0_FILE_COUNT_LIMIT_STOPS, 1);
if (compaction_picker_->IsLevel0CompactionInProgress()) {
internal_stats_->AddCFStats(
internal_stats()->AddCFStats(
InternalStats::LOCKED_L0_FILE_COUNT_LIMIT_STOPS, 1);
}
ROCKS_LOG_WARN(ioptions_.info_log,
Expand All @@ -775,7 +776,7 @@ WriteStallCondition ColumnFamilyData::RecalculateWriteStallConditions(
} else if (write_stall_condition == WriteStallCondition::kStopped &&
write_stall_cause == WriteStallCause::kPendingCompactionBytes) {
write_controller_token_ = write_controller->GetStopToken();
internal_stats_->AddCFStats(
internal_stats()->AddCFStats(
InternalStats::PENDING_COMPACTION_BYTES_LIMIT_STOPS, 1);
ROCKS_LOG_WARN(
ioptions_.info_log,
Expand All @@ -785,7 +786,7 @@ WriteStallCondition ColumnFamilyData::RecalculateWriteStallConditions(
} else if (write_stall_condition == WriteStallCondition::kStopped &&
write_stall_cause == WriteStallCause::kReadAmpLimit) {
write_controller_token_ = write_controller->GetStopToken();
internal_stats_->AddCFStats(InternalStats::READ_AMP_LIMIT_STOPS, 1);
internal_stats()->AddCFStats(InternalStats::READ_AMP_LIMIT_STOPS, 1);
ROCKS_LOG_WARN(
ioptions_.info_log,
"[%s] Stopping writes because we have %f times read amplification "
Expand All @@ -797,7 +798,7 @@ WriteStallCondition ColumnFamilyData::RecalculateWriteStallConditions(
SetupDelay(write_controller, compaction_needed_bytes,
prev_compaction_needed_bytes_, was_stopped,
mutable_cf_options.disable_auto_compactions);
internal_stats_->AddCFStats(InternalStats::MEMTABLE_LIMIT_SLOWDOWNS, 1);
internal_stats()->AddCFStats(InternalStats::MEMTABLE_LIMIT_SLOWDOWNS, 1);
ROCKS_LOG_WARN(
ioptions_.info_log,
"[%s] Stalling writes because we have %d immutable memtables "
Expand All @@ -815,10 +816,10 @@ WriteStallCondition ColumnFamilyData::RecalculateWriteStallConditions(
SetupDelay(write_controller, compaction_needed_bytes,
prev_compaction_needed_bytes_, was_stopped || near_stop,
mutable_cf_options.disable_auto_compactions);
internal_stats_->AddCFStats(InternalStats::L0_FILE_COUNT_LIMIT_SLOWDOWNS,
1);
internal_stats()->AddCFStats(InternalStats::L0_FILE_COUNT_LIMIT_SLOWDOWNS,
1);
if (compaction_picker_->IsLevel0CompactionInProgress()) {
internal_stats_->AddCFStats(
internal_stats()->AddCFStats(
InternalStats::LOCKED_L0_FILE_COUNT_LIMIT_SLOWDOWNS, 1);
}
ROCKS_LOG_WARN(ioptions_.info_log,
Expand All @@ -844,7 +845,7 @@ WriteStallCondition ColumnFamilyData::RecalculateWriteStallConditions(
SetupDelay(write_controller, compaction_needed_bytes,
prev_compaction_needed_bytes_, was_stopped || near_stop,
mutable_cf_options.disable_auto_compactions);
internal_stats_->AddCFStats(
internal_stats()->AddCFStats(
InternalStats::PENDING_COMPACTION_BYTES_LIMIT_SLOWDOWNS, 1);
ROCKS_LOG_WARN(
ioptions_.info_log,
Expand All @@ -860,7 +861,7 @@ WriteStallCondition ColumnFamilyData::RecalculateWriteStallConditions(
SetupDelay(write_controller, compaction_needed_bytes,
prev_compaction_needed_bytes_, was_stopped || near_stop,
mutable_cf_options.disable_auto_compactions);
internal_stats_->AddCFStats(InternalStats::READ_AMP_LIMIT_SLOWDOWNS, 1);
internal_stats()->AddCFStats(InternalStats::READ_AMP_LIMIT_SLOWDOWNS, 1);
ROCKS_LOG_WARN(
ioptions_.info_log,
"[%s] Stalling writes because we have %f times read amplification "
Expand Down Expand Up @@ -1262,7 +1263,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 +1278,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 +1324,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 +1335,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 All @@ -1343,7 +1344,9 @@ ColumnFamilySet::ColumnFamilySet(const std::string& dbname,
dummy_cfd_->next_ = dummy_cfd_;
}

ColumnFamilySet::~ColumnFamilySet() {
ColumnFamilySet::~ColumnFamilySet() { assert(column_family_data_.empty()); }

void ColumnFamilySet::Cleanup() {
while (column_family_data_.size() > 0) {
// cfd destructor will delete itself from column_family_data_
auto cfd = column_family_data_.begin()->second;
Expand Down Expand Up @@ -1405,7 +1408,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
Loading