backup in 4.1 and restore to 4.2

This commit is contained in:
hamstersox
2023-06-30 11:42:12 +00:00
committed by ob-robot
parent 756248ede0
commit 9136ff651e
18 changed files with 368 additions and 38 deletions

View File

@ -1069,3 +1069,80 @@ int ObBackupDataStore::read_base_tablet_list(const share::ObLSID &ls_id, ObIArra
}
return ret;
}
int ObBackupDataStore::read_tablet_to_ls_info_v_4_1_x(
const int64_t turn_id, const ObLSID &ls_id, ObIArray<ObTabletID> &tablet_ids)
{
int ret = OB_SUCCESS;
share::ObBackupPath path;
ObBackupPathString full_path;
ObBackupDataTabletToLSDesc tablet_to_ls_info;
if (!is_init()) {
ret = OB_NOT_INIT;
LOG_WARN("ObBackupDataStore not init", K(ret));
} else if (OB_FAIL(ObBackupPathUtilV_4_1::get_backup_data_tablet_ls_info_path(backup_set_dest_, turn_id, path))) {
LOG_WARN("fail to get tenant ls attr info path", K(ret));
} else if (OB_FAIL(full_path.assign(path.get_obstr()))) {
LOG_WARN("fail to assign full path", K(ret));
} else if (OB_FAIL(read_single_file(full_path, tablet_to_ls_info))) {
LOG_WARN("failed to read single file", K(ret), K(full_path));
} else if (!tablet_to_ls_info.is_valid()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid tablet to ls info", K(ret), K(tablet_to_ls_info));
}
for (int i = 0; OB_SUCC(ret) && i < tablet_to_ls_info.tablet_to_ls_.count(); ++i) {
const ObBackupDataTabletToLSInfo &info = tablet_to_ls_info.tablet_to_ls_.at(i);
if (!info.is_valid()) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("invalid info", K(ret), K(info));
} else if (info.ls_id_ == ls_id) {
if (OB_FAIL(append(tablet_ids, info.tablet_id_list_))) {
LOG_WARN("failed to append tablet ids", K(ret), K(info));
} else {
break;
}
}
}
if (OB_FAIL(ret)) {
} else if (tablet_ids.empty()) {
ret = OB_ENTRY_NOT_EXIST;
LOG_WARN("read no tablet", K(ret), K(turn_id), K(ls_id), K(full_path));
}
return ret;
}
int ObBackupDataStore::read_deleted_tablet_info_v_4_1_x(
const ObLSID &ls_id, ObIArray<ObTabletID> &deleted_tablet_ids)
{
int ret = OB_SUCCESS;
deleted_tablet_ids.reset();
share::ObBackupPath path;
ObBackupPathString full_path;
ObBackupDeletedTabletToLSDesc deleted_tablet_info;
if (!is_init()) {
ret = OB_NOT_INIT;
LOG_WARN("ObBackupDataStore not init", K(ret));
} else if (OB_FAIL(ObBackupPathUtil::get_deleted_tablet_info_path(backup_set_dest_, path))) {
LOG_WARN("fail to get tenant ls attr info path", K(ret));
} else if (OB_FAIL(full_path.assign(path.get_obstr()))) {
LOG_WARN("fail to assign full path", K(ret));
} else if (OB_FAIL(read_single_file(full_path, deleted_tablet_info))) {
if (OB_BACKUP_FILE_NOT_EXIST == ret) {
ret = OB_SUCCESS;
LOG_INFO("backup deleted file not exist", K(ret));
} else {
LOG_WARN("failed to read single file", K(ret), K(full_path));
}
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < deleted_tablet_info.deleted_tablet_to_ls_.count(); ++i) {
const ObBackupDataTabletToLSInfo &info = deleted_tablet_info.deleted_tablet_to_ls_.at(i);
if (info.ls_id_ == ls_id) {
if (OB_FAIL(deleted_tablet_ids.assign(info.tablet_id_list_))) {
LOG_WARN("failed to assign", K(ret), K(info));
}
break;
}
}
}
return ret;
}

View File

@ -312,6 +312,10 @@ public:
int read_root_key_info(const uint64_t tenant_id);
int read_base_tablet_list(const share::ObLSID &ls_id, ObIArray<common::ObTabletID> &tablet_id_array);
// 4.1 interface to get tablet to ls
int read_tablet_to_ls_info_v_4_1_x(const int64_t turn_id, const ObLSID &ls_id, ObIArray<ObTabletID> &tablet_ids);
int read_deleted_tablet_info_v_4_1_x(const ObLSID &ls_id, ObIArray<ObTabletID> &deleted_tablet_ids);
TO_STRING_KV(K_(backup_desc));
public:

View File

@ -1036,7 +1036,7 @@ int ObBackupIndexStoreWrapper::get_idx_(const share::ObBackupDataType &backup_da
int ObRestoreMetaIndexStore::init(const ObBackupRestoreMode &mode, const ObBackupIndexStoreParam &param,
const share::ObBackupDest &backup_dest, const share::ObBackupSetDesc &backup_set_desc, const bool is_sec_meta,
ObBackupIndexKVCache &index_kv_cache)
const uint64_t data_version, ObBackupIndexKVCache &index_kv_cache)
{
int ret = OB_SUCCESS;
share::ObBackupPath backup_path;
@ -1060,6 +1060,7 @@ int ObRestoreMetaIndexStore::init(const ObBackupRestoreMode &mode, const ObBacku
backup_data_type_ = param.backup_data_type_;
index_kv_cache_ = &index_kv_cache;
is_sec_meta_ = is_sec_meta;
data_version_ = data_version;
if (OB_FAIL(get_backup_file_path(backup_path))) {
LOG_WARN("failed to get backup file path", K(ret));
} else if (OB_FAIL(read_file_trailer_(backup_path.get_obstr(), backup_dest_.get_storage_info()))) {
@ -1075,7 +1076,12 @@ int ObRestoreMetaIndexStore::get_backup_file_path(share::ObBackupPath &backup_pa
{
int ret = OB_SUCCESS;
if (is_tenant_level_) {
if (OB_FAIL(share::ObBackupPathUtil::get_tenant_meta_index_backup_path(
if (DATA_VERSION_4_2_0_0 > data_version_) {
if (OB_FAIL(share::ObBackupPathUtilV_4_1::get_tenant_meta_index_backup_path(
backup_dest_, backup_data_type_, turn_id_, retry_id_, is_sec_meta_, backup_path))) {
LOG_WARN("failed to get tenant meta index file path", K(ret), K_(backup_dest), K_(backup_data_type), K_(turn_id));
}
} else if (OB_FAIL(share::ObBackupPathUtil::get_tenant_meta_index_backup_path(
backup_dest_, backup_data_type_, turn_id_, retry_id_, is_sec_meta_, backup_path))) {
LOG_WARN("failed to get tenant meta index file path", K(ret), K_(backup_dest), K_(backup_data_type),
K_(turn_id));
@ -1121,24 +1127,50 @@ int ObBackupMetaIndexStoreWrapper::init(const ObBackupRestoreMode &mode, const O
} else if (backup_data_type.is_sys_backup() && !init_sys_tablet_index_store) {
continue;
}
if (OB_FAIL(ret)) {
} else if (backup_set_info.tenant_compatible_ < DATA_VERSION_4_2_0_0) {
// In 4.1.x, sys tablet only has 1 backup turn.
// minor and major both use the data turn id.
if (backup_data_type.is_sys_backup() && OB_FALSE_IT(share_param.turn_id_ = 1)) {
} else if (!backup_data_type.is_sys_backup() && OB_FALSE_IT(share_param.turn_id_ = backup_set_info.data_turn_id_)) {
}
} else if (backup_data_type.is_minor_backup() && OB_FALSE_IT(share_param.turn_id_ = backup_set_info.minor_turn_id_)) {
} else if (backup_data_type.is_major_backup() && OB_FALSE_IT(share_param.turn_id_ = backup_set_info.major_turn_id_)) {
}
if (OB_SUCC(ret) && !backup_data_type.is_sys_backup()) {
if (backup_set_info.tenant_compatible_ < DATA_VERSION_4_2_0_0) {
if (OB_FAIL(get_tenant_meta_index_retry_id_v_4_1_x_(
backup_dest, backup_data_type, share_param.turn_id_, is_sec_meta, retry_id))) {
LOG_WARN("failed to get tenant meta index retry id", K(ret));
}
} else if (OB_FAIL(get_tenant_meta_index_retry_id_(
backup_dest, backup_data_type, share_param.turn_id_, is_sec_meta, retry_id))) {
LOG_WARN("failed to get tenant meta index retry id", K(ret));
}
if (OB_SUCC(ret)) {
share_param.retry_id_ = retry_id;
}
}
if (OB_FAIL(ret)) {
} else if (OB_FAIL(get_index_store_(backup_data_type, store))) {
LOG_WARN("failed to get index store", K(ret), K(backup_data_type));
} else if (OB_ISNULL(store)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("failed to get index store", K(ret), K(backup_data_type));
} else if (!backup_data_type.is_sys_backup() && OB_FAIL(get_tenant_meta_index_retry_id_(
backup_dest, backup_data_type, share_param.turn_id_, is_sec_meta, retry_id))) {
LOG_WARN("failed to get tenant meta index retry id", K(ret));
} else {
share_param.backup_data_type_ = backup_data_type;
share_param.is_tenant_level_ = backup_data_type.is_sys_backup() ? false : true;
if (!backup_data_type.is_sys_backup()) {
share_param.retry_id_ = retry_id;
}
if (OB_FAIL(store->init(mode, share_param, backup_dest, backup_set_desc, is_sec_meta, index_kv_cache))) {
if (OB_FAIL(store->init(mode,
share_param,
backup_dest,
backup_set_desc,
is_sec_meta,
backup_set_info.tenant_compatible_,
index_kv_cache))) {
LOG_WARN("failed to init store", K(ret), K(i));
}
}
@ -1208,6 +1240,26 @@ int ObBackupMetaIndexStoreWrapper::get_tenant_meta_index_retry_id_(
return ret;
}
int ObBackupMetaIndexStoreWrapper::get_tenant_meta_index_retry_id_v_4_1_x_(
const share::ObBackupDest &backup_dest, const share::ObBackupDataType &backup_data_type,
const int64_t turn_id, const int64_t is_sec_meta, int64_t &retry_id)
{
int ret = OB_SUCCESS;
ObBackupTenantIndexRetryIDGetter retry_id_getter;
const bool is_restore = true;
const bool is_macro_index = false;
if (!backup_dest.is_valid() || !backup_data_type.is_valid() || turn_id <= 0) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("get invalid args", K(ret), K(backup_dest), K(backup_data_type), K(turn_id));
} else if (OB_FAIL(retry_id_getter.init(backup_dest, backup_data_type,
turn_id, is_restore, is_macro_index, is_sec_meta))) {
LOG_WARN("failed to init retry id getter", K(ret), K(backup_dest), K(backup_data_type), K(turn_id));
} else if (OB_FAIL(retry_id_getter.get_max_retry_id_v_4_1_x(retry_id))) {
LOG_WARN("failed to get max retry id", K(ret));
}
return ret;
}
/* ObBackupMacroBlockIndexStoreWrapper */
ObBackupMacroBlockIndexStoreWrapper::ObBackupMacroBlockIndexStoreWrapper()
@ -1386,6 +1438,35 @@ int ObBackupTenantIndexRetryIDGetter::get_max_retry_id(int64_t &retry_id)
return ret;
}
int ObBackupTenantIndexRetryIDGetter::get_max_retry_id_v_4_1_x(int64_t &retry_id)
{
int ret = OB_SUCCESS;
retry_id = 0;
ObArray<int64_t> id_list;
const char *file_name_prefix = NULL;
share::ObBackupPath backup_path;
if (IS_NOT_INIT) {
ret = OB_NOT_INIT;
LOG_WARN("retry id getter not init", K(ret));
} else if (OB_FAIL(get_tenant_index_file_name_(file_name_prefix))) {
LOG_WARN("failed to get tenant index file name", K(ret));
} else if (is_restore_ &&
OB_FAIL(share::ObBackupPathUtilV_4_1::get_ls_info_data_info_dir_path(backup_dest_,
turn_id_,
backup_path))) {
LOG_WARN("failed to get ls info data info dir path",
K(ret), K_(backup_dest), K_(backup_data_type), K_(backup_set_desc), K_(turn_id));
} else if (OB_FAIL(list_files_(backup_path, backup_dest_.get_storage_info(), file_name_prefix, id_list))) {
LOG_WARN("failed to list files", K(ret), K(backup_path), K(backup_dest_), K(file_name_prefix));
} else if (OB_FAIL(find_largest_id_(id_list, retry_id))) {
LOG_WARN("failed to find largest id", K(ret), K(id_list));
} else {
LOG_INFO("get max tenant index retry id", K_(backup_dest), K_(backup_data_type),
K_(turn_id), K_(is_restore), K_(is_macro_index), K_(is_sec_meta), K(retry_id));
}
return ret;
}
int ObBackupTenantIndexRetryIDGetter::get_ls_info_data_info_dir_path_(ObBackupPath &backup_path)
{
int ret = OB_SUCCESS;

View File

@ -175,14 +175,14 @@ private:
class ObRestoreMetaIndexStore final : public ObBackupMetaIndexStore
{
public:
ObRestoreMetaIndexStore() {}
ObRestoreMetaIndexStore(): ObBackupMetaIndexStore(), data_version_(0) {}
virtual ~ObRestoreMetaIndexStore() {}
int init(const ObBackupRestoreMode &mode, const ObBackupIndexStoreParam &param,
const share::ObBackupDest &backup_dest, const share::ObBackupSetDesc &backup_set_desc, const bool is_sec_meta,
ObBackupIndexKVCache &index_kv_cache);
const uint64_t data_version, ObBackupIndexKVCache &index_kv_cache);
virtual int get_backup_file_path(share::ObBackupPath &backup_path) const override;
private:
uint64_t data_version_;
DISALLOW_COPY_AND_ASSIGN(ObRestoreMetaIndexStore);
};
@ -215,6 +215,8 @@ private:
int get_index_store_(const share::ObBackupDataType &type, ObRestoreMetaIndexStore *&index_store);
int get_tenant_meta_index_retry_id_(const share::ObBackupDest &backup_dest, const share::ObBackupDataType &backup_data_type,
const int64_t turn_id, const int64_t is_sec_meta, int64_t &retry_id);
int get_tenant_meta_index_retry_id_v_4_1_x_(const share::ObBackupDest &backup_dest, const share::ObBackupDataType &backup_data_type,
const int64_t turn_id, const int64_t is_sec_meta, int64_t &retry_id);
private:
bool is_inited_;
@ -256,6 +258,7 @@ public:
int init(const share::ObBackupDest &backup_dest, const share::ObBackupDataType &backup_data_type, const int64_t turn_id, const bool is_restore,
const bool is_macro_index, const bool is_sec_meta);
int get_max_retry_id(int64_t &retry_id);
int get_max_retry_id_v_4_1_x(int64_t &retry_id);
private:
int get_ls_info_data_info_dir_path_(share::ObBackupPath &backup_path);