Skip to content

Commit

Permalink
change logic
Browse files Browse the repository at this point in the history
  • Loading branch information
QlQlqiqi committed Oct 22, 2024
1 parent bc8de13 commit e5a4ff5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
5 changes: 0 additions & 5 deletions src/pika_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1439,11 +1439,6 @@ void PikaServer::InitStorageOptions() {
storage_options_.options.max_bytes_for_level_base = g_pika_conf->level0_file_num_compaction_trigger() * g_pika_conf->write_buffer_size();
storage_options_.options.max_subcompactions = g_pika_conf->max_subcompactions();
storage_options_.options.target_file_size_base = g_pika_conf->target_file_size_base();
storage_options_.options.level0_stop_writes_trigger = g_pika_conf->level0_stop_writes_trigger();
storage_options_.options.level0_slowdown_writes_trigger = g_pika_conf->level0_slowdown_writes_trigger();
storage_options_.options.min_write_buffer_number_to_merge = g_pika_conf->min_write_buffer_number_to_merge();
storage_options_.options.max_bytes_for_level_base = g_pika_conf->level0_file_num_compaction_trigger() * g_pika_conf->write_buffer_size();
storage_options_.options.max_subcompactions = g_pika_conf->max_subcompactions();
storage_options_.options.max_compaction_bytes = g_pika_conf->max_compaction_bytes();
storage_options_.options.max_background_flushes = g_pika_conf->max_background_flushes();
storage_options_.options.max_background_compactions = g_pika_conf->max_background_compactions();
Expand Down
10 changes: 8 additions & 2 deletions src/storage/src/redis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ Status Redis::Open(const StorageOptions& storage_options, const std::string& db_
rocksdb::BlockBasedTableOptions table_ops(storage_options.table_options);
table_ops.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10, true));

auto force_compact_min_delete_ratio = storage_->GetStorageOptions().compact_param_.force_compact_min_delete_ratio_;
rocksdb::Options ops(storage_options.options);
ops.create_missing_column_families = true;
if (storage_options.enable_db_statistics) {
Expand Down Expand Up @@ -299,6 +298,13 @@ Status Redis::LongestNotCompactionSstCompact(const DataType& option_type, std::v
db_->GetLiveFilesMetaData(&metadata);
std::sort(metadata.begin(), metadata.end(), [](const auto& a, const auto& b) { return a.name < b.name; });

// turn it on before compacting and turn it off after
listener_.Start();
DEFER {
listener_.End();
listener_.Clear();
};

for (auto idx : handleIdxVec) {
rocksdb::TablePropertiesCollection props;
Status s = db_->GetPropertiesOfAllTables(handles_[idx], &props);
Expand All @@ -311,7 +317,7 @@ Status Redis::LongestNotCompactionSstCompact(const DataType& option_type, std::v
continue;
}

// clear deleted sst file records because we use these only in OBD-compact
// clear deleted sst file records because we use them in different cf
listener_.Clear();

// The main goal of compaction was reclaimed the disk space and removed
Expand Down
17 changes: 15 additions & 2 deletions src/storage/src/redis.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,11 @@ class Redis {
class OBDSstListener : public rocksdb::EventListener {
public:
void OnTableFileDeleted(const rocksdb::TableFileDeletionInfo& info) override {
mu_.lock();
std::lock_guard<std::mutex> lk(mu_);
if (!running_) {
return;
}
deletedFileNameInOBDCompact_.emplace(info.file_path);
mu_.unlock();
}

void Clear() {
Expand All @@ -486,7 +488,18 @@ class Redis {
return deletedFileNameInOBDCompact_.find(str) != deletedFileNameInOBDCompact_.end();
}

// turn recording on/off
void Start() {
std::lock_guard<std::mutex> lk(mu_);
running_ = true;
}
void End() {
std::lock_guard<std::mutex> lk(mu_);
running_ = false;
}

std::mutex mu_;
bool running_ = false;
// deleted file(.sst) name in OBD compacting
std::set<std::string> deletedFileNameInOBDCompact_;
};
Expand Down

0 comments on commit e5a4ff5

Please sign in to comment.