Print compaction score for every compaction run.

Summary:
A compaction is picked based on its score. It is useful to
print the compaction score in the LOG because it aids in
debugging. If one looks at the logs, one can find out why
a compaction was preferred over another.

Test Plan: make clean check

Differential Revision: https://reviews.facebook.net/D7137
main
Dhruba Borthakur 12 years ago
parent 6eb5ed9a49
commit c847a31727
  1. 3
      db/db_impl.cc
  2. 8
      db/version_set.cc
  3. 6
      db/version_set.h

@ -1349,11 +1349,12 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
int64_t imm_micros = 0; // Micros spent doing imm_ compactions
Log(options_.info_log,
"Compacting %d@%d + %d@%d files, compaction slots available %d",
"Compacting %d@%d + %d@%d files, score %.2f slots available %d",
compact->compaction->num_input_files(0),
compact->compaction->level(),
compact->compaction->num_input_files(1),
compact->compaction->level() + 1,
compact->compaction->score(),
options_.max_background_compactions - bg_compaction_scheduled_);
char scratch[256];
compact->compaction->Summary(scratch, sizeof(scratch));

@ -1787,7 +1787,7 @@ uint64_t VersionSet::SizeBeingCompacted(int level) {
return total;
}
Compaction* VersionSet::PickCompactionBySize(int level) {
Compaction* VersionSet::PickCompactionBySize(int level, double score) {
Compaction* c = NULL;
// level 0 files are overlapping. So we cannot pick more
@ -1802,6 +1802,7 @@ Compaction* VersionSet::PickCompactionBySize(int level) {
assert(level+1 < NumberLevels());
c = new Compaction(level, MaxFileSizeForLevel(level),
MaxGrandParentOverlapBytes(level), NumberLevels());
c->score_ = score;
// Pick the largest file in this level that is not already
// being compacted
@ -1876,7 +1877,7 @@ Compaction* VersionSet::PickCompaction() {
current_->compaction_score_[i-1]);
level = current_->compaction_level_[i];
if ((current_->compaction_score_[i] >= 1)) {
c = PickCompactionBySize(level);
c = PickCompactionBySize(level, current_->compaction_score_[i]);
if (c != NULL) {
break;
}
@ -2076,7 +2077,8 @@ Compaction::Compaction(int level, uint64_t target_file_size,
seen_key_(false),
overlapped_bytes_(0),
base_index_(-1),
parent_index_(-1) {
parent_index_(-1),
score_(0) {
edit_ = new VersionEdit(number_levels_);
level_ptrs_ = new size_t[number_levels_];
for (int i = 0; i < number_levels_; i++) {

@ -345,7 +345,7 @@ class VersionSet {
// For the specfied level, pick a compaction.
// Returns NULL if there is no compaction to be done.
Compaction* PickCompactionBySize(int level);
Compaction* PickCompactionBySize(int level, double score);
// Free up the files that were participated in a compaction
void ReleaseCompactionFiles(Compaction* c, Status status);
@ -502,6 +502,9 @@ class Compaction {
void Summary(char* output, int len);
// Return the score that was used to pick this compaction run.
double score() const { return score_; }
private:
friend class Version;
friend class VersionSet;
@ -531,6 +534,7 @@ class Compaction {
// and grandparent files
int base_index_; // index of the file in files_[level_]
int parent_index_; // index of some file with same range in files_[level_+1]
double score_; // score that was used to pick this compaction.
// State for implementing IsBaseLevelForKey

Loading…
Cancel
Save