diff --git a/src/storage/column_store/ob_co_merge_ctx.h b/src/storage/column_store/ob_co_merge_ctx.h index a03b7af0e..79abfc023 100644 --- a/src/storage/column_store/ob_co_merge_ctx.h +++ b/src/storage/column_store/ob_co_merge_ctx.h @@ -104,6 +104,8 @@ struct ObCOTabletMergeCtx : public ObBasicTabletMergeCtx int inner_loop_prepare_index_tree( const uint32_t start_cg_idx, const uint32_t end_cg_idx); + virtual int try_swap_tablet(ObGetMergeTablesResult &get_merge_table_result) override + { return ObBasicTabletMergeCtx::swap_tablet(get_merge_table_result); } INHERIT_TO_STRING_KV("ObCOTabletMergeCtx", ObBasicTabletMergeCtx, K_(array_count), K_(exe_stat)); diff --git a/src/storage/compaction/ob_basic_tablet_merge_ctx.cpp b/src/storage/compaction/ob_basic_tablet_merge_ctx.cpp index c296f338c..fec0643d4 100644 --- a/src/storage/compaction/ob_basic_tablet_merge_ctx.cpp +++ b/src/storage/compaction/ob_basic_tablet_merge_ctx.cpp @@ -992,5 +992,39 @@ int ObBasicTabletMergeCtx::get_medium_compaction_info() return ret; } +int ObBasicTabletMergeCtx::swap_tablet(ObGetMergeTablesResult &get_merge_table_result) +{ + int ret = OB_SUCCESS; + // check need swap tablet when compaction + if (OB_UNLIKELY(!is_major_or_meta_merge_type(get_merge_type()))) { + ret = OB_NOT_SUPPORTED; + LOG_WARN("other merge type not support swap tablet", KR(ret), "param", get_dag_param()); + } else if (OB_UNLIKELY(!get_tablet()->get_tablet_meta().ha_status_.is_data_status_complete())) { + ret = OB_STATE_NOT_MATCH; + LOG_WARN("ha status is not allowed major", KR(ret), KPC(this)); + } else { + ObTablesHandleArray &tables_handle = get_merge_table_result.handle_; + int64_t row_count = 0; + int64_t macro_count = 0; + const ObSSTable *sstable = nullptr; + for (int64_t i = 0; i < tables_handle.get_count(); ++i) { + sstable = static_cast(tables_handle.get_table(i)); + row_count += sstable->get_row_count(); + macro_count += sstable->get_data_macro_block_count(); + } // end of for + if (need_swap_tablet(*get_tablet(), row_count, macro_count)) { + tables_handle.reset(); // clear tables array + if (OB_FAIL(swap_tablet())) { + LOG_WARN("failed to get alloc tablet handle", KR(ret)); + } else if (OB_FAIL(get_merge_tables(get_merge_table_result))) { + if (OB_NO_NEED_MERGE != ret) { + LOG_WARN("failed to get merge tables", KR(ret), KPC(this)); + } + } + } + } + return ret; +} + } // namespace compaction } // namespace oceanbase diff --git a/src/storage/compaction/ob_basic_tablet_merge_ctx.h b/src/storage/compaction/ob_basic_tablet_merge_ctx.h index 72060d0db..6cfd0da35 100644 --- a/src/storage/compaction/ob_basic_tablet_merge_ctx.h +++ b/src/storage/compaction/ob_basic_tablet_merge_ctx.h @@ -234,6 +234,7 @@ protected: virtual int collect_running_info() = 0; int swap_tablet(); int get_medium_compaction_info(); // for major + int swap_tablet(ObGetMergeTablesResult &get_merge_table_result); // for major static const int64_t LARGE_VOLUME_DATA_ROW_COUNT_THREASHOLD = 1000L * 1000L; // 100w static const int64_t LARGE_VOLUME_DATA_MACRO_COUNT_THREASHOLD = 300L; public: diff --git a/src/storage/compaction/ob_tablet_merge_ctx.cpp b/src/storage/compaction/ob_tablet_merge_ctx.cpp index 0db3228a1..1431763d2 100755 --- a/src/storage/compaction/ob_tablet_merge_ctx.cpp +++ b/src/storage/compaction/ob_tablet_merge_ctx.cpp @@ -423,40 +423,5 @@ int ObTabletMajorMergeCtx::prepare_schema() return ret; } -int ObTabletMajorMergeCtx::try_swap_tablet( - ObGetMergeTablesResult &get_merge_table_result) -{ - int ret = OB_SUCCESS; - // check need swap tablet when compaction - if (OB_UNLIKELY(!is_major_or_meta_merge_type(get_merge_type()))) { - ret = OB_NOT_SUPPORTED; - LOG_WARN("other merge type not support swap tablet", KR(ret), "param", get_dag_param()); - } else if (OB_UNLIKELY(!get_tablet()->get_tablet_meta().ha_status_.is_data_status_complete())) { - ret = OB_STATE_NOT_MATCH; - LOG_WARN("ha status is not allowed major", KR(ret), KPC(this)); - } else { - ObTablesHandleArray &tables_handle = get_merge_table_result.handle_; - int64_t row_count = 0; - int64_t macro_count = 0; - const ObSSTable *sstable = nullptr; - for (int64_t i = 0; i < tables_handle.get_count(); ++i) { - sstable = static_cast(tables_handle.get_table(i)); - row_count += sstable->get_row_count(); - macro_count += sstable->get_data_macro_block_count(); - } // end of for - if (need_swap_tablet(*get_tablet(), row_count, macro_count)) { - tables_handle.reset(); // clear tables array - if (OB_FAIL(swap_tablet())) { - LOG_WARN("failed to get alloc tablet handle", KR(ret)); - } else if (OB_FAIL(get_merge_tables(get_merge_table_result))) { - if (OB_NO_NEED_MERGE != ret) { - LOG_WARN("failed to get merge tables", KR(ret), KPC(this)); - } - } - } - } - return ret; -} - } // namespace compaction } // namespace oceanbase diff --git a/src/storage/compaction/ob_tablet_merge_ctx.h b/src/storage/compaction/ob_tablet_merge_ctx.h index 41898b85a..6c1ab8d33 100755 --- a/src/storage/compaction/ob_tablet_merge_ctx.h +++ b/src/storage/compaction/ob_tablet_merge_ctx.h @@ -92,7 +92,8 @@ struct ObTabletMajorMergeCtx : public ObTabletMergeCtx DEFAULT_CONSTRUCTOR(ObTabletMajorMergeCtx, ObTabletMergeCtx); protected: virtual int prepare_schema() override; - virtual int try_swap_tablet(ObGetMergeTablesResult &get_merge_table_result) override; + virtual int try_swap_tablet(ObGetMergeTablesResult &get_merge_table_result) override + { return ObBasicTabletMergeCtx::swap_tablet(get_merge_table_result); } virtual int cal_merge_param() override { return static_param_.cal_major_merge_param(); } };