From 0daeed471ed8d4e4d43e253781aaeeb2aac23712 Mon Sep 17 00:00:00 2001 From: obdev Date: Thu, 10 Oct 2024 08:31:59 +0000 Subject: [PATCH] Add reader type for copy finish task extra_info --- .../high_availability/ob_ls_migration.cpp | 2 +- .../high_availability/ob_ls_migration.h | 2 +- .../ob_physical_copy_ctx.cpp | 48 ++++++++++++++++++ .../high_availability/ob_physical_copy_ctx.h | 15 ++++-- .../ob_tablet_copy_finish_task.cpp | 49 +------------------ .../ob_tablet_group_restore.cpp | 2 +- .../ob_tablet_group_restore.h | 2 +- 7 files changed, 64 insertions(+), 56 deletions(-) diff --git a/src/storage/high_availability/ob_ls_migration.cpp b/src/storage/high_availability/ob_ls_migration.cpp index fb4d455ea..e3e116ef2 100644 --- a/src/storage/high_availability/ob_ls_migration.cpp +++ b/src/storage/high_availability/ob_ls_migration.cpp @@ -202,7 +202,7 @@ int ObCopyTabletCtx::get_copy_tablet_status(ObCopyTabletStatus::STATUS &status) return ret; } -int ObCopyTabletCtx::get_copy_tablet_record_extra_info(const ObCopyTabletRecordExtraInfo *&extra_info) const +int ObCopyTabletCtx::get_copy_tablet_record_extra_info(ObCopyTabletRecordExtraInfo *&extra_info) { int ret = OB_SUCCESS; if (!is_valid()) { diff --git a/src/storage/high_availability/ob_ls_migration.h b/src/storage/high_availability/ob_ls_migration.h index 194306cf4..9b7a89254 100644 --- a/src/storage/high_availability/ob_ls_migration.h +++ b/src/storage/high_availability/ob_ls_migration.h @@ -89,7 +89,7 @@ public: void reset(); int set_copy_tablet_status(const ObCopyTabletStatus::STATUS &status) override; int get_copy_tablet_status(ObCopyTabletStatus::STATUS &status) const override; - int get_copy_tablet_record_extra_info(const ObCopyTabletRecordExtraInfo *&extra_info) const override; + int get_copy_tablet_record_extra_info(ObCopyTabletRecordExtraInfo *&extra_info) override; VIRTUAL_TO_STRING_KV(K_(tablet_id), K_(status)); public: diff --git a/src/storage/high_availability/ob_physical_copy_ctx.cpp b/src/storage/high_availability/ob_physical_copy_ctx.cpp index 577b85b91..3683d9e7a 100644 --- a/src/storage/high_availability/ob_physical_copy_ctx.cpp +++ b/src/storage/high_availability/ob_physical_copy_ctx.cpp @@ -18,6 +18,54 @@ namespace oceanbase namespace storage { +/******************ObCopyTabletRecordExtraInfo*********************/ +ObCopyTabletRecordExtraInfo::ObCopyTabletRecordExtraInfo() + : cost_time_ms_(0), + total_data_size_(0), + write_data_size_(0), + major_count_(0), + macro_count_(0), + major_macro_count_(0), + reuse_macro_count_(0), + max_reuse_mgr_size_(0), + restore_action_(ObTabletRestoreAction::ACTION::RESTORE_NONE) +{ +} + +ObCopyTabletRecordExtraInfo::~ObCopyTabletRecordExtraInfo() +{ +} + +void ObCopyTabletRecordExtraInfo::reset() +{ + cost_time_ms_ = 0; + total_data_size_ = 0; + write_data_size_ = 0; + major_count_ = 0; + macro_count_ = 0; + major_macro_count_ = 0; + reuse_macro_count_ = 0; + max_reuse_mgr_size_ = 0; + restore_action_ = ObTabletRestoreAction::ACTION::RESTORE_NONE; +} + +int ObCopyTabletRecordExtraInfo::update_max_reuse_mgr_size(ObMacroBlockReuseMgr *reuse_mgr) +{ + int ret = OB_SUCCESS; + int64_t count = 0; + + if (OB_ISNULL(reuse_mgr)) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("update max reuse mgr size get invalid argument", K(ret), KP(reuse_mgr)); + } else if (OB_FAIL(reuse_mgr->count(count))) { + LOG_WARN("failed to count reuse mgr", K(ret), KP(reuse_mgr)); + } else { + max_reuse_mgr_size_ = MAX(count * reuse_mgr->get_item_size(), max_reuse_mgr_size_); + } + + return ret; +} + /******************ObPhysicalCopyCtx*********************/ ObPhysicalCopyCtx::ObPhysicalCopyCtx() : lock_(), diff --git a/src/storage/high_availability/ob_physical_copy_ctx.h b/src/storage/high_availability/ob_physical_copy_ctx.h index bf05df9e2..64caa0766 100644 --- a/src/storage/high_availability/ob_physical_copy_ctx.h +++ b/src/storage/high_availability/ob_physical_copy_ctx.h @@ -39,7 +39,7 @@ struct ObICopyTabletCtx public: virtual int set_copy_tablet_status(const ObCopyTabletStatus::STATUS &status) = 0; virtual int get_copy_tablet_status(ObCopyTabletStatus::STATUS &status) const = 0; - virtual int get_copy_tablet_record_extra_info(const ObCopyTabletRecordExtraInfo *&extra_info) const = 0; + virtual int get_copy_tablet_record_extra_info(ObCopyTabletRecordExtraInfo *&extra_info) = 0; }; class ObCopyTabletRecordExtraInfo final @@ -56,13 +56,14 @@ public: OB_INLINE void add_macro_count(const int64_t ¯o_count) { ATOMIC_FAA(¯o_count_, macro_count); } OB_INLINE void add_major_macro_count(const int64_t &major_macro_count) { ATOMIC_FAA(&major_macro_count_, major_macro_count); } OB_INLINE void add_reuse_macro_count(const int64_t &reuse_macro_count) { ATOMIC_FAA(&reuse_macro_count_, reuse_macro_count); } + OB_INLINE void set_restore_action(const ObTabletRestoreAction::ACTION &action) { ATOMIC_SET(&restore_action_, action); } OB_INLINE int get_major_count() const { return ATOMIC_LOAD(&major_count_); } // not atomic, but only called when major sstable copy finish, which is sequential - int update_max_reuse_mgr_size( - ObMacroBlockReuseMgr *&reuse_mgr); + int update_max_reuse_mgr_size(ObMacroBlockReuseMgr *reuse_mgr); - TO_STRING_KV(K_(cost_time_ms), K_(total_data_size), K_(write_data_size), K_(major_count), K_(macro_count), - K_(major_macro_count), K_(reuse_macro_count), K_(max_reuse_mgr_size)); + TO_STRING_KV(K_(cost_time_ms), K_(total_data_size), K_(write_data_size), K_(major_count), + K_(macro_count), K_(major_macro_count), K_(reuse_macro_count), K_(max_reuse_mgr_size), + "restore_action", ObTabletRestoreAction::get_action_str(restore_action_)); private: // The following 3 member variables are updated when writer of physical copy task finish // time cost of tablet copy (fully migration / restore of a single tablet) @@ -83,6 +84,10 @@ private: int64_t reuse_macro_count_; // max reuse mgr size int64_t max_reuse_mgr_size_; + + // The following 1 member variable are updated when tablet copy finish + // restore action (when migration, it is RESTORE_NONE) + ObTabletRestoreAction::ACTION restore_action_; }; struct ObPhysicalCopyCtx final diff --git a/src/storage/high_availability/ob_tablet_copy_finish_task.cpp b/src/storage/high_availability/ob_tablet_copy_finish_task.cpp index 3953bfce1..3d1debbc3 100644 --- a/src/storage/high_availability/ob_tablet_copy_finish_task.cpp +++ b/src/storage/high_availability/ob_tablet_copy_finish_task.cpp @@ -100,7 +100,7 @@ int ObTabletCopyFinishTask::process() int ret = OB_SUCCESS; bool only_contain_major = false; ObCopyTabletStatus::STATUS status = ObCopyTabletStatus::MAX_STATUS; - const ObCopyTabletRecordExtraInfo *extra_info = nullptr; + ObCopyTabletRecordExtraInfo *extra_info = nullptr; if (!is_inited_) { ret = OB_NOT_INIT; @@ -144,6 +144,7 @@ int ObTabletCopyFinishTask::process() LOG_WARN("failed to get copy tablet record extra info", K(tmp_ret), KP(extra_info)); } else if (OB_ISNULL(extra_info)) { LOG_WARN("copy tablet record extra info is NULL", K(extra_info)); + } else if (FALSE_IT(extra_info->set_restore_action(restore_action_))) { } else if (OB_SUCCESS != (tmp_ret = common::databuff_printf(extra_info_str, MAX_ROOTSERVICE_EVENT_EXTRA_INFO_LENGTH, "%s", to_cstring(*extra_info)))) { LOG_WARN("failed to print extra info", K(tmp_ret), K(extra_info)); } @@ -639,51 +640,5 @@ int ObTabletCopyFinishTask::check_log_replay_to_mds_sstable_end_scn_() return ret; } -/******************ObCopyTabletRecordExtraInfo*********************/ -ObCopyTabletRecordExtraInfo::ObCopyTabletRecordExtraInfo() - : cost_time_ms_(0), - total_data_size_(0), - write_data_size_(0), - major_count_(0), - macro_count_(0), - major_macro_count_(0), - reuse_macro_count_(0), - max_reuse_mgr_size_(0) -{ -} - -ObCopyTabletRecordExtraInfo::~ObCopyTabletRecordExtraInfo() -{ -} - -void ObCopyTabletRecordExtraInfo::reset() -{ - cost_time_ms_ = 0; - total_data_size_ = 0; - write_data_size_ = 0; - major_count_ = 0; - macro_count_ = 0; - major_macro_count_ = 0; - reuse_macro_count_ = 0; - max_reuse_mgr_size_ = 0; -} - -int ObCopyTabletRecordExtraInfo::update_max_reuse_mgr_size(ObMacroBlockReuseMgr *&reuse_mgr) -{ - int ret = OB_SUCCESS; - int64_t count = 0; - - if (OB_ISNULL(reuse_mgr)) { - ret = OB_INVALID_ARGUMENT; - LOG_WARN("update max reuse mgr size get invalid argument", K(ret), KP(reuse_mgr)); - } else if (OB_FAIL(reuse_mgr->count(count))) { - LOG_WARN("failed to count reuse mgr", K(ret), KP(reuse_mgr)); - } else { - max_reuse_mgr_size_ = MAX(count * reuse_mgr->get_item_size(), max_reuse_mgr_size_); - } - - return ret; -} - } } diff --git a/src/storage/high_availability/ob_tablet_group_restore.cpp b/src/storage/high_availability/ob_tablet_group_restore.cpp index 4c104564f..b832128d0 100644 --- a/src/storage/high_availability/ob_tablet_group_restore.cpp +++ b/src/storage/high_availability/ob_tablet_group_restore.cpp @@ -213,7 +213,7 @@ int ObTabletRestoreCtx::get_copy_tablet_status(ObCopyTabletStatus::STATUS &statu return ret; } -int ObTabletRestoreCtx::get_copy_tablet_record_extra_info(const ObCopyTabletRecordExtraInfo *&extra_info) const +int ObTabletRestoreCtx::get_copy_tablet_record_extra_info(ObCopyTabletRecordExtraInfo *&extra_info) { int ret = OB_SUCCESS; if (!is_valid()) { diff --git a/src/storage/high_availability/ob_tablet_group_restore.h b/src/storage/high_availability/ob_tablet_group_restore.h index 17a6d9e07..fded1c116 100644 --- a/src/storage/high_availability/ob_tablet_group_restore.h +++ b/src/storage/high_availability/ob_tablet_group_restore.h @@ -88,7 +88,7 @@ public: void reset(); int set_copy_tablet_status(const ObCopyTabletStatus::STATUS &status) override; int get_copy_tablet_status(ObCopyTabletStatus::STATUS &status) const override; - int get_copy_tablet_record_extra_info(const ObCopyTabletRecordExtraInfo *&extra_info) const override; + int get_copy_tablet_record_extra_info(ObCopyTabletRecordExtraInfo *&extra_info) override; VIRTUAL_TO_STRING_KV(K_(tenant_id), K_(ls_id), K_(tablet_id), KPC_(restore_base_info), K_(is_leader), K_(action), KP_(meta_index_store), KP_(second_meta_index_store), K_(replica_type), KP_(ha_table_info_mgr), K_(status));