From a92b7ae7cf0c0ed9825d6733ed3776be3cfd352c Mon Sep 17 00:00:00 2001 From: yangqise7en <877793735@qq.com> Date: Tue, 8 Oct 2024 15:15:41 +0000 Subject: [PATCH] check scheduler ptr before use & do not check CPU load in enable_adaptive_compaction --- .../scheduler/ob_tenant_dag_scheduler.cpp | 9 ++++++-- src/storage/access/ob_multiple_merge.cpp | 5 ++++- .../ob_basic_schedule_tablet_func.cpp | 2 +- .../compaction/ob_compaction_schedule_util.h | 2 +- src/storage/compaction/ob_medium_loop.cpp | 2 +- .../compaction/ob_schedule_tablet_func.cpp | 16 +++++++++----- .../compaction/ob_schedule_tablet_func.h | 5 +++-- .../compaction/ob_tenant_freeze_info_mgr.cpp | 5 ++++- .../compaction/ob_tenant_status_cache.cpp | 4 +--- .../compaction/ob_tenant_status_cache.h | 3 ++- .../compaction/ob_tenant_tablet_scheduler.cpp | 2 +- src/storage/tablet/ob_tablet.cpp | 22 ++++++++++++------- 12 files changed, 49 insertions(+), 28 deletions(-) diff --git a/src/share/scheduler/ob_tenant_dag_scheduler.cpp b/src/share/scheduler/ob_tenant_dag_scheduler.cpp index b023954ba..baddac145 100644 --- a/src/share/scheduler/ob_tenant_dag_scheduler.cpp +++ b/src/share/scheduler/ob_tenant_dag_scheduler.cpp @@ -2288,7 +2288,12 @@ int ObDagPrioScheduler::rank_compaction_dags_() int ret = OB_SUCCESS; int tmp_ret = OB_SUCCESS; const int64_t batch_size = adaptive_task_limit_ * COMPACTION_DAG_RERANK_FACTOR; - const bool need_adaptive_schedule = ObBasicMergeScheduler::get_merge_scheduler()->enable_adaptive_merge_schedule(); + bool need_adaptive_schedule = false; + const compaction::ObBasicMergeScheduler *scheduler = nullptr; + + if (OB_NOT_NULL(scheduler = ObBasicMergeScheduler::get_merge_scheduler())) { + need_adaptive_schedule = scheduler->enable_adaptive_merge_schedule(); + } if (!check_need_compaction_rank_()) { // ready list has plenty of dags, no need to rank new dags @@ -3060,7 +3065,7 @@ int ObDagPrioScheduler::get_max_major_finish_time( } } if (OB_NOT_NULL(progress) && progress->get_estimated_finish_time() > estimated_finish_time) { - estimated_finish_time = estimated_finish_time; + estimated_finish_time = progress->get_estimated_finish_time(); } } else { break; diff --git a/src/storage/access/ob_multiple_merge.cpp b/src/storage/access/ob_multiple_merge.cpp index 5f0a1fcab..87e40e659 100644 --- a/src/storage/access/ob_multiple_merge.cpp +++ b/src/storage/access/ob_multiple_merge.cpp @@ -813,7 +813,10 @@ int ObMultipleMerge::update_and_report_tablet_stat() access_ctx_->table_scan_stat_->row_cache_hit_cnt_ += access_ctx_->table_store_stat_.row_cache_hit_cnt_; access_ctx_->table_scan_stat_->row_cache_miss_cnt_ += access_ctx_->table_store_stat_.row_cache_miss_cnt_; } - if (compaction::ObBasicMergeScheduler::get_merge_scheduler()->enable_adaptive_compaction()) { + const compaction::ObBasicMergeScheduler *scheduler = nullptr; + if (OB_ISNULL(scheduler = compaction::ObBasicMergeScheduler::get_merge_scheduler())) { + // may be during the start phase + } else if (scheduler->enable_adaptive_compaction()) { report_tablet_stat(); } access_ctx_->table_store_stat_.reuse(); diff --git a/src/storage/compaction/ob_basic_schedule_tablet_func.cpp b/src/storage/compaction/ob_basic_schedule_tablet_func.cpp index cf4a09cbd..8338aaa67 100644 --- a/src/storage/compaction/ob_basic_schedule_tablet_func.cpp +++ b/src/storage/compaction/ob_basic_schedule_tablet_func.cpp @@ -62,7 +62,7 @@ int ObBasicScheduleTabletFunc::switch_ls(ObLSHandle &ls_handle) void ObBasicScheduleTabletFunc::update_tenant_cached_status() { - ObBasicMergeScheduler * scheduler = ObBasicMergeScheduler::get_merge_scheduler(); + const ObBasicMergeScheduler * scheduler = ObBasicMergeScheduler::get_merge_scheduler(); if (OB_NOT_NULL(scheduler)) { is_skip_merge_tenant_ = scheduler->get_tenant_status().is_skip_merge_tenant(); ls_could_schedule_merge_ = scheduler->could_major_merge_start() && ls_status_.can_merge(); diff --git a/src/storage/compaction/ob_compaction_schedule_util.h b/src/storage/compaction/ob_compaction_schedule_util.h index 5640ecd22..b4ec1eda0 100644 --- a/src/storage/compaction/ob_compaction_schedule_util.h +++ b/src/storage/compaction/ob_compaction_schedule_util.h @@ -96,7 +96,7 @@ public: virtual int schedule_merge(const int64_t broadcast_version) = 0; void update_merged_version(const int64_t merged_version); int64_t get_merged_version() const { return merged_version_; } - bool enable_adaptive_compaction() { return tenant_status_.enable_adaptive_compaction(); } + bool enable_adaptive_compaction() const { return tenant_status_.enable_adaptive_compaction(); } bool enable_adaptive_merge_schedule() const { return tenant_status_.enable_adaptive_merge_schedule(); } const ObTenantStatusCache &get_tenant_status() const { return tenant_status_; } static const int64_t INIT_COMPACTION_SCN = 1; diff --git a/src/storage/compaction/ob_medium_loop.cpp b/src/storage/compaction/ob_medium_loop.cpp index 89a9b833c..b8e256c85 100644 --- a/src/storage/compaction/ob_medium_loop.cpp +++ b/src/storage/compaction/ob_medium_loop.cpp @@ -265,7 +265,7 @@ int ObScheduleNewMediumLoop::loop() } else if (OB_FAIL(ls_handle.get_ls()->get_tablet_svr()->get_tablet( tablet_id, tablet_handle, 0 /*timeout_us*/))) { LOG_WARN("get tablet failed", K(ret), K(ls_id), K(tablet_id)); - } else if (OB_FAIL(func.request_schedule_new_round(tablet_handle, false/*print_warn_log*/))) { + } else if (OB_FAIL(func.request_schedule_new_round(tablet_handle, false/*user_request*/))) { LOG_WARN("get tablet failed", K(ret), K(ls_id), K(tablet_id)); } } // end of for diff --git a/src/storage/compaction/ob_schedule_tablet_func.cpp b/src/storage/compaction/ob_schedule_tablet_func.cpp index ca3b4ba6a..f0462ef94 100644 --- a/src/storage/compaction/ob_schedule_tablet_func.cpp +++ b/src/storage/compaction/ob_schedule_tablet_func.cpp @@ -64,7 +64,7 @@ int ObScheduleTabletFunc::schedule_tablet( tablet_merge_finish = true; tablet_cnt_.finish_cnt_++; } - if (tablet_status_.could_schedule_new_round() && OB_TMP_FAIL(schedule_tablet_new_round(tablet_handle))) { + if (tablet_status_.could_schedule_new_round() && OB_TMP_FAIL(schedule_tablet_new_round(tablet_handle, false/*user_request*/))) { need_diagnose = true; LOG_WARN("failed to schedule tablet new round", KR(tmp_ret), K_(ls_status), K(tablet_id)); } @@ -89,17 +89,21 @@ int ObScheduleTabletFunc::schedule_tablet( } int ObScheduleTabletFunc::schedule_tablet_new_round( - ObTabletHandle &tablet_handle) + ObTabletHandle &tablet_handle, + const bool user_request) { int ret = OB_SUCCESS; int tmp_ret = OB_SUCCESS; const ObLSID &ls_id = ls_status_.ls_id_; const ObTabletID &tablet_id = tablet_handle.get_obj()->get_tablet_id(); bool medium_clog_submitted = false; + if (OB_ISNULL(tablet_status_.medium_list())) { ret = OB_ERR_UNEXPECTED; LOG_WARN("medium list in tablet status is null", KR(ret), K_(tablet_status)); - } else { + } else if (!tablet_status_.tablet_merge_finish() + || user_request + || ObBasicMergeScheduler::get_merge_scheduler()->get_tenant_status().enable_adaptive_compaction_with_cpu_load()) { ObMediumCompactionScheduleFunc func( ls_status_.get_ls(), tablet_handle, ls_status_.weak_read_ts_, *tablet_status_.medium_list(), &tablet_cnt_, @@ -125,7 +129,7 @@ int ObScheduleTabletFunc::schedule_tablet_new_round( int ObScheduleTabletFunc::request_schedule_new_round( ObTabletHandle &tablet_handle, - const bool print_warn_log) + const bool user_request) { int ret = OB_SUCCESS; int tmp_ret = OB_SUCCESS; @@ -149,7 +153,7 @@ int ObScheduleTabletFunc::request_schedule_new_round( ls_status_.get_ls(), merge_version_, *tablet, is_skip_merge_tenant_, ls_could_schedule_new_round_))) { LOG_WARN("failed to init tablet status", KR(ret), K_(ls_status), K(tablet_id)); - } else if (print_warn_log) { // should print error log for user request + } else if (user_request) { // should print error log for user request if (!tablet_status_.tablet_merge_finish()) { ret = OB_MAJOR_FREEZE_NOT_FINISHED; LOG_WARN("no major sstable or not finish tenant major compaction, can't schedule another medium", @@ -168,7 +172,7 @@ int ObScheduleTabletFunc::request_schedule_new_round( } else { schedule_flag = tablet_status_.tablet_merge_finish() && tablet_status_.could_schedule_new_round(); } - if (OB_SUCC(ret) && schedule_flag && OB_TMP_FAIL(schedule_tablet_new_round(tablet_handle))) { + if (OB_SUCC(ret) && schedule_flag && OB_TMP_FAIL(schedule_tablet_new_round(tablet_handle, user_request))) { LOG_WARN("failed to schedule tablet new round", KR(tmp_ret), K_(ls_status), K(tablet_id)); } tablet_status_.destroy(); diff --git a/src/storage/compaction/ob_schedule_tablet_func.h b/src/storage/compaction/ob_schedule_tablet_func.h index afaa5951f..be6320a9e 100644 --- a/src/storage/compaction/ob_schedule_tablet_func.h +++ b/src/storage/compaction/ob_schedule_tablet_func.h @@ -31,7 +31,7 @@ struct ObScheduleTabletFunc final : public ObBasicScheduleTabletFunc bool &tablet_merge_finish); int request_schedule_new_round( storage::ObTabletHandle &tablet_handle, - const bool print_warn_log); + const bool user_request); const ObTabletStatusCache &get_tablet_status() const { return tablet_status_; } virtual const ObCompactionTimeGuard &get_time_guard() const override { return time_guard_; } int diagnose_switch_tablet(storage::ObLS &ls, const storage::ObTablet &tablet); @@ -40,7 +40,8 @@ struct ObScheduleTabletFunc final : public ObBasicScheduleTabletFunc private: virtual void schedule_freeze_dag(const bool force) override; int schedule_tablet_new_round( - storage::ObTabletHandle &tablet_handle); + storage::ObTabletHandle &tablet_handle, + const bool user_request); int schedule_tablet_execute( storage::ObTablet &tablet); int get_schedule_execute_info( diff --git a/src/storage/compaction/ob_tenant_freeze_info_mgr.cpp b/src/storage/compaction/ob_tenant_freeze_info_mgr.cpp index e9c2396bd..f86242f5c 100644 --- a/src/storage/compaction/ob_tenant_freeze_info_mgr.cpp +++ b/src/storage/compaction/ob_tenant_freeze_info_mgr.cpp @@ -686,7 +686,10 @@ void ObTenantFreezeInfoMgr::UpdateLSResvSnapshotTask::runTimerTask() { int tmp_ret = OB_SUCCESS; uint64_t compat_version = 0; - if (OB_TMP_FAIL(ObBasicMergeScheduler::get_merge_scheduler()->get_min_data_version(compat_version))) { + compaction::ObBasicMergeScheduler *scheduler = nullptr; + if (OB_ISNULL(scheduler = compaction::ObBasicMergeScheduler::get_merge_scheduler())) { + // may be during the start phase + } else if (OB_TMP_FAIL(scheduler->get_min_data_version(compat_version))) { LOG_WARN_RET(tmp_ret, "failed to get min data version", KR(tmp_ret)); } else if (compat_version < DATA_VERSION_4_1_0_0) { // do nothing, should not update reserved snapshot diff --git a/src/storage/compaction/ob_tenant_status_cache.cpp b/src/storage/compaction/ob_tenant_status_cache.cpp index dda84f70b..35189b913 100644 --- a/src/storage/compaction/ob_tenant_status_cache.cpp +++ b/src/storage/compaction/ob_tenant_status_cache.cpp @@ -165,19 +165,17 @@ int ObTenantStatusCache::refresh_data_version() return ret; } -bool ObTenantStatusCache::enable_adaptive_compaction() +bool ObTenantStatusCache::enable_adaptive_compaction_with_cpu_load() const { bool bret = enable_adaptive_compaction_; if (!bret || !enable_adaptive_merge_schedule()) { // do nothing #ifdef ENABLE_DEBUG_LOG } else if (GCONF.enable_crazy_medium_compaction) { - enable_adaptive_compaction_ = true; bret = true; LOG_DEBUG("set crazy medium, set enable_adaptive_compaction = true"); #endif } else if (MTL(ObTenantTabletStatMgr *)->is_high_tenant_cpu_load()) { - enable_adaptive_compaction_ = false; bret = false; if (REACH_TENANT_TIME_INTERVAL(PRINT_LOG_INVERVAL)) { FLOG_INFO("disable adaptive compaction due to the high load CPU", K(bret)); diff --git a/src/storage/compaction/ob_tenant_status_cache.h b/src/storage/compaction/ob_tenant_status_cache.h index e59cf03af..9f1054d4a 100644 --- a/src/storage/compaction/ob_tenant_status_cache.h +++ b/src/storage/compaction/ob_tenant_status_cache.h @@ -38,7 +38,8 @@ struct ObTenantStatusCache final int during_restore(bool &during_restore) const; bool is_inited() const { return is_inited_; } bool is_skip_merge_tenant() const; - bool enable_adaptive_compaction(); + bool enable_adaptive_compaction() const { return enable_adaptive_compaction_; } + bool enable_adaptive_compaction_with_cpu_load() const; bool enable_adaptive_merge_schedule() const { return enable_adaptive_merge_schedule_; } int get_min_data_version(uint64_t &min_data_version); diff --git a/src/storage/compaction/ob_tenant_tablet_scheduler.cpp b/src/storage/compaction/ob_tenant_tablet_scheduler.cpp index 734926dd8..233a7aabf 100644 --- a/src/storage/compaction/ob_tenant_tablet_scheduler.cpp +++ b/src/storage/compaction/ob_tenant_tablet_scheduler.cpp @@ -1544,7 +1544,7 @@ int ObTenantTabletScheduler::user_request_schedule_medium_merge( } else if (OB_FAIL(ls_handle.get_ls()->get_tablet_svr()->get_tablet( tablet_id, tablet_handle, 0 /*timeout_us*/))) { LOG_WARN("get tablet failed", K(ret), K(ls_id), K(tablet_id)); - } else if (OB_FAIL(func.request_schedule_new_round(tablet_handle, true/*print_warn_log*/))) { + } else if (OB_FAIL(func.request_schedule_new_round(tablet_handle, true/*user_request*/))) { LOG_WARN("failed to request schedule new round", K(ret), K(ls_id), K(tablet_id)); } } diff --git a/src/storage/tablet/ob_tablet.cpp b/src/storage/tablet/ob_tablet.cpp index 83dcd953c..9cd3d34fa 100644 --- a/src/storage/tablet/ob_tablet.cpp +++ b/src/storage/tablet/ob_tablet.cpp @@ -4631,10 +4631,13 @@ int ObTablet::do_rowkey_exists( // ROWKEY IN_ROW_CACHE / NOT EXIST } else if (FALSE_IT(context.store_ctx_->tablet_stat_.exist_row_read_table_cnt_ = check_table_cnt)) { } else if (FALSE_IT(context.store_ctx_->tablet_stat_.exist_row_total_table_cnt_ = table_iter.table_store_iter_.count())) { - } else if (ObBasicMergeScheduler::get_merge_scheduler()->enable_adaptive_compaction()) { - bool report_succ = false; /*placeholder*/ - if (OB_TMP_FAIL(MTL(ObTenantTabletStatMgr *)->report_stat(context.store_ctx_->tablet_stat_, report_succ))) { - LOG_WARN("failed to report tablet stat", K(tmp_ret), K(stat)); + } else { + const compaction::ObBasicMergeScheduler *scheduler = nullptr; + if (OB_NOT_NULL(scheduler = ObBasicMergeScheduler::get_merge_scheduler()) && scheduler->enable_adaptive_compaction()) { + bool report_succ = false; /*placeholder*/ + if (OB_TMP_FAIL(MTL(ObTenantTabletStatMgr *)->report_stat(context.store_ctx_->tablet_stat_, report_succ))) { + LOG_WARN("failed to report tablet stat", K(tmp_ret), K(stat)); + } } } } @@ -4689,10 +4692,13 @@ int ObTablet::do_rowkeys_exist( int tmp_ret = OB_SUCCESS; if (0 == access_ctx.table_store_stat_.empty_read_cnt_) { // ROWKEY IN_ROW_CACHE / NOT EXIST - } else if (ObBasicMergeScheduler::get_merge_scheduler()->enable_adaptive_compaction()) { - bool report_succ = false; /*placeholder*/ - if (OB_TMP_FAIL(MTL(ObTenantTabletStatMgr *)->report_stat(tablet_stat, report_succ))) { - LOG_WARN("failed to report tablet stat", K(tmp_ret), K(tablet_stat)); + } else { + const compaction::ObBasicMergeScheduler *scheduler = nullptr; + if (OB_NOT_NULL(scheduler = ObBasicMergeScheduler::get_merge_scheduler()) && scheduler->enable_adaptive_compaction()) { + bool report_succ = false; /*placeholder*/ + if (OB_TMP_FAIL(MTL(ObTenantTabletStatMgr *)->report_stat(tablet_stat, report_succ))) { + LOG_WARN("failed to report tablet stat", K(tmp_ret), K(tablet_stat)); + } } } }