From 184343a061a41f104d4b0bdb53883feaa2147140 Mon Sep 17 00:00:00 2001 From: Mayank Agarwal Date: Sat, 8 Jun 2013 20:15:10 -0700 Subject: [PATCH] Max_mem_compaction_level can have maximum value of num_levels-1 Summary: Without this files could be written out to a level greater than the maximum level possible and is the source of the segfaults that wormhole awas getting. The sequence of steps that was followed: 1. WriteLevel0Table was called when memtable was to be flushed for a file. 2. PickLevelForMemTableOutput was called to determine the level to which this file should be pushed. 3. PickLevelForMemTableOutput returned a wrong result because max_mem_compaction_level was equal to 2 even when num_levels was equal to 0. The fix to re-initialize max_mem_compaction_level based on num_levels passed seems correct. Test Plan: make all check; Also made a dummy file to mimic the wormhole-file behaviour which was causing the segfaults and found that the same segfault occurs without this change and not with this. Reviewers: dhruba, haobo Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D11157 --- db/db_impl.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/db/db_impl.cc b/db/db_impl.cc index 686682451..37e22b005 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -141,6 +141,9 @@ Options SanitizeOptions(const std::string& dbname, if (result.block_size_deviation < 0 || result.block_size_deviation > 100) { result.block_size_deviation = 0; } + if (result.max_mem_compaction_level >= result.num_levels) { + result.max_mem_compaction_level = result.num_levels - 1; + } return result; }