From 75d7075a8aa0dec5f0a2ef054bce8e17c369206a Mon Sep 17 00:00:00 2001 From: sdong Date: Mon, 8 Jun 2015 23:14:13 -0700 Subject: [PATCH] Print info message about files need compaction for debuging purpose Summary: When there are files marked for compaction after compactions, print extra messages to help debugging. Example: 2015/06/08-23:12:55.212855 7ff5013ff700 [default] [JOB 121] Generated table #75: 54 keys, 4807 bytes (need compaction) 2015/06/08-23:12:55.556194 7ff5013ff700 (Original Log Time 2015/06/08-23:12:55.556160) [default] compacted to: base level 1 max bytes base 10240 files[0 1 9 32 12 0 0 0] max score 0.96 (2 files need compaction), MB/sec: 0.0 rd, 0.1 wr, level 2, files in(1, 3) out(5) MB in(0.0, 0.0) out(0.0), read-write-amplify(11.3) write-amplify(5.7) OK, records in: 40, records dropped: 0 Test Plan: Run test and see LOG files. valgrind test DBTest.TablePropertiesNeedCompactTest Reviewers: rven, yhchiang, kradhakrishnan, IslamAbdelRahman, igor Reviewed By: igor Subscribers: yoshinorim, maykov, leveldb, dhruba Differential Revision: https://reviews.facebook.net/D39771 --- db/compaction_job.cc | 6 ++++-- db/flush_job.cc | 7 +++++-- db/version_set.cc | 11 +++++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/db/compaction_job.cc b/db/compaction_job.cc index 47275f00a..0b04a3d8e 100644 --- a/db/compaction_job.cc +++ b/db/compaction_job.cc @@ -1067,9 +1067,11 @@ Status CompactionJob::FinishCompactionOutputFile(Iterator* input) { info.job_id = job_id_; Log(InfoLogLevel::INFO_LEVEL, db_options_.info_log, "[%s] [JOB %d] Generated table #%" PRIu64 ": %" PRIu64 - " keys, %" PRIu64 " bytes", + " keys, %" PRIu64 " bytes%s", cfd->GetName().c_str(), job_id_, output_number, current_entries, - current_bytes); + current_bytes, + compact_->current_output()->need_compaction ? " (need compaction)" + : ""); EventHelpers::LogAndNotifyTableFileCreation( event_logger_, cfd->ioptions()->listeners, fd, info); } diff --git a/db/flush_job.cc b/db/flush_job.cc index 7536b2ba8..d6a5f7867 100644 --- a/db/flush_job.cc +++ b/db/flush_job.cc @@ -244,9 +244,12 @@ Status FlushJob::WriteLevel0Table(const autovector& mems, LogFlush(db_options_.info_log); } Log(InfoLogLevel::INFO_LEVEL, db_options_.info_log, - "[%s] [JOB %d] Level-0 flush table #%" PRIu64 ": %" PRIu64 " bytes %s", + "[%s] [JOB %d] Level-0 flush table #%" PRIu64 ": %" PRIu64 + " bytes %s" + "%s", cfd_->GetName().c_str(), job_context_->job_id, meta.fd.GetNumber(), - meta.fd.GetFileSize(), s.ToString().c_str()); + meta.fd.GetFileSize(), s.ToString().c_str(), + meta.marked_for_compaction ? " (needs compaction)" : ""); // output to event logger if (s.ok()) { diff --git a/db/version_set.cc b/db/version_set.cc index 5d2f2f801..7494ce5ee 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -1551,8 +1551,15 @@ const char* VersionStorageInfo::LevelSummary( // overwrite the last space --len; } - snprintf(scratch->buffer + len, sizeof(scratch->buffer) - len, - "] max score %.2f", compaction_score_[0]); + len += snprintf(scratch->buffer + len, sizeof(scratch->buffer) - len, + "] max score %.2f", compaction_score_[0]); + + if (!files_marked_for_compaction_.empty()) { + snprintf(scratch->buffer + len, sizeof(scratch->buffer) - len, + " (%zu files need compaction)", + files_marked_for_compaction_.size()); + } + return scratch->buffer; }