From 6480717a267982559edb108d05c75df9f2f9eef2 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Thu, 24 Jul 2014 17:06:00 -0700 Subject: [PATCH] Fixed compaction-related errors where number of input levels are hard-coded. Summary: Fixed compaction-related errors where number of input levels are hard-coded. It's a bug found in compaction branch. This diff will be pushed into master. Test Plan: export ROCKSDB_TESTS=Compact make db_test -j32 ./db_test also passed the tests in compaction branch Reviewers: igor, sdong, ljin Reviewed By: ljin Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D20577 --- db/compaction.cc | 4 ++-- db/version_set.cc | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/db/compaction.cc b/db/compaction.cc index 620474dbc..40941a98d 100644 --- a/db/compaction.cc +++ b/db/compaction.cc @@ -82,8 +82,8 @@ Compaction::~Compaction() { } void Compaction::GenerateFileLevels() { - input_levels_.resize(2); - for (int which = 0; which < 2; which++) { + input_levels_.resize(num_input_levels()); + for (int which = 0; which < num_input_levels(); which++) { DoGenerateFileLevel(&input_levels_[which], inputs_[which].files, &arena_); } } diff --git a/db/version_set.cc b/db/version_set.cc index c27c7f340..ae0759daa 100644 --- a/db/version_set.cc +++ b/db/version_set.cc @@ -2825,10 +2825,12 @@ Iterator* VersionSet::MakeInputIterator(Compaction* c) { // Level-0 files have to be merged together. For other levels, // we will make a concatenating iterator per level. // TODO(opt): use concatenating iterator for level-0 if there is no overlap - const int space = (c->level() == 0 ? c->input_levels(0)->num_files + 1 : 2); + const int space = (c->level() == 0 ? + c->input_levels(0)->num_files + c->num_input_levels() - 1: + c->num_input_levels()); Iterator** list = new Iterator*[space]; int num = 0; - for (int which = 0; which < 2; which++) { + for (int which = 0; which < c->num_input_levels(); which++) { if (c->input_levels(which)->num_files != 0) { if (c->level(which) == 0) { const FileLevel* flevel = c->input_levels(which);