From e493f2f54e90bc6aa42c4708e32f88af6e4e4e1e Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Wed, 19 Mar 2014 16:01:25 -0700 Subject: [PATCH] Don't compact with zero input files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: We have an issue with internal service trying to run compaction with zero input files: 2014/02/07-02:26:58.386531 7f79117ec700 Compaction start summary: Base version 1420 Base level 3, seek compaction:0, inputs:[ϛ~^Qy^?],[] 2014/02/07-02:26:58.386539 7f79117ec700 Compacted 0@3 + 0@4 files => 0 bytes There are two issues: * inputsummary is printing out junk * it's constantly retrying (since I guess madeProgress is true), so it prints out a lot of data in the LOG file (40GB in one day). I read through the Level compaction picker and added some failure condition if input[0] is empty. I think PickCompaction() should not return compaction with zero input files with this change. I'm not confident enough to add an assertion though :) Test Plan: make check Reviewers: dhruba, haobo, sdong, kailiu Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D16005 --- db/compaction.cc | 5 ++--- db/compaction_picker.cc | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/db/compaction.cc b/db/compaction.cc index 8faa89f672..8bb4f9c61b 100644 --- a/db/compaction.cc +++ b/db/compaction.cc @@ -197,6 +197,7 @@ static void FileSizeSummary(unsigned long long sz, char* output, int len) { static int InputSummary(std::vector& files, char* output, int len) { + *output = '\0'; int write = 0; for (unsigned int i = 0; i < files.size(); i++) { int sz = len - write; @@ -233,9 +234,7 @@ void Compaction::Summary(char* output, int len) { return; } - if (inputs_[1].size()) { - write += InputSummary(inputs_[1], output+write, len-write); - } + write += InputSummary(inputs_[1], output+write, len-write); if (write < 0 || write >= len) { return; } diff --git a/db/compaction_picker.cc b/db/compaction_picker.cc index d585e41ec7..e1b61d7e71 100644 --- a/db/compaction_picker.cc +++ b/db/compaction_picker.cc @@ -178,7 +178,11 @@ bool CompactionPicker::ExpandWhileOverlapping(Compaction* c) { // If, after the expansion, there are files that are already under // compaction, then we must drop/cancel this compaction. int parent_index = -1; - if (FilesInCompaction(c->inputs_[0]) || + if (c->inputs_[0].empty()) { + Log(options_->info_log, + "ExpandWhileOverlapping() failure because zero input files"); + } + if (c->inputs_[0].empty() || FilesInCompaction(c->inputs_[0]) || (c->level() != c->output_level() && ParentRangeInCompaction(c->input_version_, &smallest, &largest, level, &parent_index))) {