From fb6e80f1f6866e98f9f467788eae6ee08e2da56f Mon Sep 17 00:00:00 2001 From: Tyshawn Date: Sat, 12 Oct 2024 03:55:30 +0000 Subject: [PATCH] [BUG.FIX] fix duplicated memtable in tablet memtable array --- src/storage/ob_i_table.h | 4 ++-- src/storage/tablet/ob_table_store_util.cpp | 7 +++++-- src/storage/tablet/ob_tablet.cpp | 5 ++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/storage/ob_i_table.h b/src/storage/ob_i_table.h index 8a87f6ceb..c1999c0a9 100644 --- a/src/storage/ob_i_table.h +++ b/src/storage/ob_i_table.h @@ -163,8 +163,8 @@ public: OB_INLINE bool is_true_major_sstable() const { return is_row_store_major_sstable() || is_column_store_major_sstable(); } OB_INLINE const common::ObTabletID &get_tablet_id() const { return tablet_id_; } - share::SCN get_start_scn() const { return scn_range_.start_scn_; } - share::SCN get_end_scn() const { return scn_range_.end_scn_; } + share::SCN get_start_scn() const { return scn_range_.start_scn_.atomic_get(); } + share::SCN get_end_scn() const { return scn_range_.end_scn_.atomic_get(); } OB_INLINE int64_t get_snapshot_version() const { return version_range_.snapshot_version_; diff --git a/src/storage/tablet/ob_table_store_util.cpp b/src/storage/tablet/ob_table_store_util.cpp index dda4d82d1..970bd4611 100644 --- a/src/storage/tablet/ob_table_store_util.cpp +++ b/src/storage/tablet/ob_table_store_util.cpp @@ -1072,7 +1072,10 @@ bool ObMemtableArray::exist_memtable_with_end_scn(const ObITable *table, const S // we need to make sure duplicate memtable was not added to tablet, // and ensure active memtable could be added to tablet bool is_exist = false; - if (table->get_end_scn() == end_scn && count_ >= 1) { + if (0 >= count_) { + } else if (table->get_end_scn() == end_scn || end_scn.is_max()) { + // Pay Attention!!! + // The end scn of memtable can only be max or a certain value. for (int64_t i = count_ - 1; i >= 0 ; --i) { const ObITable *memtable = memtable_array_[i]; if (memtable == table) { @@ -1439,4 +1442,4 @@ int ObTableStoreUtil::check_has_backup_macro_block(const ObITable *table, bool & } } return ret; -} \ No newline at end of file +} diff --git a/src/storage/tablet/ob_tablet.cpp b/src/storage/tablet/ob_tablet.cpp index cdce08851..be0ea28ec 100644 --- a/src/storage/tablet/ob_tablet.cpp +++ b/src/storage/tablet/ob_tablet.cpp @@ -7498,7 +7498,10 @@ bool ObTablet::exist_memtable_with_end_scn(const ObITable *table, const SCN &end // we need to make sure duplicate memtable was not added to tablet, // and ensure active memtable could be added to tablet bool is_exist = false; - if (table->get_end_scn() == end_scn && memtable_count_ >= 1) { + if (0 >= memtable_count_) { + } else if (table->get_end_scn() == end_scn || end_scn.is_max()) { + // Pay Attention!!! + // The end scn of memtable can only be max or a certain value. for (int64_t i = memtable_count_ - 1; i >= 0 ; --i) { const ObIMemtable *memtable = memtables_[i]; if (memtable == table) {