From e4c367392304df2cdf3241813328b3ca7da3ca4d Mon Sep 17 00:00:00 2001 From: Igor Canadi Date: Fri, 1 Aug 2014 06:41:48 -0700 Subject: [PATCH] Never CompactRange to level 0 in level compaction Summary: I was bit by this when developing SpatialDB. In case all files are at level 0, CompactRange() will output the compacted files to level 0. This is not ideal, since read amp. is much better at level 1 and higher. Test Plan: Compacted data in SpatialDB, read manifest using ldb, verified that files are now at level 1 instead of 0. Reviewers: sdong, ljin, yhchiang, dhruba Reviewed By: dhruba Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D20901 --- HISTORY.md | 1 + db/db_impl.cc | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 034676b268..dbae316f5c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -4,6 +4,7 @@ ### New Features * Support Multiple DB paths in universal style compactions * Add feature of storing plain table index and bloom filter in SST file. +* CompactRange() will never output compacted files to level 0. This used to be the case when all the compaction input files were at level 0. ### Public API changes * DBOptions.db_paths now is a vector of a DBPath structure which indicates both of path and target size diff --git a/db/db_impl.cc b/db/db_impl.cc index 986fda3e30..09ea62ef92 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -1638,10 +1638,12 @@ Status DBImpl::CompactRange(ColumnFamilyHandle* column_family, } for (int level = 0; level <= max_level_with_files; level++) { // in case the compaction is unversal or if we're compacting the - // bottom-most level, the output level will be the same as input one + // bottom-most level, the output level will be the same as input one. + // level 0 can never be the bottommost level (i.e. if all files are in level + // 0, we will compact to level 1) if (cfd->options()->compaction_style == kCompactionStyleUniversal || cfd->options()->compaction_style == kCompactionStyleFIFO || - level == max_level_with_files) { + (level == max_level_with_files && level > 0)) { s = RunManualCompaction(cfd, level, level, target_path_id, begin, end); } else { s = RunManualCompaction(cfd, level, level + 1, target_path_id, begin,