add compaction log Summary:

Summary:
add compaction summary to log

log looks like:

2012/08/17-18:18:32.557334 7fdcaa2bb700 Compaction summary: Base level 0, input file:[11 9 7 ],[]

Test Plan: tested via db_test

Reviewers: dhruba

Differential Revision: https://reviews.facebook.net/D4749
This commit is contained in:
heyongqiang 2012-08-17 18:10:09 -07:00
parent 29c99fce95
commit 680e571c4c
3 changed files with 38 additions and 0 deletions

View File

@ -890,6 +890,9 @@ Status DBImpl::DoCompactionWork(CompactionState* compact) {
compact->compaction->level(),
compact->compaction->num_input_files(1),
compact->compaction->level() + 1);
char scratch[200];
compact->compaction->Summary(scratch, 256);
Log(options_.info_log, "Compaction start summary: %s\n", scratch);
assert(versions_->NumLevelFiles(compact->compaction->level()) > 0);
assert(compact->builder == NULL);

View File

@ -1443,4 +1443,37 @@ void Compaction::ReleaseInputs() {
}
}
static void InputSummary(std::vector<FileMetaData*>& files,
char* output,
int len) {
int write = 0;
for (int i = 0; i < files.size(); i++) {
int sz = len - write;
int ret = snprintf(output + write, sz, "%llu(%llu) ",
files.at(i)->number,
files.at(i)->file_size);
if (ret < 0 || ret >= sz)
break;
write += ret;
}
}
void Compaction::Summary(char* output, int len) {
int write = snprintf(output, len, "Base level %d, inputs:", level_);
if(write < 0 || write > len)
return;
char level_low_summary[100];
InputSummary(inputs_[0], level_low_summary, 100);
char level_up_summary[100];
if (inputs_[1].size()) {
InputSummary(inputs_[1], level_up_summary, 100);
} else {
level_up_summary[0] = '\0';
}
snprintf(output + write, len - write, "[%s],[%s]",
level_low_summary, level_up_summary);
}
} // namespace leveldb

View File

@ -344,6 +344,8 @@ class Compaction {
// is successful.
void ReleaseInputs();
void Summary(char* output, int len);
private:
friend class Version;
friend class VersionSet;