提交 c0077294 编写于 作者: Z ZhaoMing

Fix target_blob_file_size usage

上级 4e4a04d4
......@@ -232,13 +232,16 @@ Status BuildTable(
return s;
};
size_t target_blob_file_size = MaxBlobSize(
mutable_cf_options, ioptions.num_levels, ioptions.compaction_style);
auto trans_to_separate = [&](const Slice& key, LazyBuffer& value) {
assert(value.file_number() == uint64_t(-1));
Status status;
TableBuilder* blob_builder = separate_helper.builder.get();
FileMetaData* blob_meta = separate_helper.current_output;
if (blob_builder != nullptr &&
blob_builder->FileSize() > mutable_cf_options.target_file_size_base) {
blob_builder->FileSize() > target_blob_file_size) {
status = finish_output_blob_sst();
blob_builder = nullptr;
}
......
......@@ -417,15 +417,13 @@ struct CompactionJob::SubcompactionState {
// pop smaller scores if total_compaction_bytes > max_compaction_bytes
// remain one blob al least.
size_t max_file_size = mutable_cf_options->target_blob_file_size;
if (max_file_size == 0) {
max_file_size = MaxFileSizeForLevel(
*mutable_cf_options,
compaction->immutable_cf_options()->num_levels - 1,
compaction->immutable_cf_options()->compaction_style);
}
uint64_t target_compaction_bytes = std::max(
max_compaction_bytes, input_blob_info.input_bytes + max_file_size);
size_t target_blob_file_size = MaxBlobSize(
*mutable_cf_options, compaction->immutable_cf_options()->num_levels,
compaction->immutable_cf_options()->compaction_style);
uint64_t target_compaction_bytes =
std::max(max_compaction_bytes,
input_blob_info.input_bytes + target_blob_file_size);
while (total_compaction_bytes > target_compaction_bytes &&
target_range_blob_heap.size() > 1) {
total_compaction_bytes -= target_range_blob_heap.top().ref_bytes;
......@@ -1614,12 +1612,16 @@ void CompactionJob::ProcessKeyValueCompaction(SubcompactionState* sub_compact) {
->value_meta_extractor_factory->CreateValueExtractor(context);
}
size_t target_blob_file_size =
MaxBlobSize(*mutable_cf_options, cfd->ioptions()->num_levels,
cfd->ioptions()->compaction_style);
auto trans_to_separate = [&](const Slice& key, LazyBuffer& value) {
Status s;
TableBuilder* blob_builder = sub_compact->blob_builder.get();
FileMetaData* blob_meta = &sub_compact->current_blob_output()->meta;
if (blob_builder != nullptr &&
blob_builder->FileSize() > mutable_cf_options->target_file_size_base) {
blob_builder->FileSize() > target_blob_file_size) {
s = FinishCompactionOutputBlob(s, sub_compact, {});
blob_builder = nullptr;
}
......
......@@ -795,19 +795,16 @@ void CompactionPicker::GetGrandparents(
Compaction* CompactionPicker::PickGarbageCollection(
const std::string& /*cf_name*/, const MutableCFOptions& mutable_cf_options,
VersionStorageInfo* vstorage, LogBuffer* /*log_buffer*/) {
// Setting fragment_size as one eighth max_file_size prevents selecting
// massive files to single compaction which would pin down the maximum
// deletable file number for a long time resulting possible storage leakage.
size_t max_file_size = mutable_cf_options.target_blob_file_size;
if (max_file_size == 0) {
max_file_size =
MaxFileSizeForLevel(mutable_cf_options, ioptions_.num_levels - 1,
ioptions_.compaction_style);
}
// Setting fragment_size as one eighth target_blob_file_size prevents
// selecting massive files to single compaction which would pin down the
// maximum deletable file number for a long time resulting possible storage
// leakage.
size_t target_blob_file_size = MaxBlobSize(
mutable_cf_options, ioptions_.num_levels, ioptions_.compaction_style);
size_t fragment_size = mutable_cf_options.blob_file_defragment_size;
if (fragment_size == 0) {
fragment_size = max_file_size / 8;
fragment_size = target_blob_file_size / 8;
}
auto& hidden_files = vstorage->LevelFiles(-1);
......@@ -905,7 +902,7 @@ Compaction* CompactionPicker::PickGarbageCollection(
while (!candidate_blob_vec.empty() && input.files.size() < 8) {
auto f = candidate_blob_vec.front().f;
uint64_t estimate_size = candidate_blob_vec.front().estimate_size;
if (total_estimate_size + estimate_size < max_file_size) {
if (total_estimate_size + estimate_size < target_blob_file_size) {
total_estimate_size += estimate_size;
num_antiquation += f->num_antiquation;
f->set_gc_candidate();
......
......@@ -126,6 +126,16 @@ uint64_t MaxFileSizeForLevel(const MutableCFOptions& cf_options, int level,
}
}
uint64_t MaxBlobSize(const MutableCFOptions& cf_options, int num_levels,
CompactionStyle compaction_style) {
size_t target_blob_file_size = cf_options.target_blob_file_size;
if (target_blob_file_size == 0) {
target_blob_file_size =
MaxFileSizeForLevel(cf_options, num_levels - 1, compaction_style);
}
return target_blob_file_size;
}
void MutableCFOptions::RefreshDerivedOptions(int num_levels) {
max_file_size.resize(num_levels);
max_file_size[0] = 0; // unlimited
......
......@@ -260,4 +260,8 @@ uint64_t MaxFileSizeForLevel(const MutableCFOptions& cf_options, int level,
CompactionStyle compaction_style,
int base_level = 1,
bool level_compaction_dynamic_level_bytes = false);
uint64_t MaxBlobSize(const MutableCFOptions& cf_options, int num_levels,
CompactionStyle compaction_style);
} // namespace TERARKDB_NAMESPACE
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册