From 025f70b8762f46ab2ecb28e4400dccb77606f16c Mon Sep 17 00:00:00 2001 From: obdev Date: Sun, 11 Jul 2021 21:00:11 +0800 Subject: [PATCH] =?UTF-8?q?force=C2=A0mini=20minor=20to=20reduce=20mini=20?= =?UTF-8?q?sstable=20cnt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/storage/ob_table_store.cpp | 33 ++++++++++++++++++++++++++------- src/storage/ob_table_store.h | 4 ++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/storage/ob_table_store.cpp b/src/storage/ob_table_store.cpp index 35a087610..14d78b7de 100644 --- a/src/storage/ob_table_store.cpp +++ b/src/storage/ob_table_store.cpp @@ -1320,6 +1320,18 @@ int ObTableStore::deal_with_minor_result( return ret; } +void ObTableStore::adjust_minor_merge_boundary(int64_t &min_snapshot, int64_t &max_snapshot) +{ + if (table_count_ >= OB_UNSAFE_TABLE_CNT) { + max_snapshot = INT64_MAX; + if (table_count_ >= OB_EMERGENCY_TABLE_CNT) { + min_snapshot = 0; + } else if (start_pos_ >= 0 && inc_pos_ > start_pos_) { // get last major sstable after start_pos_ + min_snapshot = tables_[inc_pos_ - 1]->get_snapshot_version(); + } + } +} + int ObTableStore::get_mini_minor_merge_tables( const ObGetMergeTablesParam& param, const int64_t multi_version_start, ObGetMergeTablesResult& result) { @@ -1345,7 +1357,7 @@ int ObTableStore::get_mini_minor_merge_tables( } else if (OB_FAIL(get_neighbour_freeze_info(merge_inc_base_version, freeze_info))) { // get freeze info LOG_WARN("failed to get freeze info", K(ret), K(merge_inc_base_version), K(PRETTY_TS(*this))); } else { - const int64_t min_snapshot_version = freeze_info.prev.freeze_ts; + int64_t min_snapshot_version = freeze_info.prev.freeze_ts; // In the primary and standby database scenarios, // the freeze_info of the standby library may not be refreshed for a long time, // but then drag a minor from the primary database to update the major version. @@ -1353,7 +1365,8 @@ int ObTableStore::get_mini_minor_merge_tables( // If directly do mini minor merge, it will cause the loss of the previous major data, // so the mini minor merge should also use snapshot_gc_ts as the boundary // Unless the multi_version exceeding snapshot_gc_ts is continuous - const int64_t max_snapshot_version = freeze_info.next.freeze_version > 0 ? freeze_info.next.freeze_ts : INT64_MAX; + int64_t max_snapshot_version = freeze_info.next.freeze_version > 0 ? freeze_info.next.freeze_ts : INT64_MAX; + adjust_minor_merge_boundary(min_snapshot_version, max_snapshot_version); const int64_t expect_multi_version = MIN(freeze_info.next.freeze_ts, multi_version_start); if (OB_FAIL(find_mini_minor_merge_tables( param, min_snapshot_version, max_snapshot_version, expect_multi_version, result))) { @@ -1400,6 +1413,7 @@ int ObTableStore::get_hist_minor_range(const ObIArrayget_base_version() < last_freeze_ts) { // skip small minor sstable - } else if (table->get_max_merged_trans_version() > freeze_ts) { + } else if (table->get_snapshot_version() > freeze_ts + || (is_strict_mode && table->get_max_merged_trans_version() > freeze_ts)) { if (cnt > max_cnt) { max_cnt = cnt; max_idx = idx; @@ -1709,6 +1724,7 @@ int ObTableStore::find_mini_minor_merge_tables(const ObGetMergeTablesParam& para const int64_t inc_pos = inc_pos_ >= 0 ? inc_pos_ : 0; const ObMergeType merge_type = param.merge_type_; int64_t reserve_snapshot_for_major = INT64_MAX; + const bool is_strict_mode = table_count_ < OB_UNSAFE_TABLE_CNT; LOG_INFO("find_mini_minor_merge_tables", K(ret), K(min_snapshot_version), @@ -1760,7 +1776,8 @@ int ObTableStore::find_mini_minor_merge_tables(const ObGetMergeTablesParam& para result.handle_.reset(); result.version_range_.reset(); result.log_ts_range_.reset(); - } else if (table->get_max_merged_trans_version() > max_snapshot_version) { + } else if (table->get_snapshot_version() > max_snapshot_version + || (is_strict_mode && table->get_max_merged_trans_version() > max_snapshot_version)) { // snapshot_version <= max_merged_trans_version <= upper_trans_version // upper_trans_version is more safe to keep the minor sstable do not // crossing the major freeze, but it's not always properly filled. @@ -2697,12 +2714,14 @@ int ObTableStore::check_need_mini_minor_merge(const bool using_remote_memstore, int64_t minor_sstable_count = 0; int64_t need_merge_mini_count = 0; int64_t minor_check_snapshot_version = 0; + int64_t min_snapshot_version = freeze_info.prev.freeze_ts; + int64_t max_snapshot_version = freeze_info.next.freeze_version > 0 ? freeze_info.next.freeze_ts : INT64_MAX; + adjust_minor_merge_boundary(min_snapshot_version, max_snapshot_version); for (int64_t i = inc_pos_; OB_SUCC(ret) && i < table_count_; ++i) { if (!is_own_table(tables_[i])) { continue; - } else if (tables_[i]->get_base_version() >= freeze_info.prev.freeze_ts) { - if (freeze_info.next.freeze_version > 0 && - tables_[i]->get_max_merged_trans_version() > freeze_info.next.freeze_ts) { + } else if (tables_[i]->get_base_version() >= min_snapshot_version) { + if (tables_[i]->get_max_merged_trans_version() > max_snapshot_version) { break; } minor_sstable_count++; diff --git a/src/storage/ob_table_store.h b/src/storage/ob_table_store.h index af56b98d0..6686d09d0 100644 --- a/src/storage/ob_table_store.h +++ b/src/storage/ob_table_store.h @@ -163,6 +163,7 @@ public: private: // Common Section + void adjust_minor_merge_boundary(int64_t &min_snapshot, int64_t &max_snapshot); bool is_multi_version_break(const ObVersionRange& new_version_range, const int64_t last_snapshot_vesion); int classify_tables(const ObTablesHandle& old_handle, common::ObArray& major_tables, common::ObArray& inc_tables); @@ -237,10 +238,13 @@ private: const ObTablesHandle& old_handle, int64_t& first_reference_pos, int64_t& last_reference_pos); int get_major_split_table_pos(const ObTablesHandle& old_handle, int64_t& pos); + protected: static const int64_t INVAID_TABLE_POS = -1; static const int64_t DEFAULT_SSTABLE_CNT = 6; static const int64_t OB_HIST_MINOR_FACTOR = 3; + static const int64_t OB_UNSAFE_TABLE_CNT = 48; + static const int64_t OB_EMERGENCY_TABLE_CNT = 52; // No Need Persistence bool is_inited_; ObFreezeInfoSnapshotMgr* freeze_info_mgr_;