Skip to content

Commit

Permalink
Move CalculateSSTWriteHint into VersionStorageInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
jowlyzhang committed Sep 6, 2024
1 parent 21391cf commit 14e4102
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 37 deletions.
23 changes: 0 additions & 23 deletions db/column_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1565,29 +1565,6 @@ Status ColumnFamilyData::SetOptions(
return s;
}

// REQUIRES: DB mutex held
Env::WriteLifeTimeHint ColumnFamilyData::CalculateSSTWriteHint(Version* version,
int level) {
if (initial_cf_options_.compaction_style != kCompactionStyleLevel) {
return Env::WLTH_NOT_SET;
}
if (level == 0) {
return Env::WLTH_MEDIUM;
}
int base_level = version->storage_info()->base_level();

// L1: medium, L2: long, ...
if (level - base_level >= 2) {
return Env::WLTH_EXTREME;
} else if (level < base_level) {
// There is no restriction which prevents level passed in to be smaller
// than base_level.
return Env::WLTH_MEDIUM;
}
return static_cast<Env::WriteLifeTimeHint>(
level - base_level + static_cast<int>(Env::WLTH_MEDIUM));
}

Status ColumnFamilyData::AddDirectories(
std::map<std::string, std::shared_ptr<FSDirectory>>* created_dirs) {
Status s;
Expand Down
2 changes: 0 additions & 2 deletions db/column_family.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,6 @@ class ColumnFamilyData {
return initial_cf_options_;
}

Env::WriteLifeTimeHint CalculateSSTWriteHint(Version* version, int level);

// created_dirs remembers directory created, so that we don't need to call
// the same data creation operation again.
Status AddDirectories(
Expand Down
10 changes: 5 additions & 5 deletions db/compaction/compaction_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ void CompactionJob::Prepare() {

// Generate file_levels_ for compaction before making Iterator
auto* c = compact_->compaction;
ColumnFamilyData* cfd = c->column_family_data();
[[maybe_unused]] ColumnFamilyData* cfd = c->column_family_data();
assert(cfd != nullptr);
assert(c->input_version()->storage_info()->NumLevelFiles(
compact_->compaction->level()) > 0);
const VersionStorageInfo* storage_info = c->input_version()->storage_info();
assert(storage_info);
assert(storage_info->NumLevelFiles(compact_->compaction->level()) > 0);

write_hint_ =
cfd->CalculateSSTWriteHint(c->input_version(), c->output_level());
write_hint_ = storage_info->CalculateSSTWriteHint(c->output_level());
bottommost_level_ = c->bottommost_level();

if (c->ShouldFormSubcompactions()) {
Expand Down
8 changes: 4 additions & 4 deletions db/compaction/compaction_service_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ Status CompactionServiceCompactionJob::Run() {

auto* c = compact_->compaction;
assert(c->column_family_data() != nullptr);
assert(c->input_version()->storage_info()->NumLevelFiles(
compact_->compaction->level()) > 0);
const VersionStorageInfo* storage_info = c->input_version()->storage_info();
assert(storage_info);
assert(storage_info->NumLevelFiles(compact_->compaction->level()) > 0);

write_hint_ = c->column_family_data()->CalculateSSTWriteHint(
c->input_version(), c->output_level());
write_hint_ = storage_info->CalculateSSTWriteHint(c->output_level());
bottommost_level_ = c->bottommost_level();

Slice begin = compaction_input_.begin;
Expand Down
3 changes: 2 additions & 1 deletion db/db_impl/db_impl_open.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,8 @@ Status DBImpl::WriteLevel0TableForRecovery(int job_id, ColumnFamilyData* cfd,
meta.oldest_ancester_time = current_time;
meta.epoch_number = cfd->NewEpochNumber();
{
auto write_hint = cfd->CalculateSSTWriteHint(cfd->current(), /*level=*/0);
auto write_hint =
cfd->current()->storage_info()->CalculateSSTWriteHint(/*level=*/0);
mutex_.Unlock();

SequenceNumber earliest_write_conflict_snapshot;
Expand Down
2 changes: 1 addition & 1 deletion db/flush_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ Status FlushJob::WriteLevel0Table() {
std::vector<BlobFileAddition> blob_file_additions;

{
auto write_hint = cfd_->CalculateSSTWriteHint(base_, /*level=*/0);
auto write_hint = base_->storage_info()->CalculateSSTWriteHint(/*level=*/0);
Env::IOPriority io_priority = GetRateLimiterPriority();
db_mutex_->Unlock();
if (log_buffer_) {
Expand Down
3 changes: 2 additions & 1 deletion db/repair.cc
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ class Repairer {
meta.file_creation_time = current_time;
SnapshotChecker* snapshot_checker = DisableGCSnapshotChecker::Instance();

auto write_hint = cfd->CalculateSSTWriteHint(cfd->current(), /*level=*/0);
auto write_hint =
cfd->current()->storage_info()->CalculateSSTWriteHint(/*level=*/0);
std::vector<std::unique_ptr<FragmentedRangeTombstoneIterator>>
range_del_iters;
auto range_del_iter = mem->NewRangeTombstoneIterator(
Expand Down
21 changes: 21 additions & 0 deletions db/version_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4919,6 +4919,27 @@ bool VersionStorageInfo::RangeMightExistAfterSortedRun(
return false;
}

Env::WriteLifeTimeHint VersionStorageInfo::CalculateSSTWriteHint(
int level) const {
if (compaction_style_ != kCompactionStyleLevel) {
return Env::WLTH_NOT_SET;
}
if (level == 0) {
return Env::WLTH_MEDIUM;
}

// L1: medium, L2: long, ...
if (level - base_level_ >= 2) {
return Env::WLTH_EXTREME;
} else if (level < base_level_) {
// There is no restriction which prevents level passed in to be smaller
// than base_level.
return Env::WLTH_MEDIUM;
}
return static_cast<Env::WriteLifeTimeHint>(
level - base_level_ + static_cast<int>(Env::WLTH_MEDIUM));
}

void Version::AddLiveFiles(std::vector<uint64_t>* live_table_files,
std::vector<uint64_t>* live_blob_files) const {
assert(live_table_files);
Expand Down
2 changes: 2 additions & 0 deletions db/version_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,8 @@ class VersionStorageInfo {
const Slice& largest_user_key,
int last_level, int last_l0_idx);

Env::WriteLifeTimeHint CalculateSSTWriteHint(int level) const;

private:
void ComputeCompensatedSizes();
void UpdateNumNonEmptyLevels();
Expand Down

0 comments on commit 14e4102

Please sign in to comment.