From f29e6b3be29523e09e49e68f7dc8ed5f92586324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=94=A1=E6=B8=A0=E6=A3=A0?= Date: Mon, 11 Nov 2019 15:56:07 -0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20MemTableList::RemoveOldMemTables=20in?= =?UTF-8?q?valid=20iterator=20after=20remov=E2=80=A6=20(#6013)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Fix issue https://github.com/facebook/rocksdb/issues/6012. I found that it may be caused by the following codes in function _RemoveOldMemTables()_ in **db/memtable_list.cc** : ``` for (auto it = memlist.rbegin(); it != memlist.rend(); ++it) { MemTable* mem = *it; if (mem->GetNextLogNumber() > log_number) { break; } current_->Remove(mem, to_delete); ``` The iterator **it** turns invalid after `current_->Remove(mem, to_delete);` Pull Request resolved: https://github.com/facebook/rocksdb/pull/6013 Test Plan: ``` make check ``` Differential Revision: D18401107 Pulled By: riversand963 fbshipit-source-id: bf0da3b868ed70f7aff24cf7b3e2049c0c5c7a4e --- db/memtable_list.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/db/memtable_list.cc b/db/memtable_list.cc index de212b6a5..d9159b793 100644 --- a/db/memtable_list.cc +++ b/db/memtable_list.cc @@ -736,17 +736,24 @@ void MemTableList::RemoveOldMemTables(uint64_t log_number, assert(to_delete != nullptr); InstallNewVersion(); auto& memlist = current_->memlist_; + autovector old_memtables; for (auto it = memlist.rbegin(); it != memlist.rend(); ++it) { MemTable* mem = *it; if (mem->GetNextLogNumber() > log_number) { break; } + old_memtables.push_back(mem); + } + + for (auto it = old_memtables.begin(); it != old_memtables.end(); ++it) { + MemTable* mem = *it; current_->Remove(mem, to_delete); --num_flush_not_started_; if (0 == num_flush_not_started_) { imm_flush_needed.store(false, std::memory_order_release); } } + UpdateMemoryUsageExcludingLast(); ResetTrimHistoryNeeded(); }