From b4fdd7e0153ad380d25b6fa7b409b0909630753b Mon Sep 17 00:00:00 2001 From: oceanoverflow Date: Wed, 7 Feb 2024 09:20:10 +0000 Subject: [PATCH] [CP] add macro block count statistic for backup data --- .../backup/ob_backup_data_set_task_mgr.cpp | 3 - .../backup/ob_backup_data_table_operator.cpp | 23 +- .../backup/ob_backup_data_table_operator.h | 2 +- src/share/backup/ob_backup_struct.cpp | 25 ++- src/share/backup/ob_backup_struct.h | 2 +- .../ob_inner_table_schema.21151_21200.cpp | 2 +- .../inner_table/ob_inner_table_schema_def.py | 7 +- src/storage/backup/ob_backup_task.cpp | 208 ++++++++++++++---- src/storage/backup/ob_backup_task.h | 9 +- .../high_availability/ob_storage_ha_utils.cpp | 39 ++++ .../high_availability/ob_storage_ha_utils.h | 3 + src/storage/ls/ob_ls_tablet_service.cpp | 2 +- src/storage/ls/ob_ls_tablet_service.h | 2 +- src/storage/ob_storage_rpc.cpp | 3 +- .../r/mysql/desc_sys_views_in_sys.result | 1 + 15 files changed, 266 insertions(+), 65 deletions(-) diff --git a/src/rootserver/backup/ob_backup_data_set_task_mgr.cpp b/src/rootserver/backup/ob_backup_data_set_task_mgr.cpp index e3178d9ffe..39201dd4b4 100644 --- a/src/rootserver/backup/ob_backup_data_set_task_mgr.cpp +++ b/src/rootserver/backup/ob_backup_data_set_task_mgr.cpp @@ -1120,9 +1120,6 @@ int ObBackupSetTaskMgr::do_backup_data_( set_task_attr_.stats_.cum_with(ls_attr.stats_); } } - if (OB_SUCC(ret) && OB_FAIL(ObBackupTaskOperator::update_stats(*sql_proxy_, set_task_attr_.task_id_, set_task_attr_.tenant_id_, set_task_attr_.stats_))) { - LOG_WARN("[DATA_BACKUP]failed update statistic infomation", K(ret), K(set_task_attr_)); - } } return ret; } diff --git a/src/share/backup/ob_backup_data_table_operator.cpp b/src/share/backup/ob_backup_data_table_operator.cpp index 310efa49a6..4be161e4a1 100644 --- a/src/share/backup/ob_backup_data_table_operator.cpp +++ b/src/share/backup/ob_backup_data_table_operator.cpp @@ -1461,6 +1461,13 @@ int ObBackupTaskOperator::move_task_to_his( if (tenant_id == OB_INVALID_TENANT_ID || job_id <= 0) { ret = OB_INVALID_ARGUMENT; LOG_WARN("[DATA_BACKUP]invalid argument", K(ret), K(tenant_id), K(job_id)); + } else if (OB_FAIL(sql.assign_fmt( + "update %s set macro_block_count = finish_macro_block_count, tablet_count = finish_tablet_count", + OB_ALL_BACKUP_TASK_TNAME))) { + LOG_WARN("[DATA_BACKUP]failed to init sql", K(ret)); + } else if (OB_FAIL(proxy.write(get_exec_tenant_id(tenant_id), sql.ptr(), affected_rows))) { + LOG_WARN("[DATA_BACKUP]failed to exec sql", K(ret), K(sql)); + } else if (OB_FALSE_IT(sql.reset())) { } else if (OB_FAIL(sql.assign_fmt( "insert into %s select * from %s where %s=%lu and %s=%lu", OB_ALL_BACKUP_TASK_HISTORY_TNAME, OB_ALL_BACKUP_TASK_TNAME, @@ -2047,7 +2054,7 @@ int ObBackupLSTaskOperator::update_dst_and_status( return ret; } -int ObBackupLSTaskOperator::update_stats_( +int ObBackupLSTaskOperator::update_stats( common::ObISQLClient &proxy, const int64_t task_id, const uint64_t tenant_id, @@ -2139,6 +2146,13 @@ int ObBackupLSTaskOperator::move_ls_to_his(common::ObISQLClient &proxy, const ui if (tenant_id == OB_INVALID_TENANT_ID || job_id <= 0) { ret = OB_INVALID_ARGUMENT; LOG_WARN("[DATA_BACKUP]invalid argument", K(ret), K(tenant_id), K(job_id)); + } else if (OB_FAIL(sql.assign_fmt( + "update %s set macro_block_count = finish_macro_block_count, tablet_count = finish_tablet_count", + OB_ALL_BACKUP_LS_TASK_TNAME))) { + LOG_WARN("[DATA_BACKUP]failed to init sql", K(ret)); + } else if (OB_FAIL(proxy.write(get_exec_tenant_id(tenant_id), sql.ptr(), affected_rows))) { + LOG_WARN("[DATA_BACKUP]failed to exec sql", K(ret), K(sql)); + } else if (OB_FALSE_IT(sql.reset())) { } else if (OB_FAIL(sql.assign_fmt( "insert into %s select * from %s where %s=%lu", OB_ALL_BACKUP_LS_TASK_HISTORY_TNAME, OB_ALL_BACKUP_LS_TASK_TNAME, @@ -2520,6 +2534,13 @@ int ObBackupLSTaskInfoOperator::move_ls_task_info_to_his( if (tenant_id == OB_INVALID_TENANT_ID || task_id <= 0) { ret = OB_INVALID_ARGUMENT; LOG_WARN("[DATA_BACKUP]invalid argument", K(ret), K(tenant_id), K(task_id)); + } else if (OB_FAIL(sql.assign_fmt( + "update %s set macro_block_count = finish_macro_block_count, tablet_count = finish_tablet_count", + OB_ALL_BACKUP_LS_TASK_INFO_TNAME))) { + LOG_WARN("[DATA_BACKUP]failed to init sql", K(ret)); + } else if (OB_FAIL(proxy.write(get_exec_tenant_id(tenant_id), sql.ptr(), affected_rows))) { + LOG_WARN("[DATA_BACKUP]failed to exec sql", K(ret), K(sql)); + } else if (OB_FALSE_IT(sql.reset())) { } else if (OB_FAIL(sql.assign_fmt( "insert into %s select * from %s where %s=%lu and %s=%lu", OB_ALL_BACKUP_LS_TASK_INFO_HISTORY_TNAME, OB_ALL_BACKUP_LS_TASK_INFO_TNAME, diff --git a/src/share/backup/ob_backup_data_table_operator.h b/src/share/backup/ob_backup_data_table_operator.h index fb308208dd..b910a31edc 100644 --- a/src/share/backup/ob_backup_data_table_operator.h +++ b/src/share/backup/ob_backup_data_table_operator.h @@ -157,7 +157,7 @@ public: static int delete_build_index_task(common::ObISQLClient &proxy, const ObBackupLSTaskAttr &build_index_attr); static int move_ls_to_his(common::ObISQLClient &proxy, const uint64_t tenant_id, const int64_t job_id); static int delete_ls_task_without_sys(common::ObISQLClient &proxy, const uint64_t tenant_id, const int64_t task_id); - static int update_stats_(common::ObISQLClient &proxy, const int64_t task_id, const uint64_t tenant_id, + static int update_stats(common::ObISQLClient &proxy, const int64_t task_id, const uint64_t tenant_id, const ObLSID &ls_id, const ObBackupStats &stats); static int update_max_tablet_checkpoint_scn(common::ObISQLClient &proxy, const int64_t task_id, const uint64_t tenant_id, const ObLSID &ls_id, const SCN &max_tablet_checkpoint_scn); diff --git a/src/share/backup/ob_backup_struct.cpp b/src/share/backup/ob_backup_struct.cpp index 58a1d89e6f..8c225b6cd8 100644 --- a/src/share/backup/ob_backup_struct.cpp +++ b/src/share/backup/ob_backup_struct.cpp @@ -3058,16 +3058,23 @@ bool ObBackupStats::is_valid() const && finish_file_count_ >= 0; } -void ObBackupStats::assign(const ObBackupStats &other) +int ObBackupStats::assign(const ObBackupStats &other) { - input_bytes_ = other.input_bytes_; - output_bytes_ = other.output_bytes_; - tablet_count_ = other.tablet_count_; - finish_tablet_count_ = other.finish_tablet_count_; - macro_block_count_ = other.macro_block_count_; - finish_macro_block_count_ = other.finish_macro_block_count_; - extra_bytes_ = other.extra_bytes_; - finish_file_count_ = other.finish_file_count_; + int ret = OB_SUCCESS; + if (!other.is_valid()) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("get invalid arg", K(ret), K(other)); + } else { + input_bytes_ = other.input_bytes_; + output_bytes_ = other.output_bytes_; + tablet_count_ = other.tablet_count_; + finish_tablet_count_ = other.finish_tablet_count_; + macro_block_count_ = other.macro_block_count_; + finish_macro_block_count_ = other.finish_macro_block_count_; + extra_bytes_ = other.extra_bytes_; + finish_file_count_ = other.finish_file_count_; + } + return ret; } void ObBackupStats::cum_with(const ObBackupStats &other) diff --git a/src/share/backup/ob_backup_struct.h b/src/share/backup/ob_backup_struct.h index 2c28f46b6f..bf50941ecc 100644 --- a/src/share/backup/ob_backup_struct.h +++ b/src/share/backup/ob_backup_struct.h @@ -1290,7 +1290,7 @@ public: ObBackupStats(); ~ObBackupStats() {} bool is_valid() const; - void assign(const ObBackupStats &other); + int assign(const ObBackupStats &other); void cum_with(const ObBackupStats &other); void reset(); TO_STRING_KV(K_(input_bytes), K_(output_bytes), K_(tablet_count), K_(finish_tablet_count), diff --git a/src/share/inner_table/ob_inner_table_schema.21151_21200.cpp b/src/share/inner_table/ob_inner_table_schema.21151_21200.cpp index af3f384e06..0162df19ac 100644 --- a/src/share/inner_table/ob_inner_table_schema.21151_21200.cpp +++ b/src/share/inner_table/ob_inner_table_schema.21151_21200.cpp @@ -260,7 +260,7 @@ int ObInnerTableSchema::cdb_ob_backup_tasks_schema(ObTableSchema &table_schema) table_schema.set_collation_type(ObCharset::get_default_collation(ObCharset::get_default_charset())); if (OB_SUCC(ret)) { - if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT TENANT_ID, TASK_ID, JOB_ID, INCARNATION, BACKUP_SET_ID, USEC_TO_TIME(START_TS) AS START_TIMESTAMP, CASE WHEN END_TS = 0 THEN NULL ELSE USEC_TO_TIME(END_TS) END AS END_TIMESTAMP, STATUS, START_SCN, END_SCN, USER_LS_START_SCN, ENCRYPTION_MODE, PASSWD, INPUT_BYTES, OUTPUT_BYTES, CASE WHEN END_TS = 0 THEN 0 ELSE OUTPUT_BYTES / ((END_TS - START_TS)/1000/1000) END AS OUTPUT_RATE_BYTES, EXTRA_BYTES AS EXTRA_META_BYTES, TABLET_COUNT, FINISH_TABLET_COUNT, MACRO_BLOCK_COUNT, FINISH_MACRO_BLOCK_COUNT, FILE_COUNT, META_TURN_ID, DATA_TURN_ID, RESULT, COMMENT, PATH, MINOR_TURN_ID, MAJOR_TURN_ID FROM OCEANBASE.__all_virtual_backup_task )__"))) { + if (OB_FAIL(table_schema.set_view_definition(R"__( SELECT TENANT_ID, TASK_ID, JOB_ID, INCARNATION, BACKUP_SET_ID, USEC_TO_TIME(START_TS) AS START_TIMESTAMP, CASE WHEN END_TS = 0 THEN NULL ELSE USEC_TO_TIME(END_TS) END AS END_TIMESTAMP, STATUS, START_SCN, END_SCN, USER_LS_START_SCN, ENCRYPTION_MODE, PASSWD, INPUT_BYTES, OUTPUT_BYTES, CASE WHEN END_TS = 0 THEN 0 ELSE OUTPUT_BYTES / ((END_TS - START_TS)/1000/1000) END AS OUTPUT_RATE_BYTES, EXTRA_BYTES AS EXTRA_META_BYTES, TABLET_COUNT, FINISH_TABLET_COUNT, MACRO_BLOCK_COUNT, FINISH_MACRO_BLOCK_COUNT, FILE_COUNT, META_TURN_ID, DATA_TURN_ID, RESULT, COMMENT, PATH, MINOR_TURN_ID, MAJOR_TURN_ID, CASE WHEN MACRO_BLOCK_COUNT = 0 THEN 0.00 WHEN FINISH_MACRO_BLOCK_COUNT > MACRO_BLOCK_COUNT THEN 99.99 ELSE ROUND((FINISH_MACRO_BLOCK_COUNT / MACRO_BLOCK_COUNT) * 100, 2) END AS DATA_PROGRESS FROM OCEANBASE.__all_virtual_backup_task )__"))) { LOG_ERROR("fail to set view_definition", K(ret)); } } diff --git a/src/share/inner_table/ob_inner_table_schema_def.py b/src/share/inner_table/ob_inner_table_schema_def.py index e367e7fe6b..f5bc0f34e6 100644 --- a/src/share/inner_table/ob_inner_table_schema_def.py +++ b/src/share/inner_table/ob_inner_table_schema_def.py @@ -17279,7 +17279,12 @@ def_table_schema( COMMENT, PATH, MINOR_TURN_ID, - MAJOR_TURN_ID + MAJOR_TURN_ID, + CASE + WHEN MACRO_BLOCK_COUNT = 0 THEN 0.00 + WHEN FINISH_MACRO_BLOCK_COUNT > MACRO_BLOCK_COUNT THEN 99.99 + ELSE ROUND((FINISH_MACRO_BLOCK_COUNT / MACRO_BLOCK_COUNT) * 100, 2) + END AS DATA_PROGRESS FROM OCEANBASE.__all_virtual_backup_task """.replace("\n", " ") ) diff --git a/src/storage/backup/ob_backup_task.cpp b/src/storage/backup/ob_backup_task.cpp index 20259efa02..0c9a942348 100644 --- a/src/storage/backup/ob_backup_task.cpp +++ b/src/storage/backup/ob_backup_task.cpp @@ -48,6 +48,7 @@ #include "share/backup/ob_backup_connectivity.h" #include "share/rc/ob_tenant_base.h" #include "observer/omt/ob_tenant.h" +#include "storage/high_availability/ob_storage_ha_utils.h" #include #include "storage/column_store/ob_column_oriented_sstable.h" @@ -2870,45 +2871,47 @@ int ObLSBackupDataTask::report_ls_backup_task_info_(const ObLSBackupStat &stat) ObMySQLTransaction trans; int64_t max_file_id = 0; const bool for_update = true; - ObBackupLSTaskInfo ls_task_info; if (OB_FAIL(trans.start(report_ctx_.sql_proxy_, gen_meta_tenant_id(param_.tenant_id_)))) { LOG_WARN("failed to start transaction", K(ret), K(param_)); } else { - ObLSBackupStat new_stat; - share::ObBackupStats new_task_stat; - share::ObBackupLSTaskAttr ls_task_attr; - if (OB_FAIL(share::ObBackupLSTaskOperator::get_ls_task(trans, for_update, - param_.job_desc_.task_id_, param_.tenant_id_, param_.ls_id_, ls_task_attr))) { - LOG_WARN("failed to get ls task", K(ret), K_(param)); - } else if (OB_FAIL(ObLSBackupOperator::get_backup_ls_task_info(param_.tenant_id_, - param_.job_desc_.task_id_, - param_.ls_id_, - param_.turn_id_, - param_.retry_id_, - param_.backup_data_type_, - for_update, - ls_task_info, - trans))) { + const int64_t job_id = param_.job_desc_.job_id_; + const int64_t task_id = param_.job_desc_.task_id_; + const uint64_t tenant_id = param_.tenant_id_; + const share::ObLSID &ls_id = param_.ls_id_; + const int64_t turn_id = param_.turn_id_; + const int64_t retry_id = param_.retry_id_; + const share::ObBackupDataType &backup_data_type = param_.backup_data_type_; + share::ObBackupSetTaskAttr old_set_task_attr; + share::ObBackupLSTaskAttr old_ls_task_attr; + ObBackupLSTaskInfo old_ls_task_info; + ObLSBackupStat new_ls_task_info_stat; + share::ObBackupStats new_ls_task_stat; + share::ObBackupStats new_backup_set_stats; + if (OB_FAIL(ObBackupTaskOperator::get_backup_task(trans, job_id, tenant_id, for_update, old_set_task_attr))) { + LOG_WARN("failed to get backup task", K(ret), K_(param)); + } else if (OB_FAIL(ObBackupLSTaskOperator::get_ls_task(trans, for_update, + task_id, tenant_id, ls_id, old_ls_task_attr))) { + LOG_WARN("failed to get ls task", K(ret), K_(param)); + } else if (OB_FAIL(ObLSBackupOperator::get_backup_ls_task_info(tenant_id, + task_id, ls_id, turn_id, retry_id, backup_data_type, for_update, old_ls_task_info, trans))) { LOG_WARN("failed to get backup ls task info", K(ret), K(param_)); - } else if (ls_task_info.is_final_) { - LOG_INFO("can not update if final", K(ls_task_info), K(stat)); - } else if (ls_task_info.max_file_id_ + 1 != stat.file_id_) { - LOG_INFO("can not update if file id is not consecutive", K(ls_task_info), K(stat)); - } else if (OB_FAIL(update_task_stat_(ls_task_attr.stats_, stat, new_task_stat))) { - LOG_WARN("failed to update task stat", K(ret), K(ls_task_attr)); - } else if (OB_FAIL(update_task_info_stat_(ls_task_info, stat, new_stat))) { - LOG_WARN("failed to update task info stat", K(ret), K(ls_task_info), K(stat)); - } else if (OB_FAIL(share::ObBackupLSTaskOperator::update_stats_(trans, param_.job_desc_.task_id_, - param_.tenant_id_, param_.ls_id_, new_task_stat))) { + } else if (old_ls_task_info.is_final_) { + LOG_INFO("can not update if final", K(old_ls_task_info), K(stat)); + } else if (old_ls_task_info.max_file_id_ + 1 != stat.file_id_) { + LOG_INFO("can not update if file id is not consecutive", K(old_ls_task_info), K(stat)); + } else if (OB_FAIL(update_task_stat_(old_set_task_attr.stats_, stat, new_backup_set_stats))) { + LOG_WARN("failed to update task stat", K(ret)); + } else if (OB_FAIL(update_ls_task_stat_(old_ls_task_attr.stats_, stat, new_ls_task_stat))) { + LOG_WARN("failed to update ls task stat", K(ret), K(old_ls_task_attr)); + } else if (OB_FAIL(update_ls_task_info_stat_(old_ls_task_info, stat, new_ls_task_info_stat))) { + LOG_WARN("failed to update ls task info stat", K(ret), K(old_ls_task_info), K(stat)); + } else if (OB_FAIL(ObBackupLSTaskOperator::update_stats(trans, task_id, tenant_id, ls_id, new_ls_task_stat))) { LOG_WARN("failed to update stat", K(ret), K(param_)); - } else if (OB_FAIL(ObLSBackupOperator::report_ls_backup_task_info(param_.tenant_id_, - param_.job_desc_.task_id_, - param_.turn_id_, - param_.retry_id_, - backup_data_type_, - new_stat, - trans))) { - LOG_WARN("failed to report single task info", K_(param), K_(backup_data_type), K(new_stat)); + } else if (OB_FAIL(ObLSBackupOperator::report_ls_backup_task_info(tenant_id, + task_id, turn_id, retry_id, backup_data_type, new_ls_task_info_stat, trans))) { + LOG_WARN("failed to report single task info", K_(param), K_(backup_data_type), K(new_ls_task_info_stat)); + } else if (OB_FAIL(ObBackupTaskOperator::update_stats(trans, task_id, tenant_id, new_backup_set_stats))) { + LOG_WARN("failed to update stats", K(ret), K(task_id), K(tenant_id)); } if (OB_SUCC(ret)) { if (OB_FAIL(trans.end(true /*commit*/))) { @@ -2923,26 +2926,58 @@ int ObLSBackupDataTask::report_ls_backup_task_info_(const ObLSBackupStat &stat) return ret; } -// TODO(yangyi.yyy): make tablet count accurate int ObLSBackupDataTask::update_task_stat_(const share::ObBackupStats &old_backup_stat, const ObLSBackupStat &ls_stat, share::ObBackupStats &new_backup_stat) { int ret = OB_SUCCESS; new_backup_stat.input_bytes_ = old_backup_stat.input_bytes_ + ls_stat.input_bytes_; new_backup_stat.output_bytes_ = old_backup_stat.output_bytes_ + ls_stat.output_bytes_; - new_backup_stat.macro_block_count_ = old_backup_stat.macro_block_count_ + ls_stat.finish_macro_block_count_; + new_backup_stat.macro_block_count_ = old_backup_stat.macro_block_count_; + new_backup_stat.tablet_count_ = old_backup_stat.tablet_count_; new_backup_stat.finish_macro_block_count_ = old_backup_stat.finish_macro_block_count_ + ls_stat.finish_macro_block_count_; - if (backup_data_type_.is_minor_backup() || backup_data_type_.is_sys_backup()) { - new_backup_stat.tablet_count_ = old_backup_stat.tablet_count_ + ls_stat.finish_tablet_count_; - new_backup_stat.finish_tablet_count_ = old_backup_stat.finish_tablet_count_ + ls_stat.finish_tablet_count_; - } else { - new_backup_stat.tablet_count_ = old_backup_stat.tablet_count_; + if (backup_data_type_.is_minor_backup()) { new_backup_stat.finish_tablet_count_ = old_backup_stat.finish_tablet_count_; + } else { + new_backup_stat.finish_tablet_count_ = old_backup_stat.finish_tablet_count_ + ls_stat.finish_tablet_count_; + } + // calibrate tablet_count and macro_block_count + if (new_backup_stat.finish_macro_block_count_ > new_backup_stat.macro_block_count_) { + LOG_INFO("calibrate macro block count", "old_macro_block_count", new_backup_stat.macro_block_count_, + "new_macro_block_count", new_backup_stat.finish_macro_block_count_); + new_backup_stat.macro_block_count_ = new_backup_stat.finish_macro_block_count_; + } + if (new_backup_stat.finish_tablet_count_ > new_backup_stat.tablet_count_) { + LOG_INFO("calibrate tablet count", "old_tablet_count", new_backup_stat.tablet_count_, + "new_tablet_count", new_backup_stat.finish_tablet_count_); + new_backup_stat.tablet_count_ = new_backup_stat.finish_tablet_count_; } return ret; } -int ObLSBackupDataTask::update_task_info_stat_( +int ObLSBackupDataTask::update_ls_task_stat_(const share::ObBackupStats &old_backup_stat, const ObLSBackupStat &ls_stat, + share::ObBackupStats &new_backup_stat) +{ + int ret = OB_SUCCESS; + new_backup_stat.input_bytes_ = old_backup_stat.input_bytes_ + ls_stat.input_bytes_; + new_backup_stat.output_bytes_ = old_backup_stat.output_bytes_ + ls_stat.output_bytes_; + new_backup_stat.tablet_count_ = old_backup_stat.tablet_count_; + new_backup_stat.macro_block_count_ = old_backup_stat.macro_block_count_; + new_backup_stat.finish_macro_block_count_ = old_backup_stat.finish_macro_block_count_ + ls_stat.finish_macro_block_count_; + if (backup_data_type_.is_minor_backup()) { + new_backup_stat.finish_tablet_count_ = old_backup_stat.finish_tablet_count_; + } else { + new_backup_stat.finish_tablet_count_ = old_backup_stat.finish_tablet_count_ + ls_stat.finish_tablet_count_; + } + // calibrate tablet_count and macro_block_count + if (new_backup_stat.finish_macro_block_count_ > new_backup_stat.macro_block_count_) { + LOG_INFO("calibrate macro block count", "old_macro_block_count", new_backup_stat.macro_block_count_, + "new_macro_block_count", new_backup_stat.finish_macro_block_count_); + new_backup_stat.macro_block_count_ = new_backup_stat.finish_macro_block_count_; + } + return ret; +} + +int ObLSBackupDataTask::update_ls_task_info_stat_( const ObBackupLSTaskInfo &task_info, const ObLSBackupStat &stat, ObLSBackupStat &new_stat) { int ret = OB_SUCCESS; @@ -3620,6 +3655,8 @@ int ObLSBackupMetaTask::backup_ls_meta_and_tablet_metas_(const uint64_t tenant_i ObExternTabletMetaWriter writer; ObBackupDest backup_set_dest; int64_t backup_tablet_count = 0; + int64_t backup_macro_block_count = 0; + int64_t calc_macro_block_count_time = 0; // save max tablet checkpoint scn of all the tablets belong to the same ls. SCN max_tablet_checkpoint_scn; @@ -3639,10 +3676,13 @@ int ObLSBackupMetaTask::backup_ls_meta_and_tablet_metas_(const uint64_t tenant_i }; // persist tablet meta - auto backup_tablet_meta_f = [&writer, &backup_tablet_count, &max_tablet_checkpoint_scn](const obrpc::ObCopyTabletInfo &tablet_info)->int { + auto backup_tablet_meta_f = [&writer, &backup_tablet_count, &max_tablet_checkpoint_scn, &backup_macro_block_count, &calc_macro_block_count_time] + (const obrpc::ObCopyTabletInfo &tablet_info, const ObTabletHandle &tablet_handle)->int { int ret = OB_SUCCESS; blocksstable::ObSelfBufferWriter buffer_writer("LSBackupMetaTask"); blocksstable::ObBufferReader buffer_reader; + int64_t macro_block_count = 0; + int64_t start_time = 0; if (!tablet_info.is_valid()) { ret = OB_INVALID_ARGUMENT; LOG_WARN("tablet meta is invalid", K(ret), K(tablet_info)); @@ -3650,12 +3690,17 @@ int ObLSBackupMetaTask::backup_ls_meta_and_tablet_metas_(const uint64_t tenant_i LOG_WARN("failed to ensure space"); } else if (OB_FAIL(buffer_writer.write_serialize(tablet_info.param_))) { LOG_WARN("failed to writer", K(tablet_info)); + } else if (FALSE_IT(start_time = ObTimeUtility::current_time())) { + } else if (OB_FAIL(ObStorageHAUtils::calc_tablet_sstable_macro_block_cnt(tablet_handle, macro_block_count))) { + LOG_WARN("failed to calc tablet sstable macro block count", K(ret), K(tablet_handle)); + } else if (FALSE_IT(calc_macro_block_count_time += ObTimeUtility::current_time() - start_time)) { } else { buffer_reader.assign(buffer_writer.data(), buffer_writer.length(), buffer_writer.length()); if (OB_FAIL(writer.write_meta_data(buffer_reader, tablet_info.param_.tablet_id_))) { LOG_WARN("failed to write meta data", K(ret), K(tablet_info)); } else { max_tablet_checkpoint_scn = MAX(max_tablet_checkpoint_scn, tablet_info.param_.get_max_tablet_checkpoint_scn()); + backup_macro_block_count += macro_block_count; LOG_INFO("succeed backup tablet meta", "meta", tablet_info.param_); } } @@ -3712,7 +3757,9 @@ int ObLSBackupMetaTask::backup_ls_meta_and_tablet_metas_(const uint64_t tenant_i } } else { cost_ts = ObTimeUtility::current_time() - wait_gc_lock_start_ts; - LOG_INFO("succeed to get ls meta package and tablet meta", K(ls_id), K(cost_ts)); + LOG_INFO("succeed to get ls meta package and tablet meta", K(ls_id), K(cost_ts), K(backup_macro_block_count), + K(calc_macro_block_count_time), + "calc_macro_block_time_ratio", calc_macro_block_count_time * 100.0 / cost_ts); } } while (OB_TABLET_GC_LOCK_CONFLICT == ret); @@ -3726,6 +3773,8 @@ int ObLSBackupMetaTask::backup_ls_meta_and_tablet_metas_(const uint64_t tenant_i param_.ls_id_, max_tablet_checkpoint_scn))) { LOG_WARN("failed to update max tablet checkpoint scn", K(ret), K(param_), K(max_tablet_checkpoint_scn)); + } else if (OB_FAIL(report_backup_stat_(backup_tablet_count, backup_macro_block_count))) { + LOG_WARN("failed to report backup stat", K(ret)); } else { LOG_INFO("succeed backup ls meta and all tablet metas", K(ls_id), K(ls_meta_info), K(backup_tablet_count), K(max_tablet_checkpoint_scn)); } @@ -3761,6 +3810,77 @@ int ObLSBackupMetaTask::backup_ls_meta_package_(const ObBackupLSMetaInfo &ls_met return ret; } +int ObLSBackupMetaTask::report_backup_stat_(const int64_t tablet_count, const int64_t macro_block_count) +{ + int ret = OB_SUCCESS; + int tmp_ret = OB_SUCCESS; + ObMySQLTransaction trans; + if (OB_FAIL(trans.start(report_ctx_.sql_proxy_, gen_meta_tenant_id(param_.tenant_id_)))) { + LOG_WARN("failed to start transaction", K(ret), K(param_)); + } else { + const int64_t job_id = param_.job_desc_.job_id_; + const int64_t task_id = param_.job_desc_.task_id_; + const uint64_t tenant_id = param_.tenant_id_; + const share::ObLSID &ls_id = param_.ls_id_; + const bool for_update = true; + share::ObBackupSetTaskAttr old_set_task_attr; + share::ObBackupLSTaskAttr old_ls_task_attr; + share::ObBackupStats new_backup_task_stats; + share::ObBackupStats new_ls_task_stats; + if (OB_FAIL(ObBackupTaskOperator::get_backup_task(trans, job_id, tenant_id, for_update, old_set_task_attr))) { + LOG_WARN("failed to get backup task", K(ret), K_(param)); + } else if (OB_FAIL(ObBackupLSTaskOperator::get_ls_task(trans, for_update, task_id, tenant_id, ls_id, old_ls_task_attr))) { + LOG_WARN("failed to get ls task", K(ret), K_(param)); + } else if (OB_FAIL(calc_backup_stat_(old_set_task_attr, tablet_count, macro_block_count, new_backup_task_stats))) { + LOG_WARN("failed to calc backup stat", K(ret), K(old_set_task_attr), K(tablet_count), K(macro_block_count)); + } else if (OB_FAIL(calc_ls_backup_stat_(old_ls_task_attr.stats_, tablet_count, macro_block_count, new_ls_task_stats))) { + LOG_WARN("failed to calc ls backup stat", K(ret), K_(param)); + } else if (OB_FAIL(ObBackupTaskOperator::update_stats(trans, task_id, tenant_id, new_backup_task_stats))) { + LOG_WARN("failed to update stats", K(ret), K_(param)); + } else if (OB_FAIL(ObBackupLSTaskOperator::update_stats(trans, task_id, tenant_id, ls_id, new_ls_task_stats))) { + LOG_WARN("failed to update stat", K(ret), K_(param)); + } + + if (OB_SUCC(ret)) { + if (OB_FAIL(trans.end(true /*commit*/))) { + LOG_WARN("failed to commit", K(ret)); + } + } else { + if (OB_TMP_FAIL(trans.end(false /* commit*/))) { + LOG_WARN("failed to rollback trans", K(tmp_ret)); + } + } + } + return ret; +} + +int ObLSBackupMetaTask::calc_backup_stat_(const ObBackupSetTaskAttr &set_task_attr, + const int64_t tablet_count, const int64_t macro_block_count, ObBackupStats &backup_stats) +{ + int ret = OB_SUCCESS; + const ObBackupStats &orig_stats = set_task_attr.stats_; + if (OB_FAIL(backup_stats.assign(orig_stats))) { + LOG_WARN("failed to assign backup stats", K(ret), K(orig_stats)); + } else { + backup_stats.tablet_count_ += tablet_count; + backup_stats.macro_block_count_ += macro_block_count; + } + return ret; +} + +int ObLSBackupMetaTask::calc_ls_backup_stat_(const share::ObBackupStats &old_backup_stat, const int64_t tablet_count, + const int64_t macro_block_count, ObBackupStats &backup_stats) +{ + int ret = OB_SUCCESS; + if (OB_FAIL(backup_stats.assign(old_backup_stat))) { + LOG_WARN("failed to assign backup stats", K(ret), K(old_backup_stat)); + } else { + backup_stats.tablet_count_ = tablet_count; + backup_stats.macro_block_count_ = macro_block_count; + } + return ret; +} + /* ObLSBackupPrepareTask */ ObLSBackupPrepareTask::ObLSBackupPrepareTask() diff --git a/src/storage/backup/ob_backup_task.h b/src/storage/backup/ob_backup_task.h index 308987ccaa..32f9437341 100644 --- a/src/storage/backup/ob_backup_task.h +++ b/src/storage/backup/ob_backup_task.h @@ -411,6 +411,11 @@ private: int advance_checkpoint_by_flush_(const uint64_t tenant_id, const share::ObLSID &ls_id, const share::SCN &start_scn); int backup_ls_meta_and_tablet_metas_(const uint64_t tenant_id, const share::ObLSID &ls_id); int backup_ls_meta_package_(const ObBackupLSMetaInfo &ls_meta_info); + int report_backup_stat_(const int64_t tablet_count, const int64_t macro_block_count); + int calc_backup_stat_(const ObBackupSetTaskAttr &set_task_attr, + const int64_t tablet_count, const int64_t macro_block_count, ObBackupStats &backup_stats); + int calc_ls_backup_stat_(const share::ObBackupStats &old_backup_stat, const int64_t tablet_count, + const int64_t macro_block_count, ObBackupStats &backup_stats); private: bool is_inited_; @@ -531,7 +536,9 @@ private: int report_ls_backup_task_info_(const ObLSBackupStat &stat); int update_task_stat_(const share::ObBackupStats &old_backup_stat, const ObLSBackupStat &ls_stat, share::ObBackupStats &new_backup_stat); - int update_task_info_stat_(const ObBackupLSTaskInfo &task_info, const ObLSBackupStat &stat, ObLSBackupStat &new_stat); + int update_ls_task_stat_(const share::ObBackupStats &old_backup_stat, const ObLSBackupStat &ls_stat, + share::ObBackupStats &new_backup_stat); + int update_ls_task_info_stat_(const ObBackupLSTaskInfo &task_info, const ObLSBackupStat &stat, ObLSBackupStat &new_stat); int do_generate_next_task_(); int check_disk_space_(); int get_macro_block_id_list_(common::ObIArray &list); diff --git a/src/storage/high_availability/ob_storage_ha_utils.cpp b/src/storage/high_availability/ob_storage_ha_utils.cpp index 16b597a1bd..e1500c3896 100644 --- a/src/storage/high_availability/ob_storage_ha_utils.cpp +++ b/src/storage/high_availability/ob_storage_ha_utils.cpp @@ -15,6 +15,7 @@ #include "share/config/ob_server_config.h" #include "share/location_cache/ob_location_service.h" #include "share/ob_zone_merge_info.h" +#include "storage/tablet/ob_tablet.h" #include "share/tablet/ob_tablet_table_operator.h" #include "share/ob_global_merge_table_operator.h" #include "share/ob_tablet_replica_checksum_operator.h" @@ -343,6 +344,44 @@ int ObStorageHAUtils::check_disk_space() return ret; } +int ObStorageHAUtils::calc_tablet_sstable_macro_block_cnt( + const ObTabletHandle &tablet_handle, int64_t &data_macro_block_count) +{ + int ret = OB_SUCCESS; + data_macro_block_count = 0; + storage::ObTableStoreIterator table_store_iter; + if (OB_UNLIKELY(!tablet_handle.is_valid())) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("invalid tablet handle", K(ret), K(tablet_handle)); + } else if (OB_FAIL(tablet_handle.get_obj()->get_all_sstables(table_store_iter))) { + LOG_WARN("failed to get all tables", K(ret), K(tablet_handle)); + } else if (0 == table_store_iter.count()) { + // do nothing + } else { + ObITable *table_ptr = NULL; + while (OB_SUCC(ret)) { + table_ptr = NULL; + if (OB_FAIL(table_store_iter.get_next(table_ptr))) { + if (OB_ITER_END == ret) { + ret = OB_SUCCESS; + break; + } else { + LOG_WARN("failed to get next", K(ret)); + } + } else if (OB_ISNULL(table_ptr)) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("table should not be null", K(ret)); + } else if (!table_ptr->is_sstable()) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("table is not sstable", K(ret), KPC(table_ptr)); + } else { + data_macro_block_count += static_cast(table_ptr)->get_data_macro_block_count(); + } + } + } + return ret; +} + bool ObTransferUtils::is_need_retry_error(const int err) { bool bool_ret = false; diff --git a/src/storage/high_availability/ob_storage_ha_utils.h b/src/storage/high_availability/ob_storage_ha_utils.h index 33c3c57e40..e58ab2c6d7 100644 --- a/src/storage/high_availability/ob_storage_ha_utils.h +++ b/src/storage/high_availability/ob_storage_ha_utils.h @@ -47,6 +47,9 @@ public: static int check_is_primary_tenant(const uint64_t tenant_id, bool &is_primary_tenant); static int check_disk_space(); + static int calc_tablet_sstable_macro_block_cnt( + const ObTabletHandle &tablet_handle, int64_t &data_macro_block_count); + private: static int check_merge_error_(const uint64_t tenant_id, common::ObISQLClient &sql_client); static int fetch_src_tablet_meta_info_(const uint64_t tenant_id, const common::ObTabletID &tablet_id, diff --git a/src/storage/ls/ob_ls_tablet_service.cpp b/src/storage/ls/ob_ls_tablet_service.cpp index 2080df0363..d0194face4 100644 --- a/src/storage/ls/ob_ls_tablet_service.cpp +++ b/src/storage/ls/ob_ls_tablet_service.cpp @@ -6264,7 +6264,7 @@ int ObLSTabletService::ha_scan_all_tablets(const HandleTabletMetaFunc &handle_ta } else { tablet_info.tablet_id_ = tablet->get_tablet_meta().tablet_id_; tablet_info.status_ = ObCopyTabletStatus::TABLET_EXIST; - if (OB_FAIL(handle_tablet_meta_f(tablet_info))) { + if (OB_FAIL(handle_tablet_meta_f(tablet_info, tablet_handle))) { LOG_WARN("fail to handle tablet meta", K(ret), K(tablet_info)); } } diff --git a/src/storage/ls/ob_ls_tablet_service.h b/src/storage/ls/ob_ls_tablet_service.h index 93972f8405..8be56d5c35 100644 --- a/src/storage/ls/ob_ls_tablet_service.h +++ b/src/storage/ls/ob_ls_tablet_service.h @@ -415,7 +415,7 @@ public: int build_tablet_iter(ObLSTabletFastIter &iter, const bool except_ls_inner_tablet = false); // migration section - typedef common::ObFunction HandleTabletMetaFunc; + typedef common::ObFunction HandleTabletMetaFunc; int ha_scan_all_tablets(const HandleTabletMetaFunc &handle_tablet_meta_f); int trim_rebuild_tablet( const ObTabletID &tablet_id, diff --git a/src/storage/ob_storage_rpc.cpp b/src/storage/ob_storage_rpc.cpp index 9fd9c4dd1d..6ebb10e136 100644 --- a/src/storage/ob_storage_rpc.cpp +++ b/src/storage/ob_storage_rpc.cpp @@ -2992,7 +2992,8 @@ int ObStorageFetchLSViewP::process() return ret; }; - auto fill_tablet_meta_f = [this, &filled_tablet_count, &total_tablet_count](const obrpc::ObCopyTabletInfo &tablet_info)->int { + auto fill_tablet_meta_f = [this, &filled_tablet_count, &total_tablet_count] + (const obrpc::ObCopyTabletInfo &tablet_info, const ObTabletHandle &tablet_handle)->int { int ret = OB_SUCCESS; if (!tablet_info.is_valid()) { ret = OB_INVALID_ARGUMENT; diff --git a/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/desc_sys_views_in_sys.result b/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/desc_sys_views_in_sys.result index bee20fd2c4..5c0bc4cd11 100644 --- a/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/desc_sys_views_in_sys.result +++ b/tools/deploy/mysql_test/test_suite/inner_table/r/mysql/desc_sys_views_in_sys.result @@ -2117,6 +2117,7 @@ COMMENT varchar(4096) YES PATH varchar(4096) YES MINOR_TURN_ID bigint(20) NO MAJOR_TURN_ID bigint(20) NO +DATA_PROGRESS decimal(26,2) NO select /*+QUERY_TIMEOUT(60000000)*/ count(*) as cnt from (select * from oceanbase.CDB_OB_BACKUP_TASKS limit 1); cnt 1