diff --git a/db/column_family_test.cc b/db/column_family_test.cc index 686bab20d6f2162722608cc7d4e4bf738c238254..88479323ce3eb3977815215f5694f417b7cb8098 100644 --- a/db/column_family_test.cc +++ b/db/column_family_test.cc @@ -529,8 +529,28 @@ TEST(ColumnFamilyTest, FlushTest) { ASSERT_OK(Put(1, "mirko", "v3")); ASSERT_OK(Put(0, "foo", "v2")); ASSERT_OK(Put(2, "fodor", "v5")); - for (int i = 0; i < 3; ++i) { - Flush(i); + + for (int j = 0; j < 2; j++) { + ReadOptions ro; + std::vector iterators; + // Hold super version. + if (j == 0) { + ASSERT_OK(db_->NewIterators(ro, handles_, &iterators)); + } + + for (int i = 0; i < 3; ++i) { + uint64_t max_total_in_memory_state = + dbfull()->TEST_max_total_in_memory_state(); + Flush(i); + ASSERT_EQ(dbfull()->TEST_max_total_in_memory_state(), + max_total_in_memory_state); + } + ASSERT_OK(Put(1, "foofoo", "bar")); + ASSERT_OK(Put(0, "foofoo", "bar")); + + for (auto* it : iterators) { + delete it; + } } Reopen(); diff --git a/db/db_impl.cc b/db/db_impl.cc index a090deb76413a4f6bc8db676df193a6310c9d345..9651544173b89e34bacf5f2896f1b44dee39d069 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -2272,6 +2272,15 @@ SuperVersion* DBImpl::InstallSuperVersion( ColumnFamilyData* cfd, SuperVersion* new_sv, const MutableCFOptions& mutable_cf_options) { mutex_.AssertHeld(); + + // Update max_total_in_memory_state_ + size_t old_memtable_size = 0; + auto* old_sv = cfd->GetSuperVersion(); + if (old_sv) { + old_memtable_size = old_sv->mutable_cf_options.write_buffer_size * + old_sv->mutable_cf_options.max_write_buffer_number; + } + auto* old = cfd->InstallSuperVersion( new_sv ? new_sv : new SuperVersion(), &mutex_, mutable_cf_options); @@ -2281,11 +2290,6 @@ SuperVersion* DBImpl::InstallSuperVersion( MaybeScheduleFlushOrCompaction(); // Update max_total_in_memory_state_ - size_t old_memtable_size = 0; - if (old) { - old_memtable_size = old->mutable_cf_options.write_buffer_size * - old->mutable_cf_options.max_write_buffer_number; - } max_total_in_memory_state_ = max_total_in_memory_state_ - old_memtable_size + mutable_cf_options.write_buffer_size * diff --git a/db/db_impl.h b/db/db_impl.h index 189937b0f80ceef9a402f7cd32eeb799efba47eb..6577733b6057c6a9e2d0c9c7a46bbfae4da86de9 100644 --- a/db/db_impl.h +++ b/db/db_impl.h @@ -230,6 +230,10 @@ class DBImpl : public DB { // REQUIRES: mutex locked // pass the pointer that you got from TEST_BeginWrite() void TEST_EndWrite(void* w); + + uint64_t TEST_max_total_in_memory_state() { + return max_total_in_memory_state_; + } #endif // ROCKSDB_LITE // Returns the list of live files in 'live' and the list diff --git a/include/rocksdb/options.h b/include/rocksdb/options.h index 054d2c3e129c68595a3d2a957877a0e57d9d8e7f..298ec6aee6985b658e2f6a8bcb1715ad3113caf9 100644 --- a/include/rocksdb/options.h +++ b/include/rocksdb/options.h @@ -686,7 +686,7 @@ struct DBOptions { // column families whose memtables are backed by the oldest live WAL file // (i.e. the ones that are causing all the space amplification). If set to 0 // (default), we will dynamically choose the WAL size limit to be - // [sum of all write_buffer_size * max_write_buffer_number] * 2 + // [sum of all write_buffer_size * max_write_buffer_number] * 4 // Default: 0 uint64_t max_total_wal_size;