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); }