diff --git a/src/share/CMakeLists.txt b/src/share/CMakeLists.txt index 82b6f7cce..ac829eb70 100644 --- a/src/share/CMakeLists.txt +++ b/src/share/CMakeLists.txt @@ -290,6 +290,7 @@ ob_set_subtarget(ob_share common_mixed ash/ob_active_sess_hist_task.cpp throttle/ob_share_throttle_define.cpp throttle/ob_throttle_common.cpp + restore/ob_restore_data_mode.cpp ) ob_set_subtarget(ob_share tablet diff --git a/src/share/ob_tenant_info_proxy.cpp b/src/share/ob_tenant_info_proxy.cpp index 32df2e953..28e7e5748 100755 --- a/src/share/ob_tenant_info_proxy.cpp +++ b/src/share/ob_tenant_info_proxy.cpp @@ -86,7 +86,8 @@ bool ObAllTenantInfo::is_valid() const && tenant_role_.is_valid() && switchover_status_.is_valid() && log_mode_.is_valid() - && is_valid_tenant_scn(sync_scn_, replayable_scn_, standby_scn_, recovery_until_scn_); + && is_valid_tenant_scn(sync_scn_, replayable_scn_, standby_scn_, recovery_until_scn_) + && restore_data_mode_.is_valid(); } int ObAllTenantInfo::init( @@ -99,7 +100,8 @@ int ObAllTenantInfo::init( const SCN &standby_scn, const SCN &recovery_until_scn, const ObArchiveMode &log_mode, - const share::ObLSID &max_ls_id) + const share::ObLSID &max_ls_id, + const share::ObRestoreDataMode &restore_data_mode) { int ret = OB_SUCCESS; if (OB_UNLIKELY(OB_INVALID_TENANT_ID == tenant_id @@ -112,11 +114,12 @@ int ObAllTenantInfo::init( || !recovery_until_scn.is_valid_and_not_min() || !log_mode.is_valid() || !is_valid_tenant_scn(sync_scn, replayable_scn, standby_scn, recovery_until_scn) - || !max_ls_id.is_valid())) { + || !max_ls_id.is_valid() + || !restore_data_mode.is_valid())) { ret = OB_INVALID_ARGUMENT; LOG_WARN("invalid argument", KR(ret), K(tenant_id), K(tenant_role), K(switchover_status), K(switchover_epoch), K(sync_scn), K(replayable_scn), K(standby_scn), K(recovery_until_scn), - K(log_mode), K(max_ls_id)); + K(log_mode), K(max_ls_id), K(restore_data_mode)); } else { tenant_id_ = tenant_id; tenant_role_ = tenant_role; @@ -128,6 +131,7 @@ int ObAllTenantInfo::init( recovery_until_scn_ = recovery_until_scn; log_mode_ = log_mode; max_ls_id_ = max_ls_id; + restore_data_mode_ = restore_data_mode; } return ret; } @@ -146,6 +150,7 @@ void ObAllTenantInfo::assign(const ObAllTenantInfo &other) recovery_until_scn_ = other.recovery_until_scn_; log_mode_ = other.log_mode_; max_ls_id_ = other.max_ls_id_; + restore_data_mode_ = other.restore_data_mode_; } return ; } @@ -162,6 +167,11 @@ void ObAllTenantInfo::reset() recovery_until_scn_.set_min(); log_mode_.reset(); max_ls_id_.reset(); + // ******** For compatibility ********** + // Following members are newly added. + // They need be reset to the VALID default value. + // Consider serialization compatibility for old binary RPC packet. + restore_data_mode_ = NORMAL_RESTORE_DATA_MODE; } OB_SERIALIZE_MEMBER(ObAllTenantInfo, tenant_id_, tenant_role_, @@ -169,7 +179,7 @@ OB_SERIALIZE_MEMBER(ObAllTenantInfo, tenant_id_, tenant_role_, replayable_scn_, standby_scn_, // FARM COMPAT WHITELIST recovery_until_scn_, log_mode_, - max_ls_id_); + max_ls_id_, restore_data_mode_); ObAllTenantInfo& ObAllTenantInfo::operator= (const ObAllTenantInfo &other) { diff --git a/src/share/ob_tenant_info_proxy.h b/src/share/ob_tenant_info_proxy.h index 97c64e10c..026102b17 100755 --- a/src/share/ob_tenant_info_proxy.h +++ b/src/share/ob_tenant_info_proxy.h @@ -23,6 +23,7 @@ //#include "share/ls/ob_ls_status_operator.h" #include "lib/mysqlclient/ob_mysql_transaction.h" //ObMySQLTransaction #include "share/ls/ob_ls_i_life_manager.h" // share::OB_LS_INVALID_SCN_VALUE +#include "share/restore/ob_restore_data_mode.h" //share::ObRestoreDataMode namespace oceanbase { @@ -65,6 +66,7 @@ public: * @param[in] standby_scn * @param[in] recovery_until_scn * @param[in] log_mode + * @param[in] restore_data_mode */ int init(const uint64_t tenant_id, const ObTenantRole &tenant_role, @@ -75,7 +77,8 @@ public: const SCN &standby_scn = SCN::base_scn(), const SCN &recovery_until_scn = SCN::base_scn(), const ObArchiveMode &log_mode = NOARCHIVE_MODE, - const share::ObLSID &max_ls_id = share::SYS_LS); + const share::ObLSID &max_ls_id = share::SYS_LS, + const share::ObRestoreDataMode &restore_data_mode = NORMAL_RESTORE_DATA_MODE); ObAllTenantInfo &operator=(const ObAllTenantInfo &other); void assign(const ObAllTenantInfo &other); void reset(); @@ -115,7 +118,7 @@ IS_TENANT_STATUS(prepare_flashback_for_switch_to_primary) TO_STRING_KV(K_(tenant_id), K_(tenant_role), K_(switchover_status), K_(switchover_epoch), K_(sync_scn), K_(replayable_scn), - K_(standby_scn), K_(recovery_until_scn), K_(log_mode), K_(max_ls_id)); + K_(standby_scn), K_(recovery_until_scn), K_(log_mode), K_(max_ls_id), K_(restore_data_mode)); DECLARE_TO_YSON_KV; // Getter&Setter @@ -141,6 +144,7 @@ public:\ Property_declare_var(share::SCN, recovery_until_scn) Property_declare_var(ObArchiveMode, log_mode) Property_declare_var(share::ObLSID, max_ls_id) + Property_declare_var(share::ObRestoreDataMode, restore_data_mode) #undef Property_declare_var private: ObTenantRole tenant_role_; diff --git a/src/share/restore/ob_restore_data_mode.cpp b/src/share/restore/ob_restore_data_mode.cpp new file mode 100644 index 000000000..43e14c4a7 --- /dev/null +++ b/src/share/restore/ob_restore_data_mode.cpp @@ -0,0 +1,66 @@ +/** + * Copyright (c) 2021 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ + +#define USING_LOG_PREFIX SHARE +#include "share/restore/ob_restore_data_mode.h" + +using namespace oceanbase; +using namespace share; + +OB_SERIALIZE_MEMBER(ObRestoreDataMode, mode_); + +static const char *OB_RESTORE_DATA_MODE_STR[] = {"NORMAL", "REMOTE", "UNKNOWN"}; + +ObRestoreDataMode &ObRestoreDataMode::operator=(const ObRestoreDataMode &restore_data_mode) +{ + if (this != &restore_data_mode) { + mode_ = restore_data_mode.mode_; + } + return *this; +} + +ObRestoreDataMode &ObRestoreDataMode::operator=(const Mode &mode) +{ + mode_ = mode; + return *this; +} + +const char* ObRestoreDataMode::to_str() const +{ + STATIC_ASSERT(ARRAYSIZEOF(OB_RESTORE_DATA_MODE_STR) == RESTORE_DATA_MODE_MAX + 1, "array size mismatch"); + const char *str = OB_RESTORE_DATA_MODE_STR[RESTORE_DATA_MODE_MAX]; + if (OB_UNLIKELY(mode_ >= Mode::RESTORE_DATA_MODE_MAX + || mode_ < Mode::NORMAL)) { + LOG_ERROR_RET(OB_ERR_UNEXPECTED, "fatal error, unknown restore data mode", K_(mode)); + } else { + str = OB_RESTORE_DATA_MODE_STR[mode_]; +} + return str; +} + +ObRestoreDataMode::ObRestoreDataMode(const ObString &str) +{ + mode_ = Mode::RESTORE_DATA_MODE_MAX; + if (str.empty()) { + } else { + for (int64_t i = 0; i < ARRAYSIZEOF(OB_RESTORE_DATA_MODE_STR); i++) { + if (0 == str.case_compare(OB_RESTORE_DATA_MODE_STR[i])) { + mode_ = i; + break; + } + } + } + + if (Mode::RESTORE_DATA_MODE_MAX == mode_) { + LOG_WARN_RET(OB_INVALID_ARGUMENT, "invalid restore data mode", K_(mode), K(str)); + } +} \ No newline at end of file diff --git a/src/share/restore/ob_restore_data_mode.h b/src/share/restore/ob_restore_data_mode.h new file mode 100644 index 000000000..09d468742 --- /dev/null +++ b/src/share/restore/ob_restore_data_mode.h @@ -0,0 +1,61 @@ +/** + * Copyright (c) 2021 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ + +#ifndef OCENABASE_SHARE_OB_RESTORE_DATA_MODE_H +#define OCENABASE_SHARE_OB_RESTORE_DATA_MODE_H + +#include +#include "lib/utility/ob_print_utils.h" + +namespace oceanbase +{ +namespace share +{ +class ObRestoreDataMode final +{ + OB_UNIS_VERSION(1); +public: + enum Mode + { + // tenant restoring from whole data, default retore mode + NORMAL = 0, + // just restore clog, minor and major macro blocks are in remote reference state + REMOTE = 1, + RESTORE_DATA_MODE_MAX + }; + +public: + ObRestoreDataMode() : mode_(Mode::NORMAL) {} + ~ObRestoreDataMode() = default; + explicit ObRestoreDataMode(const Mode &mode) : mode_(mode) {} + explicit ObRestoreDataMode(const ObString &str); + ObRestoreDataMode &operator=(const ObRestoreDataMode &restore_mode); + ObRestoreDataMode &operator=(const Mode &mode); + constexpr bool is_valid() const { return mode_ >= Mode::NORMAL && mode_ < Mode::RESTORE_DATA_MODE_MAX;} + bool is_remote_mode() const { return Mode::REMOTE == mode_; } + bool is_normal_mode() const { return Mode::NORMAL == mode_; } + bool is_same_mode(const ObRestoreDataMode &other) const { return mode_ == other.mode_; } + void reset() { mode_ = Mode::NORMAL; } + const char *to_str() const; + TO_STRING_KV("restore data mode", to_str()); + +public: + int64_t mode_; +}; + +static const ObRestoreDataMode NORMAL_RESTORE_DATA_MODE(ObRestoreDataMode::Mode::NORMAL); +static const ObRestoreDataMode REMOTE_RESTORE_DATA_MODE(ObRestoreDataMode::Mode::REMOTE); + +} //share +} //oceanbase + +#endif \ No newline at end of file