Skip to content

v4.0 渐进式compact参考 #3226

@guangkun123

Description

@guangkun123

Which PikiwiDB functionalities are relevant/related to the feature request?

No response

Description

一分钟调用一次就行

Status Redis::LongestNotCompactionSstCompact(const DataType& option_type, std::vector* compact_result_vec,
const ColumnFamilyType& type) {

//printf("Redis::LongestNotCompactionSstCompact\n");
std::vector handleIdxVec;
SelectColumnFamilyHandles(option_type, type, handleIdxVec);
if (handleIdxVec.size() == 0) {
return Status::Corruption("Invalid data type");
}

if (compact_result_vec) {
compact_result_vec->clear();
}

for (auto idx : handleIdxVec) {
int rate = 0;
while (rate < 70) {
rate = 100;
//std::cout << handleIdxVec.size() << ":" << idx << std::endl;
rocksdb::ColumnFamilyMetaData meta;
rocksdb::CompactionOptions compact_options_;
//compact_options_.output_file_size_limit = 20971520;
db_->GetColumnFamilyMetaData(handles_[idx], &meta);

    // sort it for convenience to traverse
    Status compact_result;
    uint64_t min_number = -1;
    std::string min_file = "999999.sst";
    int min_level = 0;
    std::vector<std::string> input_file_names;
    for (auto level_meta : meta.levels) {
        for (auto file_meta : level_meta.files) {
            auto file_path = file_meta.db_path;
              uint64_t number = 0;
              number = TableFileNameToNumber(file_meta.name);
              //std::cout << file_path << ":" << idx << " : "<< number << " : " << level_meta.level << std::endl;
              if (number < min_number) {
                  min_file = file_meta.name;
                  min_level = level_meta.level;
                  min_number = number;
                  //std::cout << min_number << " : "<< min_file << " : " << min_level << std::endl;
              }
        }
    }

    if (min_file == "999999.sst") { continue; }

    if (min_level < 6) { min_level = min_level + 1; }

    input_file_names.push_back(min_file);

    //std::cout << "CompactFiles: " << idx << " : "<< min_file << " : " << min_level << std::endl;

    rocksdb::CompactionJobInfo job_info;
    db_->CompactFiles(compact_options_, handles_[idx], input_file_names, min_level, -1, nullptr, &job_info);
    //std::cout << "job_stats : " << job_info.stats.num_input_records <<  ": "<< job_info.stats.num_output_records << std::endl;
if (job_info.stats.num_input_records == 0) { break; }
rate = job_info.stats.num_output_records * 100 / job_info.stats.num_input_records;
}

}
return Status::OK();
}

Proposed solution

功能

Alternatives considered

渐进式compact

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions