Skip to content

Commit ca7367a

Browse files
jaykoreanfacebook-github-bot
authored andcommitted
Replace penultimate naming with proximal (#13460)
Summary: With generalized age-based tiering (work-in-progress), the "warm tier" data will no longer necessarily be placed in the second-to-last level (also known as the "penultimate level"). Also, the cold tier may no longer necessarily be at the last level, so we need to rename options like `preclude_last_level_seconds` to `preclude_cold_tier_seconds`, but renaming options is trickier because it can be a breaking change for consuming applications. We will do this later as a follow up. **Minor fix included**: Fixed one `use-after-move` in CompactionPicker Pull Request resolved: #13460 Test Plan: CI Reviewed By: pdillinger Differential Revision: D71059486 Pulled By: jaykorean fbshipit-source-id: fd360cdf719e015bf9f9e3f6f1663438226566a4
1 parent c5921df commit ca7367a

22 files changed

+373
-397
lines changed

db/compaction/compaction.cc

+51-55
Original file line numberDiff line numberDiff line change
@@ -338,16 +338,16 @@ Compaction::Compaction(
338338
_blob_garbage_collection_age_cutoff > 1
339339
? mutable_cf_options().blob_garbage_collection_age_cutoff
340340
: _blob_garbage_collection_age_cutoff),
341-
penultimate_level_(
342-
// For simplicity, we don't support the concept of "penultimate level"
341+
proximal_level_(
342+
// For simplicity, we don't support the concept of "proximal level"
343343
// with `CompactionReason::kExternalSstIngestion` and
344344
// `CompactionReason::kRefitLevel`
345345
_compaction_reason == CompactionReason::kExternalSstIngestion ||
346346
_compaction_reason == CompactionReason::kRefitLevel
347347
? Compaction::kInvalidLevel
348-
: EvaluatePenultimateLevel(vstorage, mutable_cf_options_,
349-
immutable_options_, start_level_,
350-
output_level_)) {
348+
: EvaluateProximalLevel(vstorage, mutable_cf_options_,
349+
immutable_options_, start_level_,
350+
output_level_)) {
351351
MarkFilesBeingCompacted(true);
352352
if (is_manual_compaction_) {
353353
compaction_reason_ = CompactionReason::kManualCompaction;
@@ -405,10 +405,10 @@ Compaction::Compaction(
405405
}
406406
}
407407

408-
PopulatePenultimateLevelOutputRange();
408+
PopulateProximalLevelOutputRange();
409409
}
410410

411-
void Compaction::PopulatePenultimateLevelOutputRange() {
411+
void Compaction::PopulateProximalLevelOutputRange() {
412412
if (!SupportsPerKeyPlacement()) {
413413
assert(keep_in_last_level_through_seqno_ == kMaxSequenceNumber);
414414
return;
@@ -417,46 +417,42 @@ void Compaction::PopulatePenultimateLevelOutputRange() {
417417
// exclude the last level, the range of all input levels is the safe range
418418
// of keys that can be moved up.
419419
int exclude_level = number_levels_ - 1;
420-
penultimate_output_range_type_ = PenultimateOutputRangeType::kNonLastRange;
420+
proximal_output_range_type_ = ProximalOutputRangeType::kNonLastRange;
421421

422-
// For universal compaction, the penultimate_output_range could be extended if
423-
// all penultimate level files are included in the compaction (which includes
424-
// the case that the penultimate level is empty).
422+
// For universal compaction, the proximal_output_range could be extended if
423+
// all proximal level files are included in the compaction (which includes
424+
// the case that the proximal level is empty).
425425
if (immutable_options_.compaction_style == kCompactionStyleUniversal) {
426426
exclude_level = kInvalidLevel;
427-
penultimate_output_range_type_ = PenultimateOutputRangeType::kFullRange;
428-
std::set<uint64_t> penultimate_inputs;
427+
proximal_output_range_type_ = ProximalOutputRangeType::kFullRange;
428+
std::set<uint64_t> proximal_inputs;
429429
for (const auto& input_lvl : inputs_) {
430-
if (input_lvl.level == penultimate_level_) {
430+
if (input_lvl.level == proximal_level_) {
431431
for (const auto& file : input_lvl.files) {
432-
penultimate_inputs.emplace(file->fd.GetNumber());
432+
proximal_inputs.emplace(file->fd.GetNumber());
433433
}
434434
}
435435
}
436-
auto penultimate_files = input_vstorage_->LevelFiles(penultimate_level_);
437-
for (const auto& file : penultimate_files) {
438-
if (penultimate_inputs.find(file->fd.GetNumber()) ==
439-
penultimate_inputs.end()) {
436+
auto proximal_files = input_vstorage_->LevelFiles(proximal_level_);
437+
for (const auto& file : proximal_files) {
438+
if (proximal_inputs.find(file->fd.GetNumber()) == proximal_inputs.end()) {
440439
exclude_level = number_levels_ - 1;
441-
penultimate_output_range_type_ =
442-
PenultimateOutputRangeType::kNonLastRange;
440+
proximal_output_range_type_ = ProximalOutputRangeType::kNonLastRange;
443441
break;
444442
}
445443
}
446444
}
447445

448-
// FIXME: should make use of `penultimate_output_range_type_`.
446+
// FIXME: should make use of `proximal_output_range_type_`.
449447
// FIXME: when last level's input range does not overlap with
450-
// penultimate level, and penultimate level input is empty,
451-
// this call will not set penultimate_level_smallest_ or
452-
// penultimate_level_largest_. No keys will be compacted up.
453-
GetBoundaryInternalKeys(input_vstorage_, inputs_,
454-
&penultimate_level_smallest_,
455-
&penultimate_level_largest_, exclude_level);
456-
457-
if (penultimate_output_range_type_ !=
458-
PenultimateOutputRangeType::kFullRange) {
459-
// If not full range in penultimate level, must keep everything already
448+
// proximal level, and proximal level input is empty,
449+
// this call will not set proximal_level_smallest_ or
450+
// proximal_level_largest_. No keys will be compacted up.
451+
GetBoundaryInternalKeys(input_vstorage_, inputs_, &proximal_level_smallest_,
452+
&proximal_level_largest_, exclude_level);
453+
454+
if (proximal_output_range_type_ != ProximalOutputRangeType::kFullRange) {
455+
// If not full range in proximal level, must keep everything already
460456
// in the last level there, because moving it back up might cause
461457
// overlap/placement issues that are difficult to resolve properly in the
462458
// presence of range deletes
@@ -486,53 +482,53 @@ Compaction::~Compaction() {
486482
}
487483

488484
bool Compaction::SupportsPerKeyPlacement() const {
489-
return penultimate_level_ != kInvalidLevel;
485+
return proximal_level_ != kInvalidLevel;
490486
}
491487

492-
int Compaction::GetPenultimateLevel() const { return penultimate_level_; }
488+
int Compaction::GetProximalLevel() const { return proximal_level_; }
493489

494490
// smallest_key and largest_key include timestamps if user-defined timestamp is
495491
// enabled.
496-
bool Compaction::OverlapPenultimateLevelOutputRange(
492+
bool Compaction::OverlapProximalLevelOutputRange(
497493
const Slice& smallest_key, const Slice& largest_key) const {
498494
if (!SupportsPerKeyPlacement()) {
499495
return false;
500496
}
501497

502-
// See FIXME in Compaction::PopulatePenultimateLevelOutputRange().
498+
// See FIXME in Compaction::PopulateProximalLevelOutputRange().
503499
// We do not compact any key up in this case.
504-
if (penultimate_level_smallest_.size() == 0 ||
505-
penultimate_level_largest_.size() == 0) {
500+
if (proximal_level_smallest_.size() == 0 ||
501+
proximal_level_largest_.size() == 0) {
506502
return false;
507503
}
508504

509505
const Comparator* ucmp =
510506
input_vstorage_->InternalComparator()->user_comparator();
511507

512508
return ucmp->CompareWithoutTimestamp(
513-
smallest_key, penultimate_level_largest_.user_key()) <= 0 &&
509+
smallest_key, proximal_level_largest_.user_key()) <= 0 &&
514510
ucmp->CompareWithoutTimestamp(
515-
largest_key, penultimate_level_smallest_.user_key()) >= 0;
511+
largest_key, proximal_level_smallest_.user_key()) >= 0;
516512
}
517513

518514
// key includes timestamp if user-defined timestamp is enabled.
519-
void Compaction::TEST_AssertWithinPenultimateLevelOutputRange(
515+
void Compaction::TEST_AssertWithinProximalLevelOutputRange(
520516
const Slice& user_key, bool expect_failure) const {
521517
#ifdef NDEBUG
522518
(void)user_key;
523519
(void)expect_failure;
524520
#else
525521
assert(SupportsPerKeyPlacement());
526522

527-
assert(penultimate_level_smallest_.size() > 0);
528-
assert(penultimate_level_largest_.size() > 0);
523+
assert(proximal_level_smallest_.size() > 0);
524+
assert(proximal_level_largest_.size() > 0);
529525

530526
auto* cmp = input_vstorage_->user_comparator();
531527

532528
// op_type of a key can change during compaction, e.g. Merge -> Put.
533-
if (!(cmp->Compare(user_key, penultimate_level_smallest_.user_key()) >= 0)) {
529+
if (!(cmp->Compare(user_key, proximal_level_smallest_.user_key()) >= 0)) {
534530
assert(expect_failure);
535-
} else if (!(cmp->Compare(user_key, penultimate_level_largest_.user_key()) <=
531+
} else if (!(cmp->Compare(user_key, proximal_level_largest_.user_key()) <=
536532
0)) {
537533
assert(expect_failure);
538534
} else {
@@ -1018,7 +1014,7 @@ uint64_t Compaction::MinInputFileEpochNumber() const {
10181014
return min_epoch_number;
10191015
}
10201016

1021-
int Compaction::EvaluatePenultimateLevel(
1017+
int Compaction::EvaluateProximalLevel(
10221018
const VersionStorageInfo* vstorage,
10231019
const MutableCFOptions& mutable_cf_options,
10241020
const ImmutableOptions& immutable_options, const int start_level,
@@ -1033,21 +1029,21 @@ int Compaction::EvaluatePenultimateLevel(
10331029
return kInvalidLevel;
10341030
}
10351031

1036-
int penultimate_level = output_level - 1;
1037-
assert(penultimate_level < immutable_options.num_levels);
1038-
if (penultimate_level <= 0) {
1032+
int proximal_level = output_level - 1;
1033+
assert(proximal_level < immutable_options.num_levels);
1034+
if (proximal_level <= 0) {
10391035
return kInvalidLevel;
10401036
}
10411037

1042-
// If the penultimate level is not within input level -> output level range
1043-
// check if the penultimate output level is empty, if it's empty, it could
1044-
// also be locked for the penultimate output.
1038+
// If the proximal level is not within input level -> output level range
1039+
// check if the proximal output level is empty, if it's empty, it could
1040+
// also be locked for the proximal output.
10451041
// TODO: ideally, it only needs to check if there's a file within the
10461042
// compaction output key range. For simplicity, it just check if there's any
1047-
// file on the penultimate level.
1043+
// file on the proximal level.
10481044
if (start_level == immutable_options.num_levels - 1 &&
10491045
(immutable_options.compaction_style != kCompactionStyleUniversal ||
1050-
!vstorage->LevelFiles(penultimate_level).empty())) {
1046+
!vstorage->LevelFiles(proximal_level).empty())) {
10511047
return kInvalidLevel;
10521048
}
10531049

@@ -1061,7 +1057,7 @@ int Compaction::EvaluatePenultimateLevel(
10611057
return kInvalidLevel;
10621058
}
10631059

1064-
return penultimate_level;
1060+
return proximal_level;
10651061
}
10661062

10671063
void Compaction::FilterInputsForCompactionIterator() {

db/compaction/compaction.h

+43-43
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ class Compaction {
102102
BlobGarbageCollectionPolicy::kUseDefault,
103103
double blob_garbage_collection_age_cutoff = -1);
104104

105-
// The type of the penultimate level output range
106-
enum class PenultimateOutputRangeType : int {
107-
kNotSupported, // it cannot output to the penultimate level
108-
kFullRange, // any data could be output to the penultimate level
105+
// The type of the proximal level output range
106+
enum class ProximalOutputRangeType : int {
107+
kNotSupported, // it cannot output to the proximal level
108+
kFullRange, // any data could be output to the proximal level
109109
kNonLastRange, // only the keys within non_last_level compaction inputs can
110-
// be outputted to the penultimate level
111-
kDisabled, // no data can be outputted to the penultimate level
110+
// be outputted to the proximal level
111+
kDisabled, // no data can be outputted to the proximal level
112112
};
113113

114114
// No copying allowed
@@ -370,29 +370,29 @@ class Compaction {
370370

371371
Slice GetLargestUserKey() const { return largest_user_key_; }
372372

373-
PenultimateOutputRangeType GetPenultimateOutputRangeType() const {
374-
return penultimate_output_range_type_;
373+
ProximalOutputRangeType GetProximalOutputRangeType() const {
374+
return proximal_output_range_type_;
375375
}
376376

377377
// Return true if the compaction supports per_key_placement
378378
bool SupportsPerKeyPlacement() const;
379379

380-
// Get per_key_placement penultimate output level, which is `last_level - 1`
380+
// Get per_key_placement proximal output level, which is `last_level - 1`
381381
// if per_key_placement feature is supported. Otherwise, return -1.
382-
int GetPenultimateLevel() const;
382+
int GetProximalLevel() const;
383383

384-
// Return true if the given range is overlap with penultimate level output
384+
// Return true if the given range is overlap with proximal level output
385385
// range.
386386
// Both smallest_key and largest_key include timestamps if user-defined
387387
// timestamp is enabled.
388-
bool OverlapPenultimateLevelOutputRange(const Slice& smallest_key,
389-
const Slice& largest_key) const;
388+
bool OverlapProximalLevelOutputRange(const Slice& smallest_key,
389+
const Slice& largest_key) const;
390390

391-
// For testing purposes, check that a key is within penultimate level
391+
// For testing purposes, check that a key is within proximal level
392392
// output range for per_key_placement feature, which is safe to place the key
393-
// to the penultimate level. Different compaction strategies have different
393+
// to the proximal level. Different compaction strategies have different
394394
// rules. `user_key` includes timestamp if user-defined timestamp is enabled.
395-
void TEST_AssertWithinPenultimateLevelOutputRange(
395+
void TEST_AssertWithinProximalLevelOutputRange(
396396
const Slice& user_key, bool expect_failure = false) const;
397397

398398
CompactionReason compaction_reason() const { return compaction_reason_; }
@@ -441,20 +441,20 @@ class Compaction {
441441

442442
static constexpr int kInvalidLevel = -1;
443443

444-
// Evaluate penultimate output level. If the compaction supports
445-
// per_key_placement feature, it returns the penultimate level number.
444+
// Evaluate proximal output level. If the compaction supports
445+
// per_key_placement feature, it returns the proximal level number.
446446
// Otherwise, it's set to kInvalidLevel (-1), which means
447-
// output_to_penultimate_level is not supported.
448-
// Note: even the penultimate level output is supported (PenultimateLevel !=
447+
// output_to_proximal_level is not supported.
448+
// Note: even the proximal level output is supported (ProximalLevel !=
449449
// kInvalidLevel), some key range maybe unsafe to be outputted to the
450-
// penultimate level. The safe key range is populated by
451-
// `PopulatePenultimateLevelOutputRange()`.
452-
// Which could potentially disable all penultimate level output.
453-
static int EvaluatePenultimateLevel(
454-
const VersionStorageInfo* vstorage,
455-
const MutableCFOptions& mutable_cf_options,
456-
const ImmutableOptions& immutable_options, const int start_level,
457-
const int output_level);
450+
// proximal level. The safe key range is populated by
451+
// `PopulateProximalLevelOutputRange()`.
452+
// Which could potentially disable all proximal level output.
453+
static int EvaluateProximalLevel(const VersionStorageInfo* vstorage,
454+
const MutableCFOptions& mutable_cf_options,
455+
const ImmutableOptions& immutable_options,
456+
const int start_level,
457+
const int output_level);
458458

459459
// If some data cannot be safely migrated "up" the LSM tree due to a change
460460
// in the preclude_last_level_data_seconds setting, this indicates a sequence
@@ -482,10 +482,10 @@ class Compaction {
482482
InternalKey* smallest_key, InternalKey* largest_key,
483483
int exclude_level = -1);
484484

485-
// populate penultimate level output range, which will be used to determine if
486-
// a key is safe to output to the penultimate level (details see
487-
// `Compaction::WithinPenultimateLevelOutputRange()`.
488-
void PopulatePenultimateLevelOutputRange();
485+
// populate proximal level output range, which will be used to determine if
486+
// a key is safe to output to the proximal level (details see
487+
// `Compaction::WithinProximalLevelOutputRange()`.
488+
void PopulateProximalLevelOutputRange();
489489

490490
// If oldest snapshot is specified at Compaction construction time, we have
491491
// an opportunity to optimize inputs for compaction iterator for this case:
@@ -616,37 +616,37 @@ class Compaction {
616616

617617
// only set when per_key_placement feature is enabled, -1 (kInvalidLevel)
618618
// means not supported.
619-
const int penultimate_level_;
619+
const int proximal_level_;
620620

621-
// Key range for penultimate level output
621+
// Key range for proximal level output
622622
// includes timestamp if user-defined timestamp is enabled.
623-
// penultimate_output_range_type_ shows the range type
624-
InternalKey penultimate_level_smallest_;
625-
InternalKey penultimate_level_largest_;
626-
PenultimateOutputRangeType penultimate_output_range_type_ =
627-
PenultimateOutputRangeType::kNotSupported;
623+
// proximal_output_range_type_ shows the range type
624+
InternalKey proximal_level_smallest_;
625+
InternalKey proximal_level_largest_;
626+
ProximalOutputRangeType proximal_output_range_type_ =
627+
ProximalOutputRangeType::kNotSupported;
628628
};
629629

630630
#ifndef NDEBUG
631631
// Helper struct only for tests, which contains the data to decide if a key
632-
// should be output to the penultimate level.
632+
// should be output to the proximal level.
633633
// TODO: remove this when the public feature knob is available
634634
struct PerKeyPlacementContext {
635635
const int level;
636636
const Slice key;
637637
const Slice value;
638638
const SequenceNumber seq_num;
639639

640-
bool& output_to_penultimate_level;
640+
bool& output_to_proximal_level;
641641

642642
PerKeyPlacementContext(int _level, Slice _key, Slice _value,
643643
SequenceNumber _seq_num,
644-
bool& _output_to_penultimate_level)
644+
bool& _output_to_proximal_level)
645645
: level(_level),
646646
key(_key),
647647
value(_value),
648648
seq_num(_seq_num),
649-
output_to_penultimate_level(_output_to_penultimate_level) {}
649+
output_to_proximal_level(_output_to_proximal_level) {}
650650
};
651651
#endif /* !NDEBUG */
652652

0 commit comments

Comments
 (0)