From 680e571c4c3dd5a84c2120498c0217f1d92fa395 Mon Sep 17 00:00:00 2001 From: heyongqiang Date: Fri, 17 Aug 2012 18:10:09 -0700 Subject: [PATCH] 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 --- db/db_impl.cc | 3 +++ db/version_set.cc | 33 +++++++++++++++++++++++++++++++++ db/version_set.h | 2 ++ 3 files changed, 38 insertions(+) diff --git a/db/db_impl.cc b/db/db_impl.cc index f011ed76f..41cc01ad3 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -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); diff --git a/db/version_set.cc b/db/version_set.cc index 015faa815..a51500c46 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -1443,4 +1443,37 @@ void Compaction::ReleaseInputs() { } } +static void InputSummary(std::vector& 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 diff --git a/db/version_set.h b/db/version_set.h index c0cbe7f80..a066f01c9 100644 --- a/db/version_set.h +++ b/db/version_set.h @@ -344,6 +344,8 @@ class Compaction { // is successful. void ReleaseInputs(); + void Summary(char* output, int len); + private: friend class Version; friend class VersionSet;