From 2acfa1137c51fe4fffc800c7e7cf0d5402de836e Mon Sep 17 00:00:00 2001 From: Fengjingkun Date: Mon, 29 May 2023 04:11:49 +0000 Subject: [PATCH] [CP] fix bug about update memtables in table store --- src/storage/tablet/ob_table_store_util.cpp | 15 +++++++++++---- src/storage/tablet/ob_table_store_util.h | 2 +- src/storage/tablet/ob_tablet_table_store.cpp | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/storage/tablet/ob_table_store_util.cpp b/src/storage/tablet/ob_table_store_util.cpp index c291befc32..b32a870040 100644 --- a/src/storage/tablet/ob_table_store_util.cpp +++ b/src/storage/tablet/ob_table_store_util.cpp @@ -584,7 +584,9 @@ int ObMemtableArray::build( return ret; } -int ObMemtableArray::rebuild(common::ObIArray &handle_array) +int ObMemtableArray::rebuild( + const share::SCN &clog_checkpoint_scn, + common::ObIArray &handle_array) { int ret = OB_SUCCESS; @@ -593,7 +595,9 @@ int ObMemtableArray::rebuild(common::ObIArray &handle_array) LOG_ERROR("ObMemtableArray not inited", K(ret), KPC(this), K(handle_array)); } else { ObITable *last_memtable = get_table(count() - 1); - SCN end_scn = (NULL == last_memtable) ? SCN::min_scn() : last_memtable->get_end_scn(); + SCN last_memtable_end_scn = (NULL == last_memtable) + ? clog_checkpoint_scn // memtable was filtered when tablet was initialized, use ckpt scn to filter again + : last_memtable->get_end_scn(); for (int64_t i = 0; OB_SUCC(ret) && i < handle_array.count(); ++i) { memtable::ObMemtable *memtable = nullptr; @@ -604,8 +608,11 @@ int ObMemtableArray::rebuild(common::ObIArray &handle_array) } else if (FALSE_IT(memtable = reinterpret_cast(table))) { } else if (memtable->is_empty()) { FLOG_INFO("Empty memtable discarded", KPC(memtable)); - } else if (table->get_end_scn() < end_scn) { - } else if (table->get_end_scn() == end_scn && table == last_memtable) { //fix issue 41996395 + } else if (memtable->get_end_scn() == last_memtable_end_scn && memtable == last_memtable) { + // fix issue 41996395 + // if last memtable is freezing, its end scn may still be INT64_MAX, which will cause the new active memtable to be filtered. + continue; + } else if (memtable->get_end_scn() <= last_memtable_end_scn) { } else if (OB_FAIL(add_table(table))) { LOG_WARN("failed to add memtable to curr memtables", K(ret), KPC(this)); } diff --git a/src/storage/tablet/ob_table_store_util.h b/src/storage/tablet/ob_table_store_util.h index f8c69ecdc4..6cf530b040 100644 --- a/src/storage/tablet/ob_table_store_util.h +++ b/src/storage/tablet/ob_table_store_util.h @@ -111,7 +111,7 @@ public: int init(common::ObIAllocator *allocator); int init(common::ObIAllocator *allocator, const ObMemtableArray &other); int build(common::ObIArray &handle_array, const int64_t start_pos = 0); - int rebuild(common::ObIArray &handle_array); + int rebuild(const share::SCN &clog_checkpoint_scn, common::ObIArray &handle_array); int prepare_allocate(); int find(const ObITable::TableKey &table_key, ObTableHandleV2 &handle) const; int find(const share::SCN &start_scn, const int64_t base_version, ObITable *&table, int64_t &mem_pos) const; diff --git a/src/storage/tablet/ob_tablet_table_store.cpp b/src/storage/tablet/ob_tablet_table_store.cpp index 6c997507df..208c37fe82 100644 --- a/src/storage/tablet/ob_tablet_table_store.cpp +++ b/src/storage/tablet/ob_tablet_table_store.cpp @@ -440,7 +440,7 @@ int ObTabletTableStore::update_memtables() } else if (OB_FAIL(tablet_ptr_->get_memtable_mgr()->get_all_memtables(inc_memtables))) { LOG_WARN("failed to get all memtables from memtable_mgr", K(ret)); } else if (FALSE_IT(time_guard.click("get_all_memtable"))) { - } else if (OB_FAIL(memtables_.rebuild(inc_memtables))) { + } else if (OB_FAIL(memtables_.rebuild(tablet_ptr_->get_clog_checkpoint_scn(), inc_memtables))) { LOG_ERROR("failed to rebuild table store memtables", K(ret), K(inc_memtables), KPC(this)); } else if (FALSE_IT(time_guard.click("memtables_.rebuild"))) { } else {