From debaf85ef583999ba55353f5390830e8b68ffea5 Mon Sep 17 00:00:00 2001 From: sdong Date: Tue, 14 Apr 2015 19:58:52 -0700 Subject: [PATCH] Bug of trivial move of dynamic level Summary: D36669 introduces a bug that trivial moved data is not going to specific level but the next level, which will incorrectly be level 1 for level 0 compaciton if base level is not level 1. Fixing it by appreciating the output level Test Plan: Run all tests Reviewers: MarkCallaghan, rven, yhchiang, igor Reviewed By: igor Subscribers: leveldb, dhruba Differential Revision: https://reviews.facebook.net/D37119 --- db/db_impl.cc | 2 +- db/db_test.cc | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index 451ec225f..2b073aae7 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -2269,7 +2269,7 @@ Status DBImpl::BackgroundCompaction(bool* madeProgress, JobContext* job_context, assert(c->num_input_files(0) == 1); FileMetaData* f = c->input(0, 0); c->edit()->DeleteFile(c->level(), f->fd.GetNumber()); - c->edit()->AddFile(c->level() + 1, f->fd.GetNumber(), f->fd.GetPathId(), + c->edit()->AddFile(c->output_level(), f->fd.GetNumber(), f->fd.GetPathId(), f->fd.GetFileSize(), f->smallest, f->largest, f->smallest_seqno, f->largest_seqno); status = versions_->LogAndApply(c->column_family_data(), diff --git a/db/db_test.cc b/db/db_test.cc index 6223c3591..555883bd1 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -11114,8 +11114,12 @@ TEST_F(DBTest, DynamicLevelMaxBytesBaseInc) { rocksdb::SyncPoint::GetInstance()->EnableProcessing(); Random rnd(301); - for (int i = 0; i < 3000; i++) { - ASSERT_OK(Put(Key(i), RandomString(&rnd, 102))); + const int total_keys = 3000; + const int random_part_size = 100; + for (int i = 0; i < total_keys; i++) { + std::string value = RandomString(&rnd, random_part_size); + PutFixed32(&value, static_cast(i)); + ASSERT_OK(Put(Key(i), value)); } Flush(); dbfull()->TEST_WaitForCompact(); @@ -11123,6 +11127,12 @@ TEST_F(DBTest, DynamicLevelMaxBytesBaseInc) { ASSERT_EQ(non_trivial, 0); + for (int i = 0; i < total_keys; i++) { + std::string value = Get(Key(i)); + ASSERT_EQ(DecodeFixed32(value.c_str() + random_part_size), + static_cast(i)); + } + env_->SetBackgroundThreads(1, Env::LOW); env_->SetBackgroundThreads(1, Env::HIGH); }