From aa14670b2717494d44c6fbbe43dfbfa0e1f48759 Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Thu, 23 Apr 2015 17:46:15 -0700 Subject: [PATCH] Add an assertion in CompactionPicker Summary: Reading CompactionPicker I noticed this dangerous substraction of two unsigned integers. We should assert to mark this as safe. Test Plan: make check Reviewers: anthony, rven, yhchiang, sdong Reviewed By: sdong Subscribers: kradhakrishnan, dhruba, leveldb Differential Revision: https://reviews.facebook.net/D37041 --- db/compaction_picker.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/db/compaction_picker.cc b/db/compaction_picker.cc index d8328ef87..ca813e38b 100644 --- a/db/compaction_picker.cc +++ b/db/compaction_picker.cc @@ -1058,6 +1058,10 @@ Compaction* UniversalCompactionPicker::PickCompaction( // If max read amplification is exceeding configured limits, then force // compaction without looking at filesize ratios and try to reduce // the number of files to fewer than level0_file_num_compaction_trigger. + // This is guaranteed by NeedsCompaction() + assert(sorted_runs.size() >= + static_cast( + mutable_cf_options.level0_file_num_compaction_trigger)); unsigned int num_files = static_cast(sorted_runs.size()) - mutable_cf_options.level0_file_num_compaction_trigger;