diff --git a/db/compaction/compaction.cc b/db/compaction/compaction.cc index 313e2998aec..e5c817a0f21 100644 --- a/db/compaction/compaction.cc +++ b/db/compaction/compaction.cc @@ -338,16 +338,16 @@ Compaction::Compaction( _blob_garbage_collection_age_cutoff > 1 ? mutable_cf_options().blob_garbage_collection_age_cutoff : _blob_garbage_collection_age_cutoff), - penultimate_level_( - // For simplicity, we don't support the concept of "penultimate level" + proximal_level_( + // For simplicity, we don't support the concept of "proximal level" // with `CompactionReason::kExternalSstIngestion` and // `CompactionReason::kRefitLevel` _compaction_reason == CompactionReason::kExternalSstIngestion || _compaction_reason == CompactionReason::kRefitLevel ? Compaction::kInvalidLevel - : EvaluatePenultimateLevel(vstorage, mutable_cf_options_, - immutable_options_, start_level_, - output_level_)) { + : EvaluateProximalLevel(vstorage, mutable_cf_options_, + immutable_options_, start_level_, + output_level_)) { MarkFilesBeingCompacted(true); if (is_manual_compaction_) { compaction_reason_ = CompactionReason::kManualCompaction; @@ -405,10 +405,10 @@ Compaction::Compaction( } } - PopulatePenultimateLevelOutputRange(); + PopulateProximalLevelOutputRange(); } -void Compaction::PopulatePenultimateLevelOutputRange() { +void Compaction::PopulateProximalLevelOutputRange() { if (!SupportsPerKeyPlacement()) { assert(keep_in_last_level_through_seqno_ == kMaxSequenceNumber); return; @@ -417,46 +417,42 @@ void Compaction::PopulatePenultimateLevelOutputRange() { // exclude the last level, the range of all input levels is the safe range // of keys that can be moved up. int exclude_level = number_levels_ - 1; - penultimate_output_range_type_ = PenultimateOutputRangeType::kNonLastRange; + proximal_output_range_type_ = ProximalOutputRangeType::kNonLastRange; - // For universal compaction, the penultimate_output_range could be extended if - // all penultimate level files are included in the compaction (which includes - // the case that the penultimate level is empty). + // For universal compaction, the proximal_output_range could be extended if + // all proximal level files are included in the compaction (which includes + // the case that the proximal level is empty). if (immutable_options_.compaction_style == kCompactionStyleUniversal) { exclude_level = kInvalidLevel; - penultimate_output_range_type_ = PenultimateOutputRangeType::kFullRange; - std::set penultimate_inputs; + proximal_output_range_type_ = ProximalOutputRangeType::kFullRange; + std::set proximal_inputs; for (const auto& input_lvl : inputs_) { - if (input_lvl.level == penultimate_level_) { + if (input_lvl.level == proximal_level_) { for (const auto& file : input_lvl.files) { - penultimate_inputs.emplace(file->fd.GetNumber()); + proximal_inputs.emplace(file->fd.GetNumber()); } } } - auto penultimate_files = input_vstorage_->LevelFiles(penultimate_level_); - for (const auto& file : penultimate_files) { - if (penultimate_inputs.find(file->fd.GetNumber()) == - penultimate_inputs.end()) { + auto proximal_files = input_vstorage_->LevelFiles(proximal_level_); + for (const auto& file : proximal_files) { + if (proximal_inputs.find(file->fd.GetNumber()) == proximal_inputs.end()) { exclude_level = number_levels_ - 1; - penultimate_output_range_type_ = - PenultimateOutputRangeType::kNonLastRange; + proximal_output_range_type_ = ProximalOutputRangeType::kNonLastRange; break; } } } - // FIXME: should make use of `penultimate_output_range_type_`. + // FIXME: should make use of `proximal_output_range_type_`. // FIXME: when last level's input range does not overlap with - // penultimate level, and penultimate level input is empty, - // this call will not set penultimate_level_smallest_ or - // penultimate_level_largest_. No keys will be compacted up. - GetBoundaryInternalKeys(input_vstorage_, inputs_, - &penultimate_level_smallest_, - &penultimate_level_largest_, exclude_level); - - if (penultimate_output_range_type_ != - PenultimateOutputRangeType::kFullRange) { - // If not full range in penultimate level, must keep everything already + // proximal level, and proximal level input is empty, + // this call will not set proximal_level_smallest_ or + // proximal_level_largest_. No keys will be compacted up. + GetBoundaryInternalKeys(input_vstorage_, inputs_, &proximal_level_smallest_, + &proximal_level_largest_, exclude_level); + + if (proximal_output_range_type_ != ProximalOutputRangeType::kFullRange) { + // If not full range in proximal level, must keep everything already // in the last level there, because moving it back up might cause // overlap/placement issues that are difficult to resolve properly in the // presence of range deletes @@ -486,23 +482,23 @@ Compaction::~Compaction() { } bool Compaction::SupportsPerKeyPlacement() const { - return penultimate_level_ != kInvalidLevel; + return proximal_level_ != kInvalidLevel; } -int Compaction::GetPenultimateLevel() const { return penultimate_level_; } +int Compaction::GetProximalLevel() const { return proximal_level_; } // smallest_key and largest_key include timestamps if user-defined timestamp is // enabled. -bool Compaction::OverlapPenultimateLevelOutputRange( +bool Compaction::OverlapProximalLevelOutputRange( const Slice& smallest_key, const Slice& largest_key) const { if (!SupportsPerKeyPlacement()) { return false; } - // See FIXME in Compaction::PopulatePenultimateLevelOutputRange(). + // See FIXME in Compaction::PopulateProximalLevelOutputRange(). // We do not compact any key up in this case. - if (penultimate_level_smallest_.size() == 0 || - penultimate_level_largest_.size() == 0) { + if (proximal_level_smallest_.size() == 0 || + proximal_level_largest_.size() == 0) { return false; } @@ -510,13 +506,13 @@ bool Compaction::OverlapPenultimateLevelOutputRange( input_vstorage_->InternalComparator()->user_comparator(); return ucmp->CompareWithoutTimestamp( - smallest_key, penultimate_level_largest_.user_key()) <= 0 && + smallest_key, proximal_level_largest_.user_key()) <= 0 && ucmp->CompareWithoutTimestamp( - largest_key, penultimate_level_smallest_.user_key()) >= 0; + largest_key, proximal_level_smallest_.user_key()) >= 0; } // key includes timestamp if user-defined timestamp is enabled. -void Compaction::TEST_AssertWithinPenultimateLevelOutputRange( +void Compaction::TEST_AssertWithinProximalLevelOutputRange( const Slice& user_key, bool expect_failure) const { #ifdef NDEBUG (void)user_key; @@ -524,15 +520,15 @@ void Compaction::TEST_AssertWithinPenultimateLevelOutputRange( #else assert(SupportsPerKeyPlacement()); - assert(penultimate_level_smallest_.size() > 0); - assert(penultimate_level_largest_.size() > 0); + assert(proximal_level_smallest_.size() > 0); + assert(proximal_level_largest_.size() > 0); auto* cmp = input_vstorage_->user_comparator(); // op_type of a key can change during compaction, e.g. Merge -> Put. - if (!(cmp->Compare(user_key, penultimate_level_smallest_.user_key()) >= 0)) { + if (!(cmp->Compare(user_key, proximal_level_smallest_.user_key()) >= 0)) { assert(expect_failure); - } else if (!(cmp->Compare(user_key, penultimate_level_largest_.user_key()) <= + } else if (!(cmp->Compare(user_key, proximal_level_largest_.user_key()) <= 0)) { assert(expect_failure); } else { @@ -1018,7 +1014,7 @@ uint64_t Compaction::MinInputFileEpochNumber() const { return min_epoch_number; } -int Compaction::EvaluatePenultimateLevel( +int Compaction::EvaluateProximalLevel( const VersionStorageInfo* vstorage, const MutableCFOptions& mutable_cf_options, const ImmutableOptions& immutable_options, const int start_level, @@ -1033,21 +1029,21 @@ int Compaction::EvaluatePenultimateLevel( return kInvalidLevel; } - int penultimate_level = output_level - 1; - assert(penultimate_level < immutable_options.num_levels); - if (penultimate_level <= 0) { + int proximal_level = output_level - 1; + assert(proximal_level < immutable_options.num_levels); + if (proximal_level <= 0) { return kInvalidLevel; } - // If the penultimate level is not within input level -> output level range - // check if the penultimate output level is empty, if it's empty, it could - // also be locked for the penultimate output. + // If the proximal level is not within input level -> output level range + // check if the proximal output level is empty, if it's empty, it could + // also be locked for the proximal output. // TODO: ideally, it only needs to check if there's a file within the // compaction output key range. For simplicity, it just check if there's any - // file on the penultimate level. + // file on the proximal level. if (start_level == immutable_options.num_levels - 1 && (immutable_options.compaction_style != kCompactionStyleUniversal || - !vstorage->LevelFiles(penultimate_level).empty())) { + !vstorage->LevelFiles(proximal_level).empty())) { return kInvalidLevel; } @@ -1061,7 +1057,7 @@ int Compaction::EvaluatePenultimateLevel( return kInvalidLevel; } - return penultimate_level; + return proximal_level; } void Compaction::FilterInputsForCompactionIterator() { diff --git a/db/compaction/compaction.h b/db/compaction/compaction.h index 534b13c6a8f..fe7fc5026ed 100644 --- a/db/compaction/compaction.h +++ b/db/compaction/compaction.h @@ -102,13 +102,13 @@ class Compaction { BlobGarbageCollectionPolicy::kUseDefault, double blob_garbage_collection_age_cutoff = -1); - // The type of the penultimate level output range - enum class PenultimateOutputRangeType : int { - kNotSupported, // it cannot output to the penultimate level - kFullRange, // any data could be output to the penultimate level + // The type of the proximal level output range + enum class ProximalOutputRangeType : int { + kNotSupported, // it cannot output to the proximal level + kFullRange, // any data could be output to the proximal level kNonLastRange, // only the keys within non_last_level compaction inputs can - // be outputted to the penultimate level - kDisabled, // no data can be outputted to the penultimate level + // be outputted to the proximal level + kDisabled, // no data can be outputted to the proximal level }; // No copying allowed @@ -370,29 +370,29 @@ class Compaction { Slice GetLargestUserKey() const { return largest_user_key_; } - PenultimateOutputRangeType GetPenultimateOutputRangeType() const { - return penultimate_output_range_type_; + ProximalOutputRangeType GetProximalOutputRangeType() const { + return proximal_output_range_type_; } // Return true if the compaction supports per_key_placement bool SupportsPerKeyPlacement() const; - // Get per_key_placement penultimate output level, which is `last_level - 1` + // Get per_key_placement proximal output level, which is `last_level - 1` // if per_key_placement feature is supported. Otherwise, return -1. - int GetPenultimateLevel() const; + int GetProximalLevel() const; - // Return true if the given range is overlap with penultimate level output + // Return true if the given range is overlap with proximal level output // range. // Both smallest_key and largest_key include timestamps if user-defined // timestamp is enabled. - bool OverlapPenultimateLevelOutputRange(const Slice& smallest_key, - const Slice& largest_key) const; + bool OverlapProximalLevelOutputRange(const Slice& smallest_key, + const Slice& largest_key) const; - // For testing purposes, check that a key is within penultimate level + // For testing purposes, check that a key is within proximal level // output range for per_key_placement feature, which is safe to place the key - // to the penultimate level. Different compaction strategies have different + // to the proximal level. Different compaction strategies have different // rules. `user_key` includes timestamp if user-defined timestamp is enabled. - void TEST_AssertWithinPenultimateLevelOutputRange( + void TEST_AssertWithinProximalLevelOutputRange( const Slice& user_key, bool expect_failure = false) const; CompactionReason compaction_reason() const { return compaction_reason_; } @@ -441,20 +441,20 @@ class Compaction { static constexpr int kInvalidLevel = -1; - // Evaluate penultimate output level. If the compaction supports - // per_key_placement feature, it returns the penultimate level number. + // Evaluate proximal output level. If the compaction supports + // per_key_placement feature, it returns the proximal level number. // Otherwise, it's set to kInvalidLevel (-1), which means - // output_to_penultimate_level is not supported. - // Note: even the penultimate level output is supported (PenultimateLevel != + // output_to_proximal_level is not supported. + // Note: even the proximal level output is supported (ProximalLevel != // kInvalidLevel), some key range maybe unsafe to be outputted to the - // penultimate level. The safe key range is populated by - // `PopulatePenultimateLevelOutputRange()`. - // Which could potentially disable all penultimate level output. - static int EvaluatePenultimateLevel( - const VersionStorageInfo* vstorage, - const MutableCFOptions& mutable_cf_options, - const ImmutableOptions& immutable_options, const int start_level, - const int output_level); + // proximal level. The safe key range is populated by + // `PopulateProximalLevelOutputRange()`. + // Which could potentially disable all proximal level output. + static int EvaluateProximalLevel(const VersionStorageInfo* vstorage, + const MutableCFOptions& mutable_cf_options, + const ImmutableOptions& immutable_options, + const int start_level, + const int output_level); // If some data cannot be safely migrated "up" the LSM tree due to a change // in the preclude_last_level_data_seconds setting, this indicates a sequence @@ -482,10 +482,10 @@ class Compaction { InternalKey* smallest_key, InternalKey* largest_key, int exclude_level = -1); - // populate penultimate level output range, which will be used to determine if - // a key is safe to output to the penultimate level (details see - // `Compaction::WithinPenultimateLevelOutputRange()`. - void PopulatePenultimateLevelOutputRange(); + // populate proximal level output range, which will be used to determine if + // a key is safe to output to the proximal level (details see + // `Compaction::WithinProximalLevelOutputRange()`. + void PopulateProximalLevelOutputRange(); // If oldest snapshot is specified at Compaction construction time, we have // an opportunity to optimize inputs for compaction iterator for this case: @@ -616,20 +616,20 @@ class Compaction { // only set when per_key_placement feature is enabled, -1 (kInvalidLevel) // means not supported. - const int penultimate_level_; + const int proximal_level_; - // Key range for penultimate level output + // Key range for proximal level output // includes timestamp if user-defined timestamp is enabled. - // penultimate_output_range_type_ shows the range type - InternalKey penultimate_level_smallest_; - InternalKey penultimate_level_largest_; - PenultimateOutputRangeType penultimate_output_range_type_ = - PenultimateOutputRangeType::kNotSupported; + // proximal_output_range_type_ shows the range type + InternalKey proximal_level_smallest_; + InternalKey proximal_level_largest_; + ProximalOutputRangeType proximal_output_range_type_ = + ProximalOutputRangeType::kNotSupported; }; #ifndef NDEBUG // Helper struct only for tests, which contains the data to decide if a key -// should be output to the penultimate level. +// should be output to the proximal level. // TODO: remove this when the public feature knob is available struct PerKeyPlacementContext { const int level; @@ -637,16 +637,16 @@ struct PerKeyPlacementContext { const Slice value; const SequenceNumber seq_num; - bool& output_to_penultimate_level; + bool& output_to_proximal_level; PerKeyPlacementContext(int _level, Slice _key, Slice _value, SequenceNumber _seq_num, - bool& _output_to_penultimate_level) + bool& _output_to_proximal_level) : level(_level), key(_key), value(_value), seq_num(_seq_num), - output_to_penultimate_level(_output_to_penultimate_level) {} + output_to_proximal_level(_output_to_proximal_level) {} }; #endif /* !NDEBUG */ diff --git a/db/compaction/compaction_job.cc b/db/compaction/compaction_job.cc index 3e8bbdb2c34..46939e988cd 100644 --- a/db/compaction/compaction_job.cc +++ b/db/compaction/compaction_job.cc @@ -109,16 +109,16 @@ const char* GetCompactionReasonString(CompactionReason compaction_reason) { } } -const char* GetCompactionPenultimateOutputRangeTypeString( - Compaction::PenultimateOutputRangeType range_type) { +const char* GetCompactionProximalOutputRangeTypeString( + Compaction::ProximalOutputRangeType range_type) { switch (range_type) { - case Compaction::PenultimateOutputRangeType::kNotSupported: + case Compaction::ProximalOutputRangeType::kNotSupported: return "NotSupported"; - case Compaction::PenultimateOutputRangeType::kFullRange: + case Compaction::ProximalOutputRangeType::kFullRange: return "FullRange"; - case Compaction::PenultimateOutputRangeType::kNonLastRange: + case Compaction::ProximalOutputRangeType::kNonLastRange: return "NonLastRange"; - case Compaction::PenultimateOutputRangeType::kDisabled: + case Compaction::ProximalOutputRangeType::kDisabled: return "Disabled"; default: assert(false); @@ -378,8 +378,8 @@ void CompactionJob::Prepare( } // Now combine what we would like to preclude from last level with what we // can safely support without dangerously moving data back up the LSM tree, - // to get the final seqno threshold for penultimate vs. last. In particular, - // when the reserved output key range for the penultimate level does not + // to get the final seqno threshold for proximal vs. last. In particular, + // when the reserved output key range for the proximal level does not // include the entire last level input key range, we need to keep entries // already in the last level there. (Even allowing within-range entries to // move back up could cause problems with range tombstones. Perhaps it @@ -388,8 +388,8 @@ void CompactionJob::Prepare( // tracking and complexity to CompactionIterator that is probably not // worthwhile overall. Correctness is also more clear when splitting by // seqno threshold.) - penultimate_after_seqno_ = std::max(preclude_last_level_min_seqno, - c->GetKeepInLastLevelThroughSeqno()); + proximal_after_seqno_ = std::max(preclude_last_level_min_seqno, + c->GetKeepInLastLevelThroughSeqno()); options_file_number_ = versions_->options_file_number(); } @@ -993,16 +993,16 @@ Status CompactionJob::Install(bool* compaction_released) { blob_files.back()->GetBlobFileNumber()); } - if (compaction_stats_.has_penultimate_level_output) { - ROCKS_LOG_BUFFER( - log_buffer_, - "[%s] has Penultimate Level output: %" PRIu64 - ", level %d, number of files: %" PRIu64 ", number of records: %" PRIu64, - column_family_name.c_str(), - compaction_stats_.penultimate_level_stats.bytes_written, - compact_->compaction->GetPenultimateLevel(), - compaction_stats_.penultimate_level_stats.num_output_files, - compaction_stats_.penultimate_level_stats.num_output_records); + if (compaction_stats_.has_proximal_level_output) { + ROCKS_LOG_BUFFER(log_buffer_, + "[%s] has Proximal Level output: %" PRIu64 + ", level %d, number of files: %" PRIu64 + ", number of records: %" PRIu64, + column_family_name.c_str(), + compaction_stats_.proximal_level_stats.bytes_written, + compact_->compaction->GetProximalLevel(), + compaction_stats_.proximal_level_stats.num_output_files, + compaction_stats_.proximal_level_stats.num_output_records); } UpdateCompactionJobStats(stats); @@ -1055,16 +1055,16 @@ Status CompactionJob::Install(bool* compaction_released) { stream << "blob_file_tail" << blob_files.back()->GetBlobFileNumber(); } - if (compaction_stats_.has_penultimate_level_output) { + if (compaction_stats_.has_proximal_level_output) { InternalStats::CompactionStats& pl_stats = - compaction_stats_.penultimate_level_stats; - stream << "penultimate_level_num_output_files" << pl_stats.num_output_files; - stream << "penultimate_level_bytes_written" << pl_stats.bytes_written; - stream << "penultimate_level_num_output_records" + compaction_stats_.proximal_level_stats; + stream << "proximal_level_num_output_files" << pl_stats.num_output_files; + stream << "proximal_level_bytes_written" << pl_stats.bytes_written; + stream << "proximal_level_num_output_records" << pl_stats.num_output_records; - stream << "penultimate_level_num_output_files_blob" + stream << "proximal_level_num_output_files_blob" << pl_stats.num_output_files_blob; - stream << "penultimate_level_bytes_written_blob" + stream << "proximal_level_bytes_written_blob" << pl_stats.bytes_written_blob; } @@ -1312,7 +1312,7 @@ void CompactionJob::ProcessKeyValueCompaction(SubcompactionState* sub_compact) { std::vector blob_file_paths; - // TODO: BlobDB to support output_to_penultimate_level compaction, which needs + // TODO: BlobDB to support output_to_proximal_level compaction, which needs // 2 builders, so may need to move to `CompactionOutputs` std::unique_ptr blob_file_builder( (mutable_cf_options.enable_blob_files && @@ -1397,30 +1397,30 @@ void CompactionJob::ProcessKeyValueCompaction(SubcompactionState* sub_compact) { } const auto& ikey = c_iter->ikey(); - bool use_penultimate_output = ikey.sequence > penultimate_after_seqno_; + bool use_proximal_output = ikey.sequence > proximal_after_seqno_; #ifndef NDEBUG if (sub_compact->compaction->SupportsPerKeyPlacement()) { // Could be overridden by unittest PerKeyPlacementContext context(sub_compact->compaction->output_level(), ikey.user_key, c_iter->value(), - ikey.sequence, use_penultimate_output); + ikey.sequence, use_proximal_output); TEST_SYNC_POINT_CALLBACK("CompactionIterator::PrepareOutput.context", &context); - if (use_penultimate_output) { - // Verify that entries sent to the penultimate level are within the + if (use_proximal_output) { + // Verify that entries sent to the proximal level are within the // allowed range (because the input key range of the last level could - // be larger than the allowed output key range of the penultimate + // be larger than the allowed output key range of the proximal // level). This check uses user keys (ignores sequence numbers) because // compaction boundaries are a "clean cut" between user keys (see // CompactionPicker::ExpandInputsToCleanCut()), which is especially // important when preferred sequence numbers has been swapped in for // kTypeValuePreferredSeqno / TimedPut. - sub_compact->compaction->TEST_AssertWithinPenultimateLevelOutputRange( + sub_compact->compaction->TEST_AssertWithinProximalLevelOutputRange( c_iter->user_key()); } } else { - assert(penultimate_after_seqno_ == kMaxSequenceNumber); - assert(!use_penultimate_output); + assert(proximal_after_seqno_ == kMaxSequenceNumber); + assert(!use_proximal_output); } #endif // NDEBUG @@ -1429,7 +1429,7 @@ void CompactionJob::ProcessKeyValueCompaction(SubcompactionState* sub_compact) { // and `close_file_func`. // TODO: it would be better to have the compaction file open/close moved // into `CompactionOutputs` which has the output file information. - status = sub_compact->AddToOutput(*c_iter, use_penultimate_output, + status = sub_compact->AddToOutput(*c_iter, use_proximal_output, open_file_func, close_file_func); if (!status.ok()) { break; @@ -1641,15 +1641,15 @@ Status CompactionJob::FinishCompactionOutputFile( std::pair keep_seqno_range{ 0, kMaxSequenceNumber}; if (sub_compact->compaction->SupportsPerKeyPlacement()) { - if (outputs.IsPenultimateLevel()) { - keep_seqno_range.first = penultimate_after_seqno_; + if (outputs.IsProximalLevel()) { + keep_seqno_range.first = proximal_after_seqno_; } else { - keep_seqno_range.second = penultimate_after_seqno_; + keep_seqno_range.second = proximal_after_seqno_; } } CompactionIterationStats range_del_out_stats; // NOTE1: Use `bottommost_level_ = true` for both bottommost and - // output_to_penultimate_level compaction here, as it's only used to decide + // output_to_proximal_level compaction here, as it's only used to decide // if range dels could be dropped. (Logically, we are taking a single sorted // run returned from CompactionIterator and physically splitting it between // two output levels.) @@ -1812,14 +1812,14 @@ Status CompactionJob::InstallCompactionResults(bool* compaction_released) { { Compaction::InputLevelSummaryBuffer inputs_summary; - if (compaction_stats_.has_penultimate_level_output) { + if (compaction_stats_.has_proximal_level_output) { ROCKS_LOG_BUFFER( log_buffer_, - "[%s] [JOB %d] Compacted %s => output_to_penultimate_level: %" PRIu64 + "[%s] [JOB %d] Compacted %s => output_to_proximal_level: %" PRIu64 " bytes + last: %" PRIu64 " bytes. Total: %" PRIu64 " bytes", compaction->column_family_data()->GetName().c_str(), job_id_, compaction->InputLevelSummary(&inputs_summary), - compaction_stats_.penultimate_level_stats.bytes_written, + compaction_stats_.proximal_level_stats.bytes_written, compaction_stats_.stats.bytes_written, compaction_stats_.TotalBytesWritten()); } else { @@ -1946,8 +1946,7 @@ Status CompactionJob::OpenCompactionOutputFile(SubcompactionState* sub_compact, // Here last_level_temperature supersedes default_write_temperature, when // enabled and applicable if (last_level_temp != Temperature::kUnknown && - sub_compact->compaction->is_last_level() && - !outputs.IsPenultimateLevel()) { + sub_compact->compaction->is_last_level() && !outputs.IsProximalLevel()) { temperature = last_level_temp; } fo_copy.temperature = temperature; @@ -2061,7 +2060,7 @@ Status CompactionJob::OpenCompactionOutputFile(SubcompactionState* sub_compact, bottommost_level_, TableFileCreationReason::kCompaction, 0 /* oldest_key_time */, current_time, db_id_, db_session_id_, sub_compact->compaction->max_output_file_size(), file_number, - penultimate_after_seqno_ /*last_level_inclusive_max_seqno_threshold*/); + proximal_after_seqno_ /*last_level_inclusive_max_seqno_threshold*/); outputs.NewBuilder(tboptions); @@ -2232,19 +2231,19 @@ void CompactionJob::LogCompaction() { ? int64_t{-1} // Use -1 for "none" : static_cast(existing_snapshots_[0])); if (compaction->SupportsPerKeyPlacement()) { - stream << "prenultimate_after_seqno" << penultimate_after_seqno_; + stream << "proximal_after_seqno" << proximal_after_seqno_; stream << "preserve_seqno_after" << preserve_seqno_after_; - stream << "penultimate_output_level" << compaction->GetPenultimateLevel(); - stream << "penultimate_output_range" - << GetCompactionPenultimateOutputRangeTypeString( - compaction->GetPenultimateOutputRangeType()); + stream << "proximal_output_level" << compaction->GetProximalLevel(); + stream << "proximal_output_range" + << GetCompactionProximalOutputRangeTypeString( + compaction->GetProximalOutputRangeType()); - if (compaction->GetPenultimateOutputRangeType() == - Compaction::PenultimateOutputRangeType::kDisabled) { + if (compaction->GetProximalOutputRangeType() == + Compaction::ProximalOutputRangeType::kDisabled) { ROCKS_LOG_WARN( db_options_.info_log, - "[%s] [JOB %d] Penultimate level output is disabled, likely " - "because of the range conflict in the penultimate level", + "[%s] [JOB %d] Proximal level output is disabled, likely " + "because of the range conflict in the proximal level", cfd->GetName().c_str(), job_id_); } } diff --git a/db/compaction/compaction_job.h b/db/compaction/compaction_job.h index ea4839f2158..e990124d9e9 100644 --- a/db/compaction/compaction_job.h +++ b/db/compaction/compaction_job.h @@ -104,9 +104,9 @@ class SubcompactionState; // logging and public metrics. // Internally, it's an aggregation of stats_ from each `SubcompactionState`. // It has 2 parts, normal stats about the main compaction information and -// the penultimate level output stats. -// `SubcompactionState` maintains the CompactionOutputs for normal output and -// the penultimate level output if exists, the per_level stats is +// the proximal level output stats. +// `SubcompactionState` maintains the CompactionOutputs for ordinary level +// output and the proximal level output if exists, the per_level stats is // stored with the outputs. // +---------------------------+ // | SubcompactionState | @@ -119,7 +119,7 @@ class SubcompactionState; // | | | // | | +----------------------+ | // +--------------------------------+ | | | CompactionOutputs | | -// | CompactionJob | | | | (penultimate_level) | | +// | CompactionJob | | | | (proximal_level) | | // | | +--------->| stats_ | | // | compaction_stats_ | | | | +----------------------+ | // | +-------------------------+ | | | | | @@ -127,7 +127,7 @@ class SubcompactionState; // | +-------------------------+ | | | // | | | | // | +-------------------------+ | | | +---------------------------+ -// | |penultimate_level_stats +------+ | | SubcompactionState | +// | |proximal_level_stats |------+ | | SubcompactionState | // | +-------------------------+ | | | | | // | | | | | +----------------------+ | // | | | | | | CompactionOutputs | | @@ -137,7 +137,7 @@ class SubcompactionState; // | | | // | | +----------------------+ | // | | | CompactionOutputs | | -// | | | (penultimate_level) | | +// | | | (proximal_level) | | // +--------->| stats_ | | // | +----------------------+ | // | | @@ -363,8 +363,8 @@ class CompactionJob { // Minimal sequence number to preclude the data from the last level. If the // key has bigger (newer) sequence number than this, it will be precluded from - // the last level (output to penultimate level). - SequenceNumber penultimate_after_seqno_ = kMaxSequenceNumber; + // the last level (output to proximal level). + SequenceNumber proximal_after_seqno_ = kMaxSequenceNumber; // Options File Number used for Remote Compaction // Setting this requires DBMutex. @@ -431,8 +431,7 @@ struct CompactionServiceOutputFile { bool marked_for_compaction; UniqueId64x2 unique_id{}; TableProperties table_properties; - // TODO: clean up the rest of the "penultimate" naming in the codebase - bool is_proximal_level_output; // == is_penultimate_level_output + bool is_proximal_level_output; Temperature file_temperature; CompactionServiceOutputFile() = default; diff --git a/db/compaction/compaction_job_test.cc b/db/compaction/compaction_job_test.cc index 2eb354f89e3..b7afc07b996 100644 --- a/db/compaction/compaction_job_test.cc +++ b/db/compaction/compaction_job_test.cc @@ -1474,7 +1474,7 @@ TEST_F(CompactionJobTest, OldestBlobFileNumber) { /* expected_oldest_blob_file_numbers */ {19}); } -TEST_F(CompactionJobTest, VerifyPenultimateLevelOutput) { +TEST_F(CompactionJobTest, VerifyProximalLevelOutput) { cf_options_.last_level_temperature = Temperature::kCold; SyncPoint::GetInstance()->SetCallBack( "Compaction::SupportsPerKeyPlacement:Enabled", [&](void* arg) { @@ -1487,8 +1487,7 @@ TEST_F(CompactionJobTest, VerifyPenultimateLevelOutput) { SyncPoint::GetInstance()->SetCallBack( "CompactionIterator::PrepareOutput.context", [&](void* arg) { auto context = static_cast(arg); - context->output_to_penultimate_level = - context->seq_num > latest_cold_seq; + context->output_to_proximal_level = context->seq_num > latest_cold_seq; }); SyncPoint::GetInstance()->EnableProcessing(); @@ -1534,11 +1533,11 @@ TEST_F(CompactionJobTest, VerifyPenultimateLevelOutput) { /*verify_func=*/[&](Compaction& comp) { for (char c = 'a'; c <= 'z'; c++) { if (c == 'a') { - comp.TEST_AssertWithinPenultimateLevelOutputRange( + comp.TEST_AssertWithinProximalLevelOutputRange( "a", true /*expect_failure*/); } else { std::string c_str{c}; - comp.TEST_AssertWithinPenultimateLevelOutputRange(c_str); + comp.TEST_AssertWithinProximalLevelOutputRange(c_str); } } }); diff --git a/db/compaction/compaction_outputs.cc b/db/compaction/compaction_outputs.cc index 3e1c4402cea..d3a0c711ac6 100644 --- a/db/compaction/compaction_outputs.cc +++ b/db/compaction/compaction_outputs.cc @@ -792,8 +792,8 @@ void CompactionOutputs::FillFilesToCutForTtl() { } CompactionOutputs::CompactionOutputs(const Compaction* compaction, - const bool is_penultimate_level) - : compaction_(compaction), is_penultimate_level_(is_penultimate_level) { + const bool is_proximal_level) + : compaction_(compaction), is_proximal_level_(is_proximal_level) { partitioner_ = compaction->output_level() == 0 ? nullptr : compaction->CreateSstPartitioner(); diff --git a/db/compaction/compaction_outputs.h b/db/compaction/compaction_outputs.h index 6b88eb452a0..a95bdaaa7ab 100644 --- a/db/compaction/compaction_outputs.h +++ b/db/compaction/compaction_outputs.h @@ -31,31 +31,31 @@ class CompactionOutputs { struct Output { Output(FileMetaData&& _meta, const InternalKeyComparator& _icmp, bool _enable_hash, bool _finished, uint64_t precalculated_hash, - bool _is_penultimate_level) + bool _is_proximal_level) : meta(std::move(_meta)), validator(_icmp, _enable_hash, precalculated_hash), finished(_finished), - is_penultimate_level(_is_penultimate_level) {} + is_proximal_level(_is_proximal_level) {} FileMetaData meta; OutputValidator validator; bool finished; - bool is_penultimate_level; + bool is_proximal_level; std::shared_ptr table_properties; }; CompactionOutputs() = delete; explicit CompactionOutputs(const Compaction* compaction, - const bool is_penultimate_level); + const bool is_proximal_level); - bool IsPenultimateLevel() const { return is_penultimate_level_; } + bool IsProximalLevel() const { return is_proximal_level_; } // Add generated output to the list void AddOutput(FileMetaData&& meta, const InternalKeyComparator& icmp, bool enable_hash, bool finished = false, uint64_t precalculated_hash = 0) { outputs_.emplace_back(std::move(meta), icmp, enable_hash, finished, - precalculated_hash, is_penultimate_level_); + precalculated_hash, is_proximal_level_); } // Set new table builder for the current output @@ -73,27 +73,27 @@ class CompactionOutputs { // TODO: Move the BlobDB builder into CompactionOutputs const std::vector& GetBlobFileAdditions() const { - if (is_penultimate_level_) { + if (is_proximal_level_) { assert(blob_file_additions_.empty()); } return blob_file_additions_; } std::vector* GetBlobFileAdditionsPtr() { - assert(!is_penultimate_level_); + assert(!is_proximal_level_); return &blob_file_additions_; } bool HasBlobFileAdditions() const { return !blob_file_additions_.empty(); } BlobGarbageMeter* CreateBlobGarbageMeter() { - assert(!is_penultimate_level_); + assert(!is_proximal_level_); blob_garbage_meter_ = std::make_unique(); return blob_garbage_meter_.get(); } BlobGarbageMeter* GetBlobGarbageMeter() const { - if (is_penultimate_level_) { + if (is_proximal_level_) { // blobdb doesn't support per_key_placement yet assert(blob_garbage_meter_ == nullptr); return nullptr; @@ -102,7 +102,7 @@ class CompactionOutputs { } void UpdateBlobStats() { - assert(!is_penultimate_level_); + assert(!is_proximal_level_); stats_.num_output_files_blob = blob_file_additions_.size(); for (const auto& blob : blob_file_additions_) { stats_.bytes_written_blob += blob.GetTotalBlobBytes(); @@ -310,9 +310,9 @@ class CompactionOutputs { // Basic compaction output stats for this level's outputs InternalStats::CompactionOutputsStats stats_; - // indicate if this CompactionOutputs obj for penultimate_level, should always + // indicate if this CompactionOutputs obj for proximal_level, should always // be false if per_key_placement feature is not enabled. - const bool is_penultimate_level_; + const bool is_proximal_level_; // partitioner information std::string last_key_for_partitioner_; @@ -366,7 +366,7 @@ class CompactionOutputs { std::vector level_ptrs_; }; -// helper struct to concatenate the last level and penultimate level outputs +// helper struct to concatenate the last level and proximal level outputs // which could be replaced by std::ranges::join_view() in c++20 struct OutputIterator { public: diff --git a/db/compaction/compaction_picker.cc b/db/compaction/compaction_picker.cc index 946dab5ddef..f65556d38de 100644 --- a/db/compaction/compaction_picker.cc +++ b/db/compaction/compaction_picker.cc @@ -272,8 +272,8 @@ bool CompactionPicker::RangeOverlapWithCompaction( return true; } if (c->SupportsPerKeyPlacement()) { - if (c->OverlapPenultimateLevelOutputRange(smallest_user_key, - largest_user_key)) { + if (c->OverlapProximalLevelOutputRange(smallest_user_key, + largest_user_key)) { return true; } } @@ -284,7 +284,7 @@ bool CompactionPicker::RangeOverlapWithCompaction( bool CompactionPicker::FilesRangeOverlapWithCompaction( const std::vector& inputs, int level, - int penultimate_level) const { + int proximal_level) const { bool is_empty = true; for (auto& in : inputs) { if (!in.empty()) { @@ -301,18 +301,18 @@ bool CompactionPicker::FilesRangeOverlapWithCompaction( // files cannot be overlapped in the order of L0 files. InternalKey smallest, largest; GetRange(inputs, &smallest, &largest, Compaction::kInvalidLevel); - if (penultimate_level != Compaction::kInvalidLevel) { + if (proximal_level != Compaction::kInvalidLevel) { if (ioptions_.compaction_style == kCompactionStyleUniversal) { if (RangeOverlapWithCompaction(smallest.user_key(), largest.user_key(), - penultimate_level)) { + proximal_level)) { return true; } } else { - InternalKey penultimate_smallest, penultimate_largest; - GetRange(inputs, &penultimate_smallest, &penultimate_largest, level); - if (RangeOverlapWithCompaction(penultimate_smallest.user_key(), - penultimate_largest.user_key(), - penultimate_level)) { + InternalKey proximal_smallest, proximal_largest; + GetRange(inputs, &proximal_smallest, &proximal_largest, level); + if (RangeOverlapWithCompaction(proximal_smallest.user_key(), + proximal_largest.user_key(), + proximal_level)) { return true; } } @@ -353,7 +353,7 @@ Compaction* CompactionPicker::CompactFiles( } assert(output_level == 0 || !FilesRangeOverlapWithCompaction( input_files, output_level, - Compaction::EvaluatePenultimateLevel( + Compaction::EvaluateProximalLevel( vstorage, mutable_cf_options, ioptions_, start_level, output_level))); #endif /* !NDEBUG */ @@ -659,9 +659,9 @@ Compaction* CompactionPicker::CompactRange( // overlaping outputs in the same level. if (FilesRangeOverlapWithCompaction( inputs, output_level, - Compaction::EvaluatePenultimateLevel(vstorage, mutable_cf_options, - ioptions_, start_level, - output_level))) { + Compaction::EvaluateProximalLevel(vstorage, mutable_cf_options, + ioptions_, start_level, + output_level))) { // This compaction output could potentially conflict with the output // of a currently running compaction, we cannot run it. *manual_conflict = true; @@ -848,9 +848,9 @@ Compaction* CompactionPicker::CompactRange( // overlaping outputs in the same level. if (FilesRangeOverlapWithCompaction( compaction_inputs, output_level, - Compaction::EvaluatePenultimateLevel(vstorage, mutable_cf_options, - ioptions_, input_level, - output_level))) { + Compaction::EvaluateProximalLevel(vstorage, mutable_cf_options, + ioptions_, input_level, + output_level))) { // This compaction output could potentially conflict with the output // of a currently running compaction, we cannot run it. *manual_conflict = true; @@ -1137,7 +1137,7 @@ Status CompactionPicker::SanitizeAndConvertCompactionInputFiles( if (output_level != 0 && FilesRangeOverlapWithCompaction( *converted_input_files, output_level, - Compaction::EvaluatePenultimateLevel( + Compaction::EvaluateProximalLevel( version->storage_info(), version->GetMutableCFOptions(), ioptions_, (*converted_input_files)[0].level, output_level))) { return Status::Aborted( @@ -1154,7 +1154,7 @@ void CompactionPicker::RegisterCompaction(Compaction* c) { assert(ioptions_.compaction_style != kCompactionStyleLevel || c->output_level() == 0 || !FilesRangeOverlapWithCompaction(*c->inputs(), c->output_level(), - c->GetPenultimateLevel())); + c->GetProximalLevel())); // CompactionReason::kExternalSstIngestion's start level is just a placeholder // number without actual meaning as file ingestion technically does not have // an input level like other compactions diff --git a/db/compaction/compaction_picker.h b/db/compaction/compaction_picker.h index 6285e054301..9d23555ec59 100644 --- a/db/compaction/compaction_picker.h +++ b/db/compaction/compaction_picker.h @@ -190,7 +190,7 @@ class CompactionPicker { // key range of a currently running compaction. bool FilesRangeOverlapWithCompaction( const std::vector& inputs, int level, - int penultimate_level) const; + int proximal_level) const; bool SetupOtherInputs(const std::string& cf_name, const MutableCFOptions& mutable_cf_options, diff --git a/db/compaction/compaction_picker_level.cc b/db/compaction/compaction_picker_level.cc index 612c1e5af21..b4a122954bf 100644 --- a/db/compaction/compaction_picker_level.cc +++ b/db/compaction/compaction_picker_level.cc @@ -414,9 +414,9 @@ void LevelCompactionBuilder::SetupOtherFilesWithRoundRobinExpansion() { &tmp_start_level_inputs) || compaction_picker_->FilesRangeOverlapWithCompaction( {tmp_start_level_inputs}, output_level_, - Compaction::EvaluatePenultimateLevel(vstorage_, mutable_cf_options_, - ioptions_, start_level_, - output_level_))) { + Compaction::EvaluateProximalLevel(vstorage_, mutable_cf_options_, + ioptions_, start_level_, + output_level_))) { // Constraint 1a tmp_start_level_inputs.clear(); return; @@ -490,9 +490,9 @@ bool LevelCompactionBuilder::SetupOtherInputsIfNeeded() { // We need to disallow this from happening. if (compaction_picker_->FilesRangeOverlapWithCompaction( compaction_inputs_, output_level_, - Compaction::EvaluatePenultimateLevel(vstorage_, mutable_cf_options_, - ioptions_, start_level_, - output_level_))) { + Compaction::EvaluateProximalLevel(vstorage_, mutable_cf_options_, + ioptions_, start_level_, + output_level_))) { // This compaction output could potentially conflict with the output // of a currently running compaction, we cannot run it. return false; @@ -846,9 +846,9 @@ bool LevelCompactionBuilder::PickFileToCompact() { &start_level_inputs_) || compaction_picker_->FilesRangeOverlapWithCompaction( {start_level_inputs_}, output_level_, - Compaction::EvaluatePenultimateLevel(vstorage_, mutable_cf_options_, - ioptions_, start_level_, - output_level_))) { + Compaction::EvaluateProximalLevel(vstorage_, mutable_cf_options_, + ioptions_, start_level_, + output_level_))) { // A locked (pending compaction) input-level file was pulled in due to // user-key overlap. start_level_inputs_.clear(); diff --git a/db/compaction/compaction_picker_test.cc b/db/compaction/compaction_picker_test.cc index f48195e29a0..35193db57ee 100644 --- a/db/compaction/compaction_picker_test.cc +++ b/db/compaction/compaction_picker_test.cc @@ -3677,7 +3677,7 @@ TEST_F(CompactionPickerTest, UniversalSizeRatioTierCompactionLastLevel) { const uint64_t kFileSize = 100000; const int kNumLevels = 7; const int kLastLevel = kNumLevels - 1; - const int kPenultimateLevel = kLastLevel - 1; + const int kProximalLevel = kLastLevel - 1; ioptions_.compaction_style = kCompactionStyleUniversal; mutable_cf_options_.preclude_last_level_data_seconds = 1000; @@ -3702,14 +3702,14 @@ TEST_F(CompactionPickerTest, UniversalSizeRatioTierCompactionLastLevel) { // Here to make sure it's size ratio compaction instead of size amp ASSERT_EQ(compaction->compaction_reason(), CompactionReason::kUniversalSizeRatio); - ASSERT_EQ(compaction->output_level(), kPenultimateLevel - 1); + ASSERT_EQ(compaction->output_level(), kProximalLevel - 1); ASSERT_EQ(compaction->input_levels(0)->num_files, 2); ASSERT_EQ(compaction->input_levels(5)->num_files, 0); ASSERT_EQ(compaction->input_levels(6)->num_files, 0); } TEST_F(CompactionPickerTest, UniversalSizeAmpTierCompactionNotSuport) { - // Tiered compaction only support level_num > 2 (otherwise the penultimate + // Tiered compaction only support level_num > 2 (otherwise the proximal // level is going to be level 0, which may make thing more complicated), so // when there's only 2 level, still treating level 1 as the last level for // size amp compaction @@ -3753,7 +3753,7 @@ TEST_F(CompactionPickerTest, UniversalSizeAmpTierCompactionLastLevel) { const uint64_t kFileSize = 100000; const int kNumLevels = 7; const int kLastLevel = kNumLevels - 1; - const int kPenultimateLevel = kLastLevel - 1; + const int kProximalLevel = kLastLevel - 1; ioptions_.compaction_style = kCompactionStyleUniversal; mutable_cf_options_.preclude_last_level_data_seconds = 1000; @@ -3775,10 +3775,10 @@ TEST_F(CompactionPickerTest, UniversalSizeAmpTierCompactionLastLevel) { vstorage_.get(), &log_buffer_)); // It's a Size Amp compaction, but doesn't include the last level file and - // output to the penultimate level. + // output to the proximal level. ASSERT_EQ(compaction->compaction_reason(), CompactionReason::kUniversalSizeAmplification); - ASSERT_EQ(compaction->output_level(), kPenultimateLevel); + ASSERT_EQ(compaction->output_level(), kProximalLevel); ASSERT_EQ(compaction->input_levels(0)->num_files, 2); ASSERT_EQ(compaction->input_levels(5)->num_files, 1); ASSERT_EQ(compaction->input_levels(6)->num_files, 0); @@ -3940,7 +3940,7 @@ TEST_P(PerKeyPlacementCompactionPickerTest, OverlapWithNormalCompaction) { ASSERT_EQ(enable_per_key_placement_, level_compaction_picker.FilesRangeOverlapWithCompaction( input_files, 6, - Compaction::EvaluatePenultimateLevel( + Compaction::EvaluateProximalLevel( vstorage_.get(), mutable_cf_options_, ioptions_, 0, 6))); } @@ -4028,7 +4028,7 @@ TEST_P(PerKeyPlacementCompactionPickerTest, ASSERT_EQ(enable_per_key_placement_, universal_compaction_picker.FilesRangeOverlapWithCompaction( input_files, 6, - Compaction::EvaluatePenultimateLevel( + Compaction::EvaluateProximalLevel( vstorage_.get(), mutable_cf_options_, ioptions_, 0, 6))); } @@ -4076,9 +4076,9 @@ TEST_P(PerKeyPlacementCompactionPickerTest, NormalCompactionOverlapUniversal) { input_files, 5, Compaction::kInvalidLevel)); } -TEST_P(PerKeyPlacementCompactionPickerTest, PenultimateOverlapUniversal) { +TEST_P(PerKeyPlacementCompactionPickerTest, ProximalOverlapUniversal) { // This test is make sure the Tiered compaction would lock whole range of - // both output level and penultimate level + // both output level and proximal level if (enable_per_key_placement_) { mutable_cf_options_.preclude_last_level_data_seconds = 10000; } @@ -4098,7 +4098,7 @@ TEST_P(PerKeyPlacementCompactionPickerTest, PenultimateOverlapUniversal) { UpdateVersionStorageInfo(); // the existing compaction is the 1st L4 file + L6 file - // then compaction of the 2nd L4 file to L5 (penultimate level) is overlapped + // then compaction of the 2nd L4 file to L5 (proximal level) is overlapped // when the tiered compaction feature is on. CompactionOptions comp_options; std::unordered_set input_set; @@ -4187,9 +4187,9 @@ TEST_P(PerKeyPlacementCompactionPickerTest, LastLevelOnlyOverlapUniversal) { } TEST_P(PerKeyPlacementCompactionPickerTest, - LastLevelOnlyFailPenultimateUniversal) { + LastLevelOnlyFailProximalUniversal) { // This is to test last_level only compaction still unable to do the - // penultimate level compaction if there's already a file in the penultimate + // proximal level compaction if there's already a file in the proximal // level. // This should rarely happen in universal compaction, as the non-empty L5 // should be included in the compaction. @@ -4222,9 +4222,9 @@ TEST_P(PerKeyPlacementCompactionPickerTest, mutable_db_options_, 0)); ASSERT_TRUE(comp1); - ASSERT_EQ(comp1->GetPenultimateLevel(), Compaction::kInvalidLevel); + ASSERT_EQ(comp1->GetProximalLevel(), Compaction::kInvalidLevel); - // As comp1 cannot be output to the penultimate level, compacting file 40 to + // As comp1 cannot be output to the proximal level, compacting file 40 to // L5 is always safe. input_set.clear(); input_files.clear(); @@ -4239,14 +4239,14 @@ TEST_P(PerKeyPlacementCompactionPickerTest, comp_options, input_files, 5, vstorage_.get(), mutable_cf_options_, mutable_db_options_, 0)); ASSERT_TRUE(comp2); - ASSERT_EQ(Compaction::kInvalidLevel, comp2->GetPenultimateLevel()); + ASSERT_EQ(Compaction::kInvalidLevel, comp2->GetProximalLevel()); } TEST_P(PerKeyPlacementCompactionPickerTest, LastLevelOnlyConflictWithOngoingUniversal) { // This is to test last_level only compaction still unable to do the - // penultimate level compaction if there's already an ongoing compaction to - // the penultimate level + // proximal level compaction if there's already an ongoing compaction to + // the proximal level if (enable_per_key_placement_) { mutable_cf_options_.preclude_last_level_data_seconds = 10000; } @@ -4265,7 +4265,7 @@ TEST_P(PerKeyPlacementCompactionPickerTest, Add(6, 60U, "101", "351", 60000000U); UpdateVersionStorageInfo(); - // create an ongoing compaction to L5 (penultimate level) + // create an ongoing compaction to L5 (proximal level) CompactionOptions comp_options; std::unordered_set input_set; input_set.insert(40); @@ -4278,7 +4278,7 @@ TEST_P(PerKeyPlacementCompactionPickerTest, mutable_db_options_, 0)); ASSERT_TRUE(comp1); - ASSERT_EQ(comp1->GetPenultimateLevel(), Compaction::kInvalidLevel); + ASSERT_EQ(comp1->GetProximalLevel(), Compaction::kInvalidLevel); input_set.clear(); input_files.clear(); @@ -4289,7 +4289,7 @@ TEST_P(PerKeyPlacementCompactionPickerTest, ASSERT_EQ(enable_per_key_placement_, universal_compaction_picker.FilesRangeOverlapWithCompaction( input_files, 6, - Compaction::EvaluatePenultimateLevel( + Compaction::EvaluateProximalLevel( vstorage_.get(), mutable_cf_options_, ioptions_, 6, 6))); if (!enable_per_key_placement_) { @@ -4297,7 +4297,7 @@ TEST_P(PerKeyPlacementCompactionPickerTest, comp_options, input_files, 6, vstorage_.get(), mutable_cf_options_, mutable_db_options_, 0)); ASSERT_TRUE(comp2); - ASSERT_EQ(Compaction::kInvalidLevel, comp2->GetPenultimateLevel()); + ASSERT_EQ(Compaction::kInvalidLevel, comp2->GetProximalLevel()); } } @@ -4306,7 +4306,7 @@ TEST_P(PerKeyPlacementCompactionPickerTest, // This is similar to `LastLevelOnlyConflictWithOngoingUniversal`, the only // change is the ongoing compaction to L5 has no overlap with the last level // compaction, so it's safe to move data from the last level to the - // penultimate level. + // proximal level. if (enable_per_key_placement_) { mutable_cf_options_.preclude_last_level_data_seconds = 10000; } @@ -4325,7 +4325,7 @@ TEST_P(PerKeyPlacementCompactionPickerTest, Add(6, 60U, "101", "351", 60000000U); UpdateVersionStorageInfo(); - // create an ongoing compaction to L5 (penultimate level) + // create an ongoing compaction to L5 (proximal level) CompactionOptions comp_options; std::unordered_set input_set; input_set.insert(42); @@ -4338,7 +4338,7 @@ TEST_P(PerKeyPlacementCompactionPickerTest, mutable_db_options_, 0)); ASSERT_TRUE(comp1); - ASSERT_EQ(comp1->GetPenultimateLevel(), Compaction::kInvalidLevel); + ASSERT_EQ(comp1->GetProximalLevel(), Compaction::kInvalidLevel); input_set.clear(); input_files.clear(); @@ -4349,8 +4349,8 @@ TEST_P(PerKeyPlacementCompactionPickerTest, // always safe to move data up ASSERT_FALSE(universal_compaction_picker.FilesRangeOverlapWithCompaction( input_files, 6, - Compaction::EvaluatePenultimateLevel(vstorage_.get(), mutable_cf_options_, - ioptions_, 6, 6))); + Compaction::EvaluateProximalLevel(vstorage_.get(), mutable_cf_options_, + ioptions_, 6, 6))); // 2 compactions can be run in parallel std::unique_ptr comp2(universal_compaction_picker.CompactFiles( @@ -4358,9 +4358,9 @@ TEST_P(PerKeyPlacementCompactionPickerTest, mutable_db_options_, 0)); ASSERT_TRUE(comp2); if (enable_per_key_placement_) { - ASSERT_NE(Compaction::kInvalidLevel, comp2->GetPenultimateLevel()); + ASSERT_NE(Compaction::kInvalidLevel, comp2->GetProximalLevel()); } else { - ASSERT_EQ(Compaction::kInvalidLevel, comp2->GetPenultimateLevel()); + ASSERT_EQ(Compaction::kInvalidLevel, comp2->GetProximalLevel()); } } diff --git a/db/compaction/compaction_picker_universal.cc b/db/compaction/compaction_picker_universal.cc index 427abb9eabc..f2bc740028e 100644 --- a/db/compaction/compaction_picker_universal.cc +++ b/db/compaction/compaction_picker_universal.cc @@ -288,7 +288,9 @@ class UniversalCompactionBuilder { // and the index of the file in that level struct InputFileInfo { - InputFileInfo() : f(nullptr), level(0), index(0) {} + InputFileInfo() : InputFileInfo(nullptr, 0, 0) {} + InputFileInfo(FileMetaData* file_meta, size_t l, size_t i) + : f(file_meta), level(l), index(i) {} FileMetaData* f; size_t level; @@ -321,22 +323,14 @@ SmallestKeyHeap create_level_heap(Compaction* c, const Comparator* ucmp) { SmallestKeyHeap smallest_key_priority_q = SmallestKeyHeap(SmallestKeyHeapComparator(ucmp)); - InputFileInfo input_file; - for (size_t l = 0; l < c->num_input_levels(); l++) { if (c->num_input_files(l) != 0) { if (l == 0 && c->start_level() == 0) { for (size_t i = 0; i < c->num_input_files(0); i++) { - input_file.f = c->input(0, i); - input_file.level = 0; - input_file.index = i; - smallest_key_priority_q.push(std::move(input_file)); + smallest_key_priority_q.emplace(c->input(0, i), 0, i); } } else { - input_file.f = c->input(l, 0); - input_file.level = l; - input_file.index = 0; - smallest_key_priority_q.push(std::move(input_file)); + smallest_key_priority_q.emplace(c->input(l, 0), l, 0); } } } @@ -374,7 +368,7 @@ bool UniversalCompactionBuilder::IsInputFilesNonOverlapping(Compaction* c) { auto comparator = icmp_->user_comparator(); int first_iter = 1; - InputFileInfo prev, curr, next; + InputFileInfo prev, curr; SmallestKeyHeap smallest_key_priority_q = create_level_heap(c, icmp_->user_comparator()); @@ -397,17 +391,10 @@ bool UniversalCompactionBuilder::IsInputFilesNonOverlapping(Compaction* c) { prev = curr; } - next.f = nullptr; - if (c->level(curr.level) != 0 && curr.index < c->num_input_files(curr.level) - 1) { - next.f = c->input(curr.level, curr.index + 1); - next.level = curr.level; - next.index = curr.index + 1; - } - - if (next.f) { - smallest_key_priority_q.push(std::move(next)); + smallest_key_priority_q.emplace(c->input(curr.level, curr.index + 1), + curr.level, curr.index + 1); } } return true; @@ -996,7 +983,7 @@ Compaction* UniversalCompactionBuilder::PickCompactionToReduceSortedRuns( if (output_level != 0 && picker_->FilesRangeOverlapWithCompaction( inputs, output_level, - Compaction::EvaluatePenultimateLevel( + Compaction::EvaluateProximalLevel( vstorage_, mutable_cf_options_, ioptions_, start_level, output_level))) { return nullptr; @@ -1345,7 +1332,7 @@ Compaction* UniversalCompactionBuilder::PickIncrementalForReduceSizeAmp( // intra L0 compactions outputs could have overlap if (output_level != 0 && picker_->FilesRangeOverlapWithCompaction( inputs, output_level, - Compaction::EvaluatePenultimateLevel( + Compaction::EvaluateProximalLevel( vstorage_, mutable_cf_options_, ioptions_, start_level, output_level))) { return nullptr; @@ -1486,9 +1473,9 @@ Compaction* UniversalCompactionBuilder::PickDeleteTriggeredCompaction() { } if (picker_->FilesRangeOverlapWithCompaction( inputs, output_level, - Compaction::EvaluatePenultimateLevel( - vstorage_, mutable_cf_options_, ioptions_, start_level, - output_level))) { + Compaction::EvaluateProximalLevel(vstorage_, mutable_cf_options_, + ioptions_, start_level, + output_level))) { return nullptr; } @@ -1590,7 +1577,7 @@ Compaction* UniversalCompactionBuilder::PickCompactionWithSortedRunRange( // intra L0 compactions outputs could have overlap if (output_level != 0 && picker_->FilesRangeOverlapWithCompaction( inputs, output_level, - Compaction::EvaluatePenultimateLevel( + Compaction::EvaluateProximalLevel( vstorage_, mutable_cf_options_, ioptions_, start_level, output_level))) { return nullptr; diff --git a/db/compaction/compaction_service_job.cc b/db/compaction/compaction_service_job.cc index cc75729bfe0..0b6afa10e6b 100644 --- a/db/compaction/compaction_service_job.cc +++ b/db/compaction/compaction_service_job.cc @@ -391,8 +391,8 @@ Status CompactionServiceCompactionJob::Run() { // 2. Update the Output information in the Compaction Job Stats with // aggregated Internal Compaction Stats. UpdateCompactionJobStats(compaction_stats_.stats); - if (compaction_stats_.has_penultimate_level_output) { - UpdateCompactionJobStats(compaction_stats_.penultimate_level_stats); + if (compaction_stats_.has_proximal_level_output) { + UpdateCompactionJobStats(compaction_stats_.proximal_level_stats); } // 3. Set fields that are not propagated as part of aggregations above @@ -417,7 +417,7 @@ Status CompactionServiceCompactionJob::Run() { meta.file_creation_time, meta.epoch_number, meta.file_checksum, meta.file_checksum_func_name, output_file.validator.GetHash(), meta.marked_for_compaction, meta.unique_id, - *output_file.table_properties, output_file.is_penultimate_level, + *output_file.table_properties, output_file.is_proximal_level, meta.temperature); } } diff --git a/db/compaction/compaction_service_test.cc b/db/compaction/compaction_service_test.cc index 064eae37fe8..af3cfa029ce 100644 --- a/db/compaction/compaction_service_test.cc +++ b/db/compaction/compaction_service_test.cc @@ -1194,7 +1194,7 @@ TEST_F(CompactionServiceTest, PrecludeLastLevel) { } ASSERT_OK(dbfull()->TEST_WaitForCompact()); - // Data split between penultimate (kUnknown) and last (kCold) levels + // Data split between proximal (kUnknown) and last (kCold) levels ASSERT_EQ("0,0,0,0,0,1,1", FilesPerLevel()); ASSERT_GT(GetSstSizeHelper(Temperature::kUnknown), 0); ASSERT_GT(GetSstSizeHelper(Temperature::kCold), 0); diff --git a/db/compaction/subcompaction_state.cc b/db/compaction/subcompaction_state.cc index 13f40f63f0c..1651a3dec48 100644 --- a/db/compaction/subcompaction_state.cc +++ b/db/compaction/subcompaction_state.cc @@ -18,29 +18,28 @@ void SubcompactionState::AggregateCompactionOutputStats( // Outputs should be closed. By extension, any files created just for // range deletes have already been written also. assert(compaction_outputs_.HasBuilder() == false); - assert(penultimate_level_outputs_.HasBuilder() == false); + assert(proximal_level_outputs_.HasBuilder() == false); // FIXME: These stats currently include abandonned output files // assert(compaction_outputs_.stats_.num_output_files == // compaction_outputs_.outputs_.size()); - // assert(penultimate_level_outputs_.stats_.num_output_files == - // penultimate_level_outputs_.outputs_.size()); + // assert(proximal_level_outputs_.stats_.num_output_files == + // proximal_level_outputs_.outputs_.size()); compaction_stats.stats.Add(compaction_outputs_.stats_); - if (penultimate_level_outputs_.HasOutput()) { - compaction_stats.has_penultimate_level_output = true; - compaction_stats.penultimate_level_stats.Add( - penultimate_level_outputs_.stats_); + if (proximal_level_outputs_.HasOutput()) { + compaction_stats.has_proximal_level_output = true; + compaction_stats.proximal_level_stats.Add(proximal_level_outputs_.stats_); } } OutputIterator SubcompactionState::GetOutputs() const { - return OutputIterator(penultimate_level_outputs_.outputs_, + return OutputIterator(proximal_level_outputs_.outputs_, compaction_outputs_.outputs_); } void SubcompactionState::Cleanup(Cache* cache) { - penultimate_level_outputs_.Cleanup(); + proximal_level_outputs_.Cleanup(); compaction_outputs_.Cleanup(); if (!status.ok()) { @@ -63,9 +62,9 @@ void SubcompactionState::Cleanup(Cache* cache) { } Slice SubcompactionState::SmallestUserKey() const { - if (penultimate_level_outputs_.HasOutput()) { + if (proximal_level_outputs_.HasOutput()) { Slice a = compaction_outputs_.SmallestUserKey(); - Slice b = penultimate_level_outputs_.SmallestUserKey(); + Slice b = proximal_level_outputs_.SmallestUserKey(); if (a.empty()) { return b; } @@ -85,9 +84,9 @@ Slice SubcompactionState::SmallestUserKey() const { } Slice SubcompactionState::LargestUserKey() const { - if (penultimate_level_outputs_.HasOutput()) { + if (proximal_level_outputs_.HasOutput()) { Slice a = compaction_outputs_.LargestUserKey(); - Slice b = penultimate_level_outputs_.LargestUserKey(); + Slice b = proximal_level_outputs_.LargestUserKey(); if (a.empty()) { return b; } @@ -107,12 +106,12 @@ Slice SubcompactionState::LargestUserKey() const { } Status SubcompactionState::AddToOutput( - const CompactionIterator& iter, bool use_penultimate_output, + const CompactionIterator& iter, bool use_proximal_output, const CompactionFileOpenFunc& open_file_func, const CompactionFileCloseFunc& close_file_func) { // update target output - current_outputs_ = use_penultimate_output ? &penultimate_level_outputs_ - : &compaction_outputs_; + current_outputs_ = + use_proximal_output ? &proximal_level_outputs_ : &compaction_outputs_; return current_outputs_->AddToOutput(iter, open_file_func, close_file_func); } diff --git a/db/compaction/subcompaction_state.h b/db/compaction/subcompaction_state.h index b9117f5adfb..016d253566e 100644 --- a/db/compaction/subcompaction_state.h +++ b/db/compaction/subcompaction_state.h @@ -26,13 +26,13 @@ namespace ROCKSDB_NAMESPACE { // Maintains state and outputs for each sub-compaction // It contains 2 `CompactionOutputs`: // 1. one for the normal output files -// 2. another for the penultimate level outputs +// 2. another for the proximal level outputs // a `current` pointer maintains the current output group, when calling // `AddToOutput()`, it checks the output of the current compaction_iterator key // and point `current` to the target output group. By default, it just points to // normal compaction_outputs, if the compaction_iterator key should be placed on -// the penultimate level, `current` is changed to point to -// `penultimate_level_outputs`. +// the proximal level, `current` is changed to point to +// `proximal_level_outputs`. // The later operations uses `Current()` to get the target group. // // +----------+ +-----------------------------+ +---------+ @@ -43,7 +43,7 @@ namespace ROCKSDB_NAMESPACE { // | | ... | // | // | +-----------------------------+ +---------+ -// +-------------> | penultimate_level_outputs |----->| output | +// +-------------> | proximal_level_outputs |----->| output | // +-----------------------------+ +---------+ // | ... | @@ -78,7 +78,7 @@ class SubcompactionState { Slice LargestUserKey() const; // Get all outputs from the subcompaction. For per_key_placement compaction, - // it returns both the last level outputs and penultimate level outputs. + // it returns both the last level outputs and proximal level outputs. OutputIterator GetOutputs() const; // Assign range dels aggregator. The various tombstones will potentially @@ -92,7 +92,7 @@ class SubcompactionState { void RemoveLastEmptyOutput() { compaction_outputs_.RemoveLastEmptyOutput(); - penultimate_level_outputs_.RemoveLastEmptyOutput(); + proximal_level_outputs_.RemoveLastEmptyOutput(); } void BuildSubcompactionJobInfo( @@ -119,14 +119,14 @@ class SubcompactionState { start(_start), end(_end), sub_job_id(_sub_job_id), - compaction_outputs_(c, /*is_penultimate_level=*/false), - penultimate_level_outputs_(c, /*is_penultimate_level=*/true) { + compaction_outputs_(c, /*is_proximal_level=*/false), + proximal_level_outputs_(c, /*is_proximal_level=*/true) { assert(compaction != nullptr); // Set output split key (used for RoundRobin feature) only for normal - // compaction_outputs, output to penultimate_level feature doesn't support + // compaction_outputs, output to proximal_level feature doesn't support // RoundRobin feature (and may never going to be supported, because for // RoundRobin, the data time is mostly naturally sorted, no need to have - // per-key placement with output_to_penultimate_level). + // per-key placement with output_to_proximal_level). compaction_outputs_.SetOutputSlitKey(start, end); } @@ -141,18 +141,17 @@ class SubcompactionState { compaction_job_stats(std::move(state.compaction_job_stats)), sub_job_id(state.sub_job_id), compaction_outputs_(std::move(state.compaction_outputs_)), - penultimate_level_outputs_(std::move(state.penultimate_level_outputs_)), + proximal_level_outputs_(std::move(state.proximal_level_outputs_)), range_del_agg_(std::move(state.range_del_agg_)) { - current_outputs_ = - state.current_outputs_ == &state.penultimate_level_outputs_ - ? &penultimate_level_outputs_ - : &compaction_outputs_; + current_outputs_ = state.current_outputs_ == &state.proximal_level_outputs_ + ? &proximal_level_outputs_ + : &compaction_outputs_; } // Add all the new files from this compaction to version_edit void AddOutputsEdit(VersionEdit* out_edit) const { - for (const auto& file : penultimate_level_outputs_.outputs_) { - out_edit->AddFile(compaction->GetPenultimateLevel(), file.meta); + for (const auto& file : proximal_level_outputs_.outputs_) { + out_edit->AddFile(compaction->GetProximalLevel(), file.meta); } for (const auto& file : compaction_outputs_.outputs_) { out_edit->AddFile(compaction->output_level(), file.meta); @@ -169,11 +168,11 @@ class SubcompactionState { return *current_outputs_; } - CompactionOutputs* Outputs(bool is_penultimate_level) { + CompactionOutputs* Outputs(bool is_proximal_level) { assert(compaction); - if (is_penultimate_level) { + if (is_proximal_level) { assert(compaction->SupportsPerKeyPlacement()); - return &penultimate_level_outputs_; + return &proximal_level_outputs_; } return &compaction_outputs_; } @@ -188,12 +187,11 @@ class SubcompactionState { } // Add compaction_iterator key/value to the `Current` output group. - Status AddToOutput(const CompactionIterator& iter, - bool use_penultimate_output, + Status AddToOutput(const CompactionIterator& iter, bool use_proximal_output, const CompactionFileOpenFunc& open_file_func, const CompactionFileCloseFunc& close_file_func); - // Close all compaction output files, both output_to_penultimate_level outputs + // Close all compaction output files, both output_to_proximal_level outputs // and normal outputs. Status CloseCompactionFiles(const Status& curr_status, const CompactionFileOpenFunc& open_file_func, @@ -204,11 +202,11 @@ class SubcompactionState { // CloseOutput() may open new compaction output files. Status s = curr_status; if (per_key) { - s = penultimate_level_outputs_.CloseOutput( - s, range_del_agg_.get(), open_file_func, close_file_func); + s = proximal_level_outputs_.CloseOutput(s, range_del_agg_.get(), + open_file_func, close_file_func); } else { - assert(penultimate_level_outputs_.HasBuilder() == false); - assert(penultimate_level_outputs_.HasOutput() == false); + assert(proximal_level_outputs_.HasBuilder() == false); + assert(proximal_level_outputs_.HasOutput() == false); } s = compaction_outputs_.CloseOutput(s, range_del_agg_.get(), open_file_func, close_file_func); @@ -218,7 +216,7 @@ class SubcompactionState { private: // State kept for output being generated CompactionOutputs compaction_outputs_; - CompactionOutputs penultimate_level_outputs_; + CompactionOutputs proximal_level_outputs_; CompactionOutputs* current_outputs_ = &compaction_outputs_; std::unique_ptr range_del_agg_; }; diff --git a/db/compaction/tiered_compaction_test.cc b/db/compaction/tiered_compaction_test.cc index eed5cb936f0..a7f2e948d16 100644 --- a/db/compaction/tiered_compaction_test.cc +++ b/db/compaction/tiered_compaction_test.cc @@ -215,8 +215,8 @@ TEST_F(TieredCompactionTest, SequenceBasedTieredStorageUniversal) { } ASSERT_OK(dbfull()->TEST_WaitForCompact()); - // the penultimate level file temperature is not cold, all data are output to - // the penultimate level. + // the proximal level file temperature is not cold, all data are output to + // the proximal level. ASSERT_EQ("0,0,0,0,0,1", FilesPerLevel()); ASSERT_GT(GetSstSizeHelper(Temperature::kUnknown), 0); ASSERT_EQ(GetSstSizeHelper(Temperature::kCold), 0); @@ -230,7 +230,7 @@ TEST_F(TieredCompactionTest, SequenceBasedTieredStorageUniversal) { ResetAllStats(expect_stats, expect_pl_stats); // move forward the cold_seq to split the file into 2 levels, so should have - // both the last level stats and the output_to_penultimate_level stats + // both the last level stats and the output_to_proximal_level stats latest_cold_seq = seq_history[0]; ASSERT_OK(db_->CompactRange(CompactRangeOptions(), nullptr, nullptr)); ASSERT_EQ("0,0,0,0,0,1,1", FilesPerLevel()); @@ -246,7 +246,7 @@ TEST_F(TieredCompactionTest, SequenceBasedTieredStorageUniversal) { expect_pl_stats.ResetCompactionReason(CompactionReason::kManualCompaction); VerifyCompactionStats(expect_stats, expect_pl_stats); - // delete all cold data, so all data will be on penultimate level + // delete all cold data, so all data will be on proximal level for (int i = 0; i < 10; i++) { ASSERT_OK(Delete(Key(i))); } @@ -364,7 +364,7 @@ TEST_F(TieredCompactionTest, DISABLED_RangeBasedTieredStorageUniversal) { "CompactionIterator::PrepareOutput.context", [&](void* arg) { auto context = static_cast(arg); MutexLock l(&mutex); - context->output_to_penultimate_level = + context->output_to_proximal_level = cmp->Compare(context->key, hot_start) >= 0 && cmp->Compare(context->key, hot_end) < 0; }); @@ -393,7 +393,7 @@ TEST_F(TieredCompactionTest, DISABLED_RangeBasedTieredStorageUniversal) { ResetAllStats(expect_stats, expect_pl_stats); - // change to all cold, no output_to_penultimate_level output + // change to all cold, no output_to_proximal_level output { MutexLock l(&mutex); hot_start = Key(100); @@ -421,7 +421,7 @@ TEST_F(TieredCompactionTest, DISABLED_RangeBasedTieredStorageUniversal) { } // No data is moved from cold tier to hot tier because no input files from L5 - // or higher, it's not safe to move data to output_to_penultimate_level level. + // or higher, it's not safe to move data to output_to_proximal_level level. ASSERT_OK(db_->CompactRange(CompactRangeOptions(), nullptr, nullptr)); ASSERT_EQ("0,0,0,0,0,1", FilesPerLevel()); @@ -567,7 +567,7 @@ TEST_F(TieredCompactionTest, LevelColdRangeDelete) { // 20->30 will be marked as cold data, but it cannot be placed to cold tier // (bottommost) otherwise, it will be "deleted" by the range del in - // output_to_penultimate_level level verify that these data will be able to + // output_to_proximal_level level verify that these data will be able to // queried for (int i = 20; i < 30; i++) { ASSERT_OK(Put(Key(i), "value" + std::to_string(i))); @@ -677,17 +677,17 @@ TEST_F(TieredCompactionTest, LevelOutofBoundaryRangeDelete) { std::vector> level_to_files; dbfull()->TEST_GetFilesMetaData(dbfull()->DefaultColumnFamily(), &level_to_files); - // range tombstone is in the penultimate level - const int penultimate_level = kNumLevels - 2; - ASSERT_EQ(level_to_files[penultimate_level].size(), 1); - ASSERT_EQ(level_to_files[penultimate_level][0].num_entries, 1); - ASSERT_EQ(level_to_files[penultimate_level][0].num_deletions, 1); - ASSERT_EQ(level_to_files[penultimate_level][0].temperature, + // range tombstone is in the proximal level + const int proximal_level = kNumLevels - 2; + ASSERT_EQ(level_to_files[proximal_level].size(), 1); + ASSERT_EQ(level_to_files[proximal_level][0].num_entries, 1); + ASSERT_EQ(level_to_files[proximal_level][0].num_deletions, 1); + ASSERT_EQ(level_to_files[proximal_level][0].temperature, Temperature::kUnknown); ASSERT_GT(GetSstSizeHelper(Temperature::kCold), 0); ASSERT_EQ("0,1,10", - FilesPerLevel()); // one file is at the penultimate level which + FilesPerLevel()); // one file is at the proximal level which // only contains a range delete // Add 2 hot keys, each is a new SST, they will be placed in the same level as @@ -701,7 +701,7 @@ TEST_F(TieredCompactionTest, LevelOutofBoundaryRangeDelete) { ASSERT_OK(db_->CompactRange(cro, nullptr, nullptr)); ASSERT_EQ("0,2,10", - FilesPerLevel()); // one file is at the penultimate level + FilesPerLevel()); // one file is at the proximal level // which only contains a range delete std::vector live_file_meta; db_->GetLiveFilesMetaData(&live_file_meta); @@ -711,7 +711,7 @@ TEST_F(TieredCompactionTest, LevelOutofBoundaryRangeDelete) { if (meta.num_deletions > 0) { // found SST with del, which has 2 entries, one for data one for range del ASSERT_EQ(meta.level, - kNumLevels - 2); // output to penultimate level + kNumLevels - 2); // output to proximal level ASSERT_EQ(meta.num_entries, 2); ASSERT_EQ(meta.num_deletions, 1); found_sst_with_del = true; @@ -722,7 +722,7 @@ TEST_F(TieredCompactionTest, LevelOutofBoundaryRangeDelete) { // release the first snapshot and compact, which should compact the range del // but new inserted key `0` and `6` are still hot data which will be placed on - // the penultimate level + // the proximal level db_->ReleaseSnapshot(snap); ASSERT_OK(db_->CompactRange(cro, nullptr, nullptr)); ASSERT_EQ("0,2,7", FilesPerLevel()); @@ -738,7 +738,7 @@ TEST_F(TieredCompactionTest, LevelOutofBoundaryRangeDelete) { ASSERT_FALSE(found_sst_with_del); // Now make all data cold, key 0 will be moved to the last level, but key 6 is - // still in snap2, so it will be kept at the penultimate level + // still in snap2, so it will be kept at the proximal level latest_cold_seq = dbfull()->GetLatestSequenceNumber(); ASSERT_OK(db_->CompactRange(cro, nullptr, nullptr)); ASSERT_EQ("0,1,8", FilesPerLevel()); @@ -783,7 +783,7 @@ TEST_F(TieredCompactionTest, UniversalRangeDelete) { } ASSERT_OK(Flush()); - // compact to the penultimate level with 10 files + // compact to the proximal level with 10 files CompactRangeOptions cro; cro.bottommost_level_compaction = BottommostLevelCompaction::kForce; ASSERT_OK(db_->CompactRange(cro, nullptr, nullptr)); @@ -810,7 +810,7 @@ TEST_F(TieredCompactionTest, UniversalRangeDelete) { ASSERT_EQ("0,0,0,0,0,0,8", FilesPerLevel()); - // range del with snapshot should be preserved in the penultimate level + // range del with snapshot should be preserved in the proximal level auto snap = db_->GetSnapshot(); start = Key(6); @@ -841,7 +841,7 @@ TEST_F(TieredCompactionTest, UniversalRangeDelete) { if (meta.num_deletions > 0) { // found SST with del, which has 2 entries, one for data one for range del ASSERT_EQ(meta.level, - kNumLevels - 2); // output_to_penultimate_level level + kNumLevels - 2); // output_to_proximal_level level ASSERT_EQ(meta.num_entries, 2); ASSERT_EQ(meta.num_deletions, 1); found_sst_with_del = true; @@ -1138,7 +1138,7 @@ TEST_F(TieredCompactionTest, DISABLED_RangeBasedTieredStorageLevel) { "CompactionIterator::PrepareOutput.context", [&](void* arg) { auto context = static_cast(arg); MutexLock l(&mutex); - context->output_to_penultimate_level = + context->output_to_proximal_level = cmp->Compare(context->key, hot_start) >= 0 && cmp->Compare(context->key, hot_end) < 0; }); @@ -1221,10 +1221,10 @@ TEST_F(TieredCompactionTest, DISABLED_RangeBasedTieredStorageLevel) { options.statistics->getTickerCount(COMPACTION_RANGE_DEL_DROP_OBSOLETE), 1); - // Tests that we only compact keys up to penultimate level - // that are within penultimate level input's internal key range. - // UPDATE: this functionality has changed. With penultimate-enabled - // compaction, the expanded potential output range in the penultimate + // Tests that we only compact keys up to proximal level + // that are within proximal level input's internal key range. + // UPDATE: this functionality has changed. With proximal-enabled + // compaction, the expanded potential output range in the proximal // level is reserved so should be safe to use. { MutexLock l(&mutex); @@ -1376,7 +1376,7 @@ TEST_P(PrecludeLastLevelTest, MigrationFromPreserveTimeManualCompaction) { cro.bottommost_level_compaction = BottommostLevelCompaction::kForce; ASSERT_OK(db_->CompactRange(cro, nullptr, nullptr)); - // all data is moved up to the penultimate level + // all data is moved up to the proximal level ASSERT_EQ("0,0,0,0,0,1", FilesPerLevel()); ASSERT_EQ(GetSstSizeHelper(Temperature::kCold), 0); ASSERT_GT(GetSstSizeHelper(Temperature::kUnknown), 0); @@ -1448,7 +1448,7 @@ TEST_P(PrecludeLastLevelTest, MigrationFromPreserveTimeAutoCompaction) { ASSERT_OK(dbfull()->TEST_WaitForCompact()); } - // all data is moved up to the penultimate level + // all data is moved up to the proximal level ASSERT_EQ("0,0,0,0,0,1", FilesPerLevel()); ASSERT_EQ(GetSstSizeHelper(Temperature::kCold), 0); ASSERT_GT(GetSstSizeHelper(Temperature::kUnknown), 0); @@ -1579,9 +1579,9 @@ TEST_P(PrecludeLastLevelTest, SmallPrecludeTime) { } TEST_P(PrecludeLastLevelTest, CheckInternalKeyRange) { - // When compacting keys from the last level to penultimate level, - // output to penultimate level should be within internal key range - // of input files from penultimate level. + // When compacting keys from the last level to proximal level, + // output to proximal level should be within internal key range + // of input files from proximal level. // Set up: // L5: // File 1: DeleteRange[1, 3)@4, File 2: [3@5, 100@6] @@ -1719,8 +1719,8 @@ TEST_P(PrecludeWithCompactStyleTest, RangeTombstoneSnapshotMigrateFromLast) { ApplyConfigChange(&options, {{"preclude_last_level_data_seconds", "10000"}}); - // To exercise the WithinPenultimateLevelOutputRange feature, we want files - // around the middle file to be compacted on the penultimate level + // To exercise the WithinProximalLevelOutputRange feature, we want files + // around the middle file to be compacted on the proximal level ASSERT_OK(Put(Key(0), "val0")); ASSERT_OK(Flush()); ASSERT_OK(Put(Key(3), "val3")); @@ -1777,9 +1777,9 @@ TEST_P(PrecludeWithCompactStyleTest, RangeTombstoneSnapshotMigrateFromLast) { EXPECT_EQ("0,0,0,0,0,3,1", FilesPerLevel()); VerifyLogicalState(__LINE__); - // Compact everything, but some data still goes to both penultimate and last + // Compact everything, but some data still goes to both proximal and last // levels. A full-range compaction should be safe to "migrate" data from the - // last level to penultimate (because of preclude setting change). + // last level to proximal (because of preclude setting change). ASSERT_OK(CompactRange({}, {}, {})); EXPECT_EQ("0,0,0,0,0,1,1", FilesPerLevel()); VerifyLogicalState(__LINE__); @@ -1898,7 +1898,7 @@ TEST_P(TimedPutPrecludeLastLevelTest, InterleavedTimedPutAndPut) { Close(); } -TEST_P(TimedPutPrecludeLastLevelTest, PreserveTimedPutOnPenultimateLevel) { +TEST_P(TimedPutPrecludeLastLevelTest, PreserveTimedPutOnProximalLevel) { Options options = CurrentOptions(); options.compaction_style = kCompactionStyleUniversal; options.disable_auto_compactions = true; @@ -1924,14 +1924,14 @@ TEST_P(TimedPutPrecludeLastLevelTest, PreserveTimedPutOnPenultimateLevel) { ASSERT_OK(TimedPut(0, Key(2), "v2", kMockStartTime - 1 * 24 * 60 * 60, wo)); ASSERT_OK(Flush()); - // Should still be in penultimate level. + // Should still be in proximal level. ASSERT_OK(db_->CompactRange(CompactRangeOptions(), nullptr, nullptr)); ASSERT_EQ("0,0,0,0,0,1", FilesPerLevel()); ASSERT_GT(GetSstSizeHelper(Temperature::kHot), 0); ASSERT_EQ(GetSstSizeHelper(Temperature::kCold), 0); // Wait one more day and release snapshot. Data's preferred seqno should be - // swapped in, but data should still stay in penultimate level. SST file's + // swapped in, but data should still stay in proximal level. SST file's // seqno to time mapping should continue to cover preferred seqno after // compaction. db_->ReleaseSnapshot(snap1); @@ -2253,13 +2253,13 @@ TEST_P(PrecludeLastLevelOptionalTest, LastLevelOnlyCompactionNoPreclude) { Close(); } -TEST_P(PrecludeLastLevelOptionalTest, PeriodicCompactionToPenultimateLevel) { +TEST_P(PrecludeLastLevelOptionalTest, PeriodicCompactionToProximalLevel) { // Test the last level only periodic compaction should also be blocked by an - // ongoing compaction in penultimate level if tiered compaction is enabled + // ongoing compaction in proximal level if tiered compaction is enabled // otherwise, the periodic compaction should just run for the last level. const int kNumTrigger = 4; const int kNumLevels = 7; - const int kPenultimateLevel = kNumLevels - 2; + const int kProximalLevel = kNumLevels - 2; const int kKeyPerSec = 1; const int kNumKeys = 100; @@ -2301,13 +2301,13 @@ TEST_P(PrecludeLastLevelOptionalTest, PeriodicCompactionToPenultimateLevel) { SyncPoint::GetInstance()->SetCallBack( "CompactionJob::ProcessKeyValueCompaction()::Processing", [&](void* arg) { auto compaction = static_cast(arg); - if (compaction->output_level() == kPenultimateLevel) { + if (compaction->output_level() == kProximalLevel) { is_size_ratio_compaction_running = true; TEST_SYNC_POINT( - "PrecludeLastLevelTest::PeriodicCompactionToPenultimateLevel:" + "PrecludeLastLevelTest::PeriodicCompactionToProximalLevel:" "SizeRatioCompaction1"); TEST_SYNC_POINT( - "PrecludeLastLevelTest::PeriodicCompactionToPenultimateLevel:" + "PrecludeLastLevelTest::PeriodicCompactionToProximalLevel:" "SizeRatioCompaction2"); is_size_ratio_compaction_running = false; } @@ -2329,17 +2329,17 @@ TEST_P(PrecludeLastLevelOptionalTest, PeriodicCompactionToPenultimateLevel) { verified_last_level_compaction = true; } TEST_SYNC_POINT( - "PrecludeLastLevelTest::PeriodicCompactionToPenultimateLevel:" + "PrecludeLastLevelTest::PeriodicCompactionToProximalLevel:" "AutoCompactionPicked"); }); SyncPoint::GetInstance()->LoadDependency({ - {"PrecludeLastLevelTest::PeriodicCompactionToPenultimateLevel:" + {"PrecludeLastLevelTest::PeriodicCompactionToProximalLevel:" "SizeRatioCompaction1", - "PrecludeLastLevelTest::PeriodicCompactionToPenultimateLevel:DoneWrite"}, - {"PrecludeLastLevelTest::PeriodicCompactionToPenultimateLevel:" + "PrecludeLastLevelTest::PeriodicCompactionToProximalLevel:DoneWrite"}, + {"PrecludeLastLevelTest::PeriodicCompactionToProximalLevel:" "AutoCompactionPicked", - "PrecludeLastLevelTest::PeriodicCompactionToPenultimateLevel:" + "PrecludeLastLevelTest::PeriodicCompactionToProximalLevel:" "SizeRatioCompaction2"}, }); @@ -2356,11 +2356,11 @@ TEST_P(PrecludeLastLevelOptionalTest, PeriodicCompactionToPenultimateLevel) { } TEST_SYNC_POINT( - "PrecludeLastLevelTest::PeriodicCompactionToPenultimateLevel:DoneWrite"); + "PrecludeLastLevelTest::PeriodicCompactionToProximalLevel:DoneWrite"); // wait for periodic compaction time and flush to trigger the periodic // compaction, which should be blocked by ongoing compaction in the - // penultimate level + // proximal level mock_clock_->MockSleepForSeconds(10000); for (int i = 0; i < 3 * kNumKeys; i++) { ASSERT_OK(Put(Key(i), rnd.RandomString(10))); @@ -2423,7 +2423,7 @@ class ThreeRangesPartitionerFactory : public SstPartitionerFactory { } }; -TEST_P(PrecludeLastLevelTest, PartialPenultimateLevelCompaction) { +TEST_P(PrecludeLastLevelTest, PartialProximalLevelCompaction) { const int kNumTrigger = 4; const int kNumLevels = 7; const int kKeyPerSec = 10; @@ -2593,8 +2593,8 @@ TEST_P(PrecludeLastLevelTest, RangeDelsCauseFileEndpointsToOverlap) { "UniversalCompactionBuilder::PickCompaction:Return", [&](void* arg) { auto compaction = static_cast(arg); if (compaction->SupportsPerKeyPlacement()) { - ASSERT_EQ(compaction->GetPenultimateOutputRangeType(), - Compaction::PenultimateOutputRangeType::kNonLastRange); + ASSERT_EQ(compaction->GetProximalOutputRangeType(), + Compaction::ProximalOutputRangeType::kNonLastRange); per_key_comp_num++; } }); @@ -2650,7 +2650,7 @@ TEST_P(PrecludeLastLevelTest, RangeDelsCauseFileEndpointsToOverlap) { ASSERT_EQ(3, per_key_comp_num); verify_db(); - // Finish off the penultimate level. + // Finish off the proximal level. ASSERT_OK(db_->CompactRange(cro, nullptr, nullptr)); ASSERT_EQ("0,0,0,0,0,0,3", FilesPerLevel()); verify_db(); diff --git a/db/flush_job.h b/db/flush_job.h index 1c1f15d1b1d..f3f85abbcc7 100644 --- a/db/flush_job.h +++ b/db/flush_job.h @@ -234,7 +234,7 @@ class FlushJob { // The current minimum seqno that compaction jobs will preclude the data from // the last level. Data with seqnos larger than this or larger than - // `earliest_snapshot_` will be output to the penultimate level had it gone + // `earliest_snapshot_` will be output to the proximal level had it gone // through a compaction to the last level. SequenceNumber preclude_last_level_min_seqno_ = kMaxSequenceNumber; }; diff --git a/db/internal_stats.h b/db/internal_stats.h index 7ebd406db75..01c4c4bd718 100644 --- a/db/internal_stats.h +++ b/db/internal_stats.h @@ -474,33 +474,33 @@ class InternalStats { }; // Compaction stats, for per_key_placement compaction, it includes 2 levels - // stats: the last level and the penultimate level. + // stats: the last level and the proximal level. struct CompactionStatsFull { // the stats for the target primary output level CompactionStats stats; - // stats for penultimate level output if exist - bool has_penultimate_level_output = false; - CompactionStats penultimate_level_stats; + // stats for proximal level output if exist + bool has_proximal_level_output = false; + CompactionStats proximal_level_stats; - explicit CompactionStatsFull() : stats(), penultimate_level_stats() {} + explicit CompactionStatsFull() : stats(), proximal_level_stats() {} explicit CompactionStatsFull(CompactionReason reason, int c) - : stats(reason, c), penultimate_level_stats(reason, c) {} + : stats(reason, c), proximal_level_stats(reason, c) {} uint64_t TotalBytesWritten() const { uint64_t bytes_written = stats.bytes_written + stats.bytes_written_blob; - if (has_penultimate_level_output) { - bytes_written += penultimate_level_stats.bytes_written + - penultimate_level_stats.bytes_written_blob; + if (has_proximal_level_output) { + bytes_written += proximal_level_stats.bytes_written + + proximal_level_stats.bytes_written_blob; } return bytes_written; } uint64_t DroppedRecords() { uint64_t output_records = stats.num_output_records; - if (has_penultimate_level_output) { - output_records += penultimate_level_stats.num_output_records; + if (has_proximal_level_output) { + output_records += proximal_level_stats.num_output_records; } if (stats.num_input_records > output_records) { return stats.num_input_records - output_records; @@ -510,12 +510,12 @@ class InternalStats { void SetMicros(uint64_t val) { stats.micros = val; - penultimate_level_stats.micros = val; + proximal_level_stats.micros = val; } void AddCpuMicros(uint64_t val) { stats.cpu_micros += val; - penultimate_level_stats.cpu_micros += val; + proximal_level_stats.cpu_micros += val; } }; @@ -588,9 +588,8 @@ class InternalStats { void AddCompactionStats(int level, Env::Priority thread_pri, const CompactionStatsFull& comp_stats_full) { AddCompactionStats(level, thread_pri, comp_stats_full.stats); - if (comp_stats_full.has_penultimate_level_output) { - per_key_placement_comp_stats_.Add( - comp_stats_full.penultimate_level_stats); + if (comp_stats_full.has_proximal_level_output) { + per_key_placement_comp_stats_.Add(comp_stats_full.proximal_level_stats); } } diff --git a/db/seqno_time_test.cc b/db/seqno_time_test.cc index a23f9ce6671..98fae6d6c53 100644 --- a/db/seqno_time_test.cc +++ b/db/seqno_time_test.cc @@ -96,7 +96,7 @@ TEST_F(SeqnoTimeTest, TemperatureBasicUniversal) { } ASSERT_OK(dbfull()->TEST_WaitForCompact()); - // All data is hot, only output to penultimate level + // All data is hot, only output to proximal level ASSERT_EQ("0,0,0,0,0,1", FilesPerLevel()); ASSERT_GT(GetSstSizeHelper(Temperature::kUnknown), 0); ASSERT_EQ(GetSstSizeHelper(Temperature::kCold), 0); @@ -185,7 +185,7 @@ TEST_F(SeqnoTimeTest, TemperatureBasicLevel) { options.num_levels = kNumLevels; options.level_compaction_dynamic_level_bytes = true; // TODO(zjay): for level compaction, auto-compaction may stuck in deadloop, if - // the penultimate level score > 1, but the hot is not cold enough to compact + // the proximal level score > 1, but the hot is not cold enough to compact // to last level, which will keep triggering compaction. options.disable_auto_compactions = true; DestroyAndReopen(options); @@ -205,7 +205,7 @@ TEST_F(SeqnoTimeTest, TemperatureBasicLevel) { cro.bottommost_level_compaction = BottommostLevelCompaction::kForce; ASSERT_OK(db_->CompactRange(cro, nullptr, nullptr)); - // All data is hot, only output to penultimate level + // All data is hot, only output to proximal level ASSERT_EQ("0,0,0,0,0,1", FilesPerLevel()); ASSERT_GT(GetSstSizeHelper(Temperature::kUnknown), 0); ASSERT_EQ(GetSstSizeHelper(Temperature::kCold), 0); @@ -753,7 +753,7 @@ TEST_P(SeqnoTimeTablePropTest, SeqnoToTimeMappingUniversal) { CompactRangeOptions cro; cro.bottommost_level_compaction = BottommostLevelCompaction::kForce; ASSERT_OK(db_->CompactRange(cro, nullptr, nullptr)); - // make sure the data is all compacted to penultimate level if the feature is + // make sure the data is all compacted to proximal level if the feature is // on, otherwise, compacted to the last level. if (options.preclude_last_level_data_seconds > 0) { ASSERT_GT(NumTableFilesAtLevel(5), 0); diff --git a/db/version_set.cc b/db/version_set.cc index 7e9893a93c0..c8f13b48bc3 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -4761,7 +4761,7 @@ void VersionStorageInfo::CalculateBaseBytes(const ImmutableOptions& ioptions, cur_level_size <= base_bytes_min && (options.preclude_last_level_data_seconds == 0 || i < num_levels_ - 2)) { - // When per_key_placement is enabled, the penultimate level is + // When per_key_placement is enabled, the proximal level is // necessary. lowest_unnecessary_level_ = i; } diff --git a/include/rocksdb/compaction_job_stats.h b/include/rocksdb/compaction_job_stats.h index 91709795a17..ba3fcebcc90 100644 --- a/include/rocksdb/compaction_job_stats.h +++ b/include/rocksdb/compaction_job_stats.h @@ -118,6 +118,6 @@ struct CompactionJobStats { // number of single-deletes which meet something other than a put uint64_t num_single_del_mismatch = 0; - // TODO: Add output_to_penultimate_level output information + // TODO: Add output_to_proximal_level output information }; } // namespace ROCKSDB_NAMESPACE