|
|
@ -103,6 +103,15 @@ class Version { |
|
|
|
void Ref(); |
|
|
|
void Ref(); |
|
|
|
void Unref(); |
|
|
|
void Unref(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Returns true iff some level needs a compaction.
|
|
|
|
|
|
|
|
bool NeedsCompaction() const; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Returns the maxmimum compaction score for levels 1 to max
|
|
|
|
|
|
|
|
double MaxCompactionScore() const { return max_compaction_score_; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// See field declaration
|
|
|
|
|
|
|
|
int MaxCompactionScoreLevel() const { return max_compaction_score_level_; } |
|
|
|
|
|
|
|
|
|
|
|
void GetOverlappingInputs( |
|
|
|
void GetOverlappingInputs( |
|
|
|
int level, |
|
|
|
int level, |
|
|
|
const InternalKey* begin, // nullptr means before all keys
|
|
|
|
const InternalKey* begin, // nullptr means before all keys
|
|
|
@ -390,49 +399,6 @@ class VersionSet { |
|
|
|
// The caller should delete the iterator when no longer needed.
|
|
|
|
// The caller should delete the iterator when no longer needed.
|
|
|
|
Iterator* MakeInputIterator(Compaction* c); |
|
|
|
Iterator* MakeInputIterator(Compaction* c); |
|
|
|
|
|
|
|
|
|
|
|
// Returns true iff some level needs a compaction because it has
|
|
|
|
|
|
|
|
// exceeded its target size.
|
|
|
|
|
|
|
|
bool NeedsSizeCompaction() const { |
|
|
|
|
|
|
|
// In universal compaction case, this check doesn't really
|
|
|
|
|
|
|
|
// check the compaction condition, but checks num of files threshold
|
|
|
|
|
|
|
|
// only. We are not going to miss any compaction opportunity
|
|
|
|
|
|
|
|
// but it's likely that more compactions are scheduled but
|
|
|
|
|
|
|
|
// ending up with nothing to do. We can improve it later.
|
|
|
|
|
|
|
|
// TODO: improve this function to be accurate for universal
|
|
|
|
|
|
|
|
// compactions.
|
|
|
|
|
|
|
|
// TODO this only works for default column family now
|
|
|
|
|
|
|
|
Version* version = column_family_set_->GetDefault()->current; |
|
|
|
|
|
|
|
int num_levels_to_check = |
|
|
|
|
|
|
|
(options_->compaction_style != kCompactionStyleUniversal) ? |
|
|
|
|
|
|
|
NumberLevels() - 1 : 1; |
|
|
|
|
|
|
|
for (int i = 0; i < num_levels_to_check; i++) { |
|
|
|
|
|
|
|
if (version->compaction_score_[i] >= 1) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Returns true iff some level needs a compaction.
|
|
|
|
|
|
|
|
bool NeedsCompaction() const { |
|
|
|
|
|
|
|
// TODO this only works for default column family now
|
|
|
|
|
|
|
|
Version* version = column_family_set_->GetDefault()->current; |
|
|
|
|
|
|
|
return ((version->file_to_compact_ != nullptr) || NeedsSizeCompaction()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Returns the maxmimum compaction score for levels 1 to max
|
|
|
|
|
|
|
|
double MaxCompactionScore() const { |
|
|
|
|
|
|
|
// TODO this only works for default column family now
|
|
|
|
|
|
|
|
Version* version = column_family_set_->GetDefault()->current; |
|
|
|
|
|
|
|
return version->max_compaction_score_; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// See field declaration
|
|
|
|
|
|
|
|
int MaxCompactionScoreLevel() const { |
|
|
|
|
|
|
|
// TODO this only works for default column family now
|
|
|
|
|
|
|
|
Version* version = column_family_set_->GetDefault()->current; |
|
|
|
|
|
|
|
return version->max_compaction_score_level_; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Add all files listed in any live version to *live.
|
|
|
|
// Add all files listed in any live version to *live.
|
|
|
|
void AddLiveFiles(std::vector<uint64_t>* live_list); |
|
|
|
void AddLiveFiles(std::vector<uint64_t>* live_list); |
|
|
|
|
|
|
|
|
|
|
|