[FEAT MERGE] merge recover table
Co-authored-by: hamstersox <673144759@qq.com> Co-authored-by: skylhd <dickylhd@gmail.com> Co-authored-by: HaHaJeff <jeffzhouhhh@gmail.com>
This commit is contained in:
153
src/share/restore/ob_import_arg.cpp
Normal file
153
src/share/restore/ob_import_arg.cpp
Normal file
@ -0,0 +1,153 @@
|
||||
/**
|
||||
* 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_import_arg.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
|
||||
// ObImportArg
|
||||
OB_SERIALIZE_MEMBER(ObImportArg, import_table_arg_, remap_table_arg_);
|
||||
|
||||
const ObImportDatabaseArray &ObImportArg::get_import_database_array() const
|
||||
{
|
||||
return import_table_arg_.get_import_database_array();
|
||||
}
|
||||
|
||||
const ObImportTableArray &ObImportArg::get_import_table_array() const
|
||||
{
|
||||
return import_table_arg_.get_import_table_array();
|
||||
}
|
||||
|
||||
const ObImportPartitionArray &ObImportArg::get_import_partition_array() const
|
||||
{
|
||||
return import_table_arg_.get_import_partition_array();
|
||||
}
|
||||
|
||||
const ObRemapDatabaseArray &ObImportArg::get_remap_database_array() const
|
||||
{
|
||||
return remap_table_arg_.get_remap_database_array();
|
||||
}
|
||||
|
||||
const ObRemapTableArray &ObImportArg::get_remap_table_array() const
|
||||
{
|
||||
return remap_table_arg_.get_remap_table_array();
|
||||
}
|
||||
|
||||
const ObRemapPartitionArray &ObImportArg::get_remap_partition_array() const
|
||||
{
|
||||
return remap_table_arg_.get_remap_partition_array();
|
||||
}
|
||||
|
||||
const ObRemapTablegroupArray &ObImportArg::get_remap_tablegroup_array() const
|
||||
{
|
||||
return remap_table_arg_.get_remap_tablegroup_array();
|
||||
}
|
||||
|
||||
const ObRemapTablespaceArray &ObImportArg::get_remap_tablespace_array() const
|
||||
{
|
||||
return remap_table_arg_.get_remap_tablespace_array();
|
||||
}
|
||||
|
||||
void ObImportArg::reset()
|
||||
{
|
||||
import_table_arg_.reset();
|
||||
remap_table_arg_.reset();
|
||||
}
|
||||
|
||||
int ObImportArg::assign(const ObImportArg &other)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(import_table_arg_.assign(other.get_import_table_arg()))) {
|
||||
LOG_WARN("failed to assign import table arg", K(ret), "import table arg", other.get_import_table_arg());
|
||||
} else if (OB_FAIL(remap_table_arg_.assign(other.get_remap_table_arg()))) {
|
||||
LOG_WARN("failed to assign remap table arg", K(ret), "remap table arg", other.get_remap_table_arg());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportArg::add_import_database(const ObImportDatabaseItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(import_table_arg_.add_database(item))) {
|
||||
LOG_WARN("failed to add import database", K(ret), K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportArg::add_import_table(const ObImportTableItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(import_table_arg_.add_table(item))) {
|
||||
LOG_WARN("failed to add import table", K(ret), K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportArg::add_import_parition(const ObImportPartitionItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(import_table_arg_.add_partition(item))) {
|
||||
LOG_WARN("failed to add import partition", K(ret), K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportArg::add_remap_database(const ObRemapDatabaseItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(remap_table_arg_.add_remap_database(item))) {
|
||||
LOG_WARN("failed to add remap database", K(ret), K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportArg::add_remap_table(const ObRemapTableItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(remap_table_arg_.add_remap_table(item))) {
|
||||
LOG_WARN("failed to add remap table", K(ret), K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportArg::add_remap_parition(const ObRemapPartitionItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(remap_table_arg_.add_remap_parition(item))) {
|
||||
LOG_WARN("failed to add remap partition", K(ret), K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportArg::add_remap_tablegroup(const ObRemapTablegroupItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(remap_table_arg_.add_remap_tablegroup(item))) {
|
||||
LOG_WARN("failed to add remap tablegroup", K(ret), K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportArg::add_remap_tablespace(const ObRemapTablespaceItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(remap_table_arg_.add_remap_tablespace(item))) {
|
||||
LOG_WARN("failed to add remap tablespace", K(ret), K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
69
src/share/restore/ob_import_arg.h
Normal file
69
src/share/restore/ob_import_arg.h
Normal file
@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 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 OCEANBASE_SHARE_IMPORT_ARG_H
|
||||
#define OCEANBASE_SHARE_IMPORT_ARG_H
|
||||
|
||||
#include "share/restore/ob_import_table_arg.h"
|
||||
#include "share/restore/ob_import_remap_arg.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
|
||||
class ObImportArg final
|
||||
{
|
||||
OB_UNIS_VERSION(1);
|
||||
public:
|
||||
ObImportArg() : import_table_arg_(), remap_table_arg_()
|
||||
{}
|
||||
|
||||
const ObImportTableArg &get_import_table_arg() const { return import_table_arg_; }
|
||||
const ObImportRemapArg &get_remap_table_arg() const { return remap_table_arg_; }
|
||||
ObImportTableArg &get_import_table_arg() { return import_table_arg_; }
|
||||
ObImportRemapArg &get_remap_table_arg() { return remap_table_arg_; }
|
||||
|
||||
const ObImportDatabaseArray &get_import_database_array() const;
|
||||
const ObImportTableArray &get_import_table_array() const;
|
||||
const ObImportPartitionArray &get_import_partition_array() const;
|
||||
|
||||
const ObRemapDatabaseArray &get_remap_database_array() const;
|
||||
const ObRemapTableArray &get_remap_table_array() const;
|
||||
const ObRemapPartitionArray &get_remap_partition_array() const;
|
||||
const ObRemapTablegroupArray &get_remap_tablegroup_array() const;
|
||||
const ObRemapTablespaceArray &get_remap_tablespace_array() const;
|
||||
|
||||
void reset();
|
||||
int assign(const ObImportArg &other);
|
||||
int add_import_database(const ObImportDatabaseItem &item);
|
||||
int add_import_table(const ObImportTableItem &item);
|
||||
int add_import_parition(const ObImportPartitionItem &item);
|
||||
int add_remap_database(const ObRemapDatabaseItem &item);
|
||||
int add_remap_table(const ObRemapTableItem &item);
|
||||
int add_remap_parition(const ObRemapPartitionItem &item);
|
||||
int add_remap_tablegroup(const ObRemapTablegroupItem &item);
|
||||
int add_remap_tablespace(const ObRemapTablespaceItem &item);
|
||||
|
||||
TO_STRING_KV(K_(import_table_arg), K_(remap_table_arg));
|
||||
|
||||
private:
|
||||
ObImportTableArg import_table_arg_;
|
||||
ObImportRemapArg remap_table_arg_;
|
||||
DISALLOW_COPY_AND_ASSIGN(ObImportArg);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
96
src/share/restore/ob_import_item_format_provider.cpp
Normal file
96
src/share/restore/ob_import_item_format_provider.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
/**
|
||||
* 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_import_item_format_provider.h"
|
||||
#include "lib/allocator/page_arena.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
|
||||
// ObIImportItemFormatProvider
|
||||
int ObIImportItemFormatProvider::format_serialize(common::ObIAllocator &allocator, common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
char *serialize_buf = NULL;
|
||||
int64_t serialize_pos = 0;
|
||||
int64_t serialize_size = get_format_serialize_size();
|
||||
if (OB_ISNULL(serialize_buf = static_cast<char*>(allocator.alloc(serialize_size)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("fail to alloc memory", K(ret), K(serialize_size));
|
||||
} else if (OB_FAIL(format_serialize(serialize_buf, serialize_size, serialize_pos))) {
|
||||
LOG_WARN("fail to format serialize", K(ret));
|
||||
} else {
|
||||
str.assign_ptr(serialize_buf, serialize_size);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ObImportItemHexFormatImpl
|
||||
int64_t ObImportItemHexFormatImpl::get_hex_format_serialize_size() const
|
||||
{
|
||||
return 2 * get_serialize_size();
|
||||
}
|
||||
|
||||
int ObImportItemHexFormatImpl::hex_format_serialize(
|
||||
char *buf, const int64_t buf_len, int64_t &pos) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
common::ObArenaAllocator tmp_allocator;
|
||||
char *serialize_buf = NULL;
|
||||
int64_t serialize_pos = 0;
|
||||
int64_t serialize_size = get_serialize_size();
|
||||
if ((NULL == buf) || (buf_len <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid arguments.", K(ret), KP(buf), K(buf_len));
|
||||
} else if (OB_ISNULL(serialize_buf = static_cast<char*>(tmp_allocator.alloc(serialize_size)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("fail to alloc memory", K(ret), K(serialize_size));
|
||||
} else if (OB_FAIL(serialize(serialize_buf, serialize_size, serialize_pos))) {
|
||||
LOG_WARN("fail to serialize", K(ret));
|
||||
} else if (OB_FAIL(hex_print(serialize_buf, serialize_pos, buf, buf_len, pos))) {
|
||||
LOG_WARN("fail to print hex", K(ret), K(serialize_pos), K(buf_len), K(pos));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ObImportItemHexFormatImpl::hex_format_deserialize(
|
||||
const char *buf, const int64_t data_len, int64_t &pos)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
common::ObArenaAllocator tmp_allocator;
|
||||
int64_t hex_size = data_len - pos;
|
||||
char *deserialize_buf = NULL;
|
||||
int64_t deserialize_size = hex_size / 2 + 1;
|
||||
int64_t deserialize_pos = 0;
|
||||
if ((NULL == buf) || (data_len < 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid arguments.", K(ret), KP(buf), K(data_len));
|
||||
} else if (hex_size <= 0) {
|
||||
// skip
|
||||
} else if (OB_ISNULL(deserialize_buf = static_cast<char*>(tmp_allocator.alloc(deserialize_size)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("fail to alloc memory", K(ret), K(deserialize_size));
|
||||
} else if (OB_FAIL(hex_to_cstr(buf, hex_size, deserialize_buf, deserialize_size))) {
|
||||
LOG_WARN("fail to get cstr from hex", K(ret), K(hex_size), K(deserialize_size));
|
||||
} else if (OB_FAIL(deserialize(deserialize_buf, deserialize_size, deserialize_pos))) {
|
||||
LOG_WARN("fail to deserialize", K(ret));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
63
src/share/restore/ob_import_item_format_provider.h
Normal file
63
src/share/restore/ob_import_item_format_provider.h
Normal file
@ -0,0 +1,63 @@
|
||||
/**
|
||||
* 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 OCEANBASE_SHARE_IMPORT_ITEM_FORMAT_PROVIEDER_H_
|
||||
#define OCEANBASE_SHARE_IMPORT_ITEM_FORMAT_PROVIEDER_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "lib/ob_define.h"
|
||||
#include "lib/utility/ob_print_utils.h"
|
||||
#include "lib/utility/ob_unify_serialize.h"
|
||||
#include "lib/oblog/ob_log_module.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
// Format string used for show to user
|
||||
class ObIImportItemFormatProvider
|
||||
{
|
||||
public:
|
||||
virtual int64_t get_format_serialize_size() const = 0;
|
||||
|
||||
virtual int format_serialize(char *buf, const int64_t buf_len, int64_t &pos) const = 0;
|
||||
|
||||
int format_serialize(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
};
|
||||
|
||||
|
||||
// Format string used to persist to table
|
||||
class ObIImportItemHexFormatProvider
|
||||
{
|
||||
public:
|
||||
virtual int64_t get_hex_format_serialize_size() const = 0;
|
||||
|
||||
virtual int hex_format_serialize(char *buf, const int64_t buf_len, int64_t &pos) const = 0;
|
||||
|
||||
virtual int hex_format_deserialize(const char *buf, const int64_t data_len, int64_t &pos) = 0;
|
||||
};
|
||||
|
||||
|
||||
class ObImportItemHexFormatImpl : public ObIImportItemHexFormatProvider
|
||||
{
|
||||
OB_UNIS_VERSION_PV(); // pure virtual
|
||||
public:
|
||||
virtual int64_t get_hex_format_serialize_size() const override;
|
||||
|
||||
virtual int hex_format_serialize(char *buf, const int64_t buf_len, int64_t &pos) const override;
|
||||
|
||||
virtual int hex_format_deserialize(const char *buf, const int64_t data_len, int64_t &pos) override;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
144
src/share/restore/ob_import_partition_item.cpp
Normal file
144
src/share/restore/ob_import_partition_item.cpp
Normal file
@ -0,0 +1,144 @@
|
||||
/**
|
||||
* 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_import_partition_item.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
|
||||
// ObImportPartitionItem
|
||||
OB_SERIALIZE_MEMBER(ObImportPartitionItem, mode_, database_name_, table_name_, partition_name_);
|
||||
|
||||
void ObImportPartitionItem::reset()
|
||||
{
|
||||
mode_ = common::OB_NAME_CASE_INVALID;
|
||||
database_name_.reset();
|
||||
table_name_.reset();
|
||||
partition_name_.reset();
|
||||
}
|
||||
|
||||
bool ObImportPartitionItem::is_valid() const
|
||||
{
|
||||
return common::OB_NAME_CASE_INVALID != mode_
|
||||
&& !database_name_.empty()
|
||||
&& !table_name_.empty()
|
||||
&& !partition_name_.empty();
|
||||
}
|
||||
|
||||
bool ObImportPartitionItem::case_mode_equal(const ObIImportItem &other) const
|
||||
{
|
||||
bool is_equal = false;
|
||||
if (get_item_type() == other.get_item_type()) {
|
||||
const ObImportPartitionItem &the_other = static_cast<const ObImportPartitionItem &>(other);
|
||||
is_equal = ObCharset::case_mode_equal(mode_, database_name_, the_other.database_name_)
|
||||
&& ObCharset::case_mode_equal(mode_, table_name_, the_other.table_name_)
|
||||
&& ObCharset::case_mode_equal(mode_, partition_name_, the_other.partition_name_);
|
||||
}
|
||||
return is_equal;
|
||||
}
|
||||
|
||||
int64_t ObImportPartitionItem::get_format_serialize_size() const
|
||||
{
|
||||
// For example, database name is SH, table name is SALES, and partition name is SALES_1998.
|
||||
// The format string is `SH`.`SALES`:`SALES_1998`.
|
||||
// Pre allocate twice the size to handle escape character.
|
||||
int64_t size = 0;
|
||||
size += database_name_.length() * 2;
|
||||
size += table_name_.length() * 2;
|
||||
size += partition_name_.length() * 2;
|
||||
size += 8;
|
||||
return size;
|
||||
}
|
||||
|
||||
int ObImportPartitionItem::format_serialize(char *buf, const int64_t buf_len, int64_t &pos) const
|
||||
{
|
||||
// For example, database name is SH, table name is SALES, and partition name is SALES_1998.
|
||||
// The format string is `SH`.`SALES`:`SALES_1998`.
|
||||
int ret = OB_SUCCESS;
|
||||
if ((NULL == buf) || (buf_len <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid arguments.", K(ret), KP(buf), K(buf_len));
|
||||
} else if (!is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret));
|
||||
} else {
|
||||
const bool skip_escape = false;
|
||||
const bool do_oracle_mode_escape = false;
|
||||
int64_t string_size = 0;
|
||||
common::ObHexEscapeSqlStr hex_escape_db_name(database_name_, skip_escape, do_oracle_mode_escape);
|
||||
common::ObHexEscapeSqlStr hex_escape_table_name(table_name_, skip_escape, do_oracle_mode_escape);
|
||||
common::ObHexEscapeSqlStr hex_escape_part_name(partition_name_, skip_escape, do_oracle_mode_escape);
|
||||
if (OB_FAIL(databuff_printf(buf, buf_len, pos, "%s", "`"))) {
|
||||
LOG_WARN("fail to format str", K(ret), K(pos), K(buf_len));
|
||||
} else if (OB_FALSE_IT(string_size = hex_escape_db_name.to_string(buf + pos, buf_len - pos))) {
|
||||
} else if (OB_FALSE_IT(pos += string_size)) {
|
||||
} else if (OB_FAIL(databuff_printf(buf, buf_len, pos, "%s", "`.`"))) {
|
||||
LOG_WARN("fail to format str", K(ret), K(pos), K(buf_len));
|
||||
} else if (OB_FALSE_IT(string_size = hex_escape_table_name.to_string(buf + pos, buf_len - pos))) {
|
||||
} else if (OB_FALSE_IT(pos += string_size)) {
|
||||
} else if (OB_FAIL(databuff_printf(buf, buf_len, pos, "%s", "`:`"))) {
|
||||
LOG_WARN("fail to format str", K(ret), K(pos), K(buf_len));
|
||||
} else if (OB_FALSE_IT(string_size = hex_escape_part_name.to_string(buf + pos, buf_len - pos))) {
|
||||
} else if (OB_FALSE_IT(pos += string_size)) {
|
||||
} else if (OB_FAIL(databuff_printf(buf, buf_len, pos, "%s", "`"))) {
|
||||
LOG_WARN("fail to format str", K(ret), K(pos), K(buf_len));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportPartitionItem::deep_copy(common::ObIAllocator &allocator, const ObIImportItem &src)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!src.is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(src));
|
||||
} else if (get_item_type() != src.get_item_type()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("item type not match", K(ret), "src", src.get_item_type(), "dest", get_item_type());
|
||||
} else {
|
||||
const ObImportPartitionItem &other = static_cast<const ObImportPartitionItem &>(src);
|
||||
if (OB_FAIL(ob_write_string(allocator, other.database_name_, database_name_))) {
|
||||
LOG_WARN("failed to copy item", K(ret), K(other));
|
||||
} else if (OB_FAIL(ob_write_string(allocator, other.table_name_, table_name_))) {
|
||||
LOG_WARN("failed to copy item", K(ret), K(other));
|
||||
} else if (OB_FAIL(ob_write_string(allocator, other.partition_name_, partition_name_))) {
|
||||
LOG_WARN("failed to copy item", K(ret), K(other));
|
||||
} else {
|
||||
mode_ = other.mode_;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportPartitionItem::assign(const ObImportPartitionItem &other)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!other.is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(other));
|
||||
} else {
|
||||
mode_ = other.mode_;
|
||||
database_name_ = other.database_name_;
|
||||
table_name_ = other.table_name_;
|
||||
partition_name_ = other.partition_name_;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
70
src/share/restore/ob_import_partition_item.h
Normal file
70
src/share/restore/ob_import_partition_item.h
Normal file
@ -0,0 +1,70 @@
|
||||
/**
|
||||
* 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 OCEANBASE_SHARE_IMPORT_PARTITION_ITEM_H
|
||||
#define OCEANBASE_SHARE_IMPORT_PARTITION_ITEM_H
|
||||
|
||||
#include "share/restore/ob_import_schema_item.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
struct ObImportPartitionItem final : public ObIImportSchemaItem
|
||||
{
|
||||
OB_UNIS_VERSION(1);
|
||||
public:
|
||||
ObImportPartitionItem() :
|
||||
ObIImportSchemaItem(ItemType::PARTITION),
|
||||
database_name_(),
|
||||
table_name_(),
|
||||
partition_name_()
|
||||
{}
|
||||
|
||||
ObImportPartitionItem(common::ObNameCaseMode mode, const char *db_name, const int64_t db_len,
|
||||
const char *table_name, const int64_t table_len, const char *part_name, const int64_t part_len) :
|
||||
ObIImportSchemaItem(ItemType::PARTITION, mode),
|
||||
database_name_(db_len, db_name),
|
||||
table_name_(table_len, table_name),
|
||||
partition_name_(part_len, part_name)
|
||||
{}
|
||||
|
||||
virtual void reset() override;
|
||||
virtual bool is_valid() const override;
|
||||
// ignore case
|
||||
virtual bool case_mode_equal(const ObIImportItem &other) const override;
|
||||
virtual int64_t get_format_serialize_size() const override;
|
||||
virtual int format_serialize(
|
||||
char *buf,
|
||||
const int64_t buf_len,
|
||||
int64_t &pos) const override;
|
||||
|
||||
virtual int deep_copy(common::ObIAllocator &allocator, const ObIImportItem &src) override;
|
||||
int assign(const ObImportPartitionItem &other);
|
||||
|
||||
TO_STRING_KV(K_(mode), K_(database_name), K_(table_name), K_(partition_name));
|
||||
|
||||
public:
|
||||
// The following 3 names are all c_style string, and '\0' is not included
|
||||
// into the length.
|
||||
common::ObString database_name_;
|
||||
common::ObString table_name_;
|
||||
common::ObString partition_name_;
|
||||
};
|
||||
|
||||
|
||||
using ObImportPartitionArray = ObImportSchemaItemArray<ObImportPartitionItem>;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
548
src/share/restore/ob_import_remap_arg.cpp
Normal file
548
src/share/restore/ob_import_remap_arg.cpp
Normal file
@ -0,0 +1,548 @@
|
||||
/**
|
||||
* 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_import_remap_arg.h"
|
||||
#include "share/schema/ob_multi_version_schema_service.h"
|
||||
//#include "share/schema/ob_column_schema.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
|
||||
// ObImportRemapArg
|
||||
OB_SERIALIZE_MEMBER(
|
||||
ObImportRemapArg,
|
||||
remap_database_array_,
|
||||
remap_table_array_,
|
||||
remap_partition_array_,
|
||||
remap_tablegroup_array_,
|
||||
remap_tablespace_array_);
|
||||
|
||||
ObImportRemapArg::ObImportRemapArg()
|
||||
: remap_database_array_(),
|
||||
remap_table_array_(),
|
||||
remap_partition_array_(),
|
||||
remap_tablegroup_array_(),
|
||||
remap_tablespace_array_()
|
||||
{}
|
||||
|
||||
|
||||
void ObImportRemapArg::reset()
|
||||
{
|
||||
remap_database_array_.reset();
|
||||
remap_table_array_.reset();
|
||||
remap_partition_array_.reset();
|
||||
remap_tablegroup_array_.reset();
|
||||
remap_tablespace_array_.reset();
|
||||
}
|
||||
|
||||
int ObImportRemapArg::assign(const ObImportRemapArg &other)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(remap_database_array_.assign(other.get_remap_database_array()))) {
|
||||
LOG_WARN("failed to assign database array", K(ret), "database array", other.get_remap_database_array());
|
||||
} else if (OB_FAIL(remap_table_array_.assign(other.get_remap_table_array()))) {
|
||||
LOG_WARN("failed to assign table array", K(ret), "table array", other.get_remap_table_array());
|
||||
} else if (OB_FAIL(remap_partition_array_.assign(other.get_remap_partition_array()))) {
|
||||
LOG_WARN("failed to assign partition array", K(ret), "partition array", other.get_remap_partition_array());
|
||||
} else if (OB_FAIL(remap_tablegroup_array_.assign(other.get_remap_tablegroup_array()))) {
|
||||
LOG_WARN("failed to assign partition array", K(ret), "tablegroup array", other.get_remap_tablegroup_array());
|
||||
} else if (OB_FAIL(remap_tablespace_array_.assign(other.get_remap_tablespace_array()))) {
|
||||
LOG_WARN("failed to assign partition array", K(ret), "tablespace array", other.get_remap_tablespace_array());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::add_remap_database(const ObRemapDatabaseItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObImportDatabaseItem *dup_db_item = NULL;
|
||||
common::ObArenaAllocator allocator;
|
||||
ObString source_err_str;
|
||||
ObString target_err_str;
|
||||
|
||||
if (remap_database_array_.is_src_exist(item.src_, dup_db_item)
|
||||
|| remap_database_array_.is_target_exist(item.target_, dup_db_item)) {
|
||||
if (OB_FAIL(dup_db_item->format_serialize(allocator, source_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), KPC(dup_db_item));
|
||||
} else if (OB_FAIL(item.format_serialize(allocator, target_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), K(item));
|
||||
} else {
|
||||
ret = OB_BACKUP_CONFLICT_VALUE;
|
||||
LOG_WARN("input remap database is conflict", K(ret), K(item), KPC(dup_db_item));
|
||||
LOG_USER_ERROR(OB_BACKUP_CONFLICT_VALUE, target_err_str.length(), target_err_str.ptr(), source_err_str.length(), source_err_str.ptr());
|
||||
}
|
||||
} else if (OB_FAIL(remap_database_array_.add_item(item))) {
|
||||
LOG_WARN("failed to add remap database item", K(ret), K(item));
|
||||
} else {
|
||||
LOG_INFO("add one remap database", K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::add_remap_table(const ObRemapTableItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObImportTableItem *dup_table_item = NULL;
|
||||
common::ObArenaAllocator allocator;
|
||||
ObString source_err_str;
|
||||
ObString target_err_str;
|
||||
|
||||
if (remap_table_array_.is_src_exist(item.src_, dup_table_item)
|
||||
|| remap_table_array_.is_target_exist(item.target_, dup_table_item)) {
|
||||
if (OB_FAIL(dup_table_item->format_serialize(allocator, source_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), KPC(dup_table_item));
|
||||
} else if (OB_FAIL(item.format_serialize(allocator, target_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), K(item));
|
||||
} else {
|
||||
ret = OB_BACKUP_CONFLICT_VALUE;
|
||||
LOG_WARN("input remap table is conflict", K(ret), K(item), KPC(dup_table_item));
|
||||
LOG_USER_ERROR(OB_BACKUP_CONFLICT_VALUE, target_err_str.length(), target_err_str.ptr(), source_err_str.length(), source_err_str.ptr());
|
||||
}
|
||||
} else if (OB_FAIL(remap_table_array_.add_item(item))) {
|
||||
LOG_WARN("failed to add remap table item", K(ret), K(item));
|
||||
} else {
|
||||
LOG_INFO("add one remap table", K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::add_remap_parition(const ObRemapPartitionItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
bool is_dup = false;
|
||||
ObSqlString dup_item;
|
||||
if (OB_FAIL(check_remap_partition_dup(item, is_dup, dup_item))) {
|
||||
LOG_WARN("failed to check remap tablespace dup", K(ret), K(item));
|
||||
} else if (is_dup) {
|
||||
ret = OB_ENTRY_EXIST;
|
||||
LOG_WARN("duplicate partition", K(ret), K(item));
|
||||
LOG_USER_ERROR(OB_ENTRY_EXIST, dup_item.ptr());
|
||||
} else if (OB_FAIL(remap_partition_array_.add_item(item))) {
|
||||
LOG_WARN("failed to add remap partition item", K(ret), K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::add_remap_tablegroup(const ObRemapTablegroupItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObImportTablegroupItem *dup_tg_item = NULL;
|
||||
common::ObArenaAllocator allocator;
|
||||
ObString source_err_str;
|
||||
ObString target_err_str;
|
||||
|
||||
if (remap_tablegroup_array_.is_src_exist(item.src_, dup_tg_item)
|
||||
|| remap_tablegroup_array_.is_target_exist(item.target_, dup_tg_item)) {
|
||||
if (OB_FAIL(dup_tg_item->format_serialize(allocator, source_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), KPC(dup_tg_item));
|
||||
} else if (OB_FAIL(item.format_serialize(allocator, target_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), K(item));
|
||||
} else {
|
||||
ret = OB_BACKUP_CONFLICT_VALUE;
|
||||
LOG_WARN("input remap tablegroup is conflict", K(ret), K(item), KPC(dup_tg_item));
|
||||
LOG_USER_ERROR(OB_BACKUP_CONFLICT_VALUE, target_err_str.length(), target_err_str.ptr(), source_err_str.length(), source_err_str.ptr());
|
||||
}
|
||||
} else if (OB_FAIL(remap_tablegroup_array_.add_item(item))) {
|
||||
LOG_WARN("failed to add remap tablegroup item", K(ret), K(item));
|
||||
} else {
|
||||
LOG_INFO("add one remap tablegroup", K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::add_remap_tablespace(const ObRemapTablespaceItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObImportTablespaceItem *dup_ts_item = NULL;
|
||||
common::ObArenaAllocator allocator;
|
||||
ObString source_err_str;
|
||||
ObString target_err_str;
|
||||
|
||||
if (remap_tablespace_array_.is_src_exist(item.src_, dup_ts_item)
|
||||
|| remap_tablespace_array_.is_target_exist(item.target_, dup_ts_item)) {
|
||||
if (OB_FAIL(dup_ts_item->format_serialize(allocator, source_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), KPC(dup_ts_item));
|
||||
} else if (OB_FAIL(item.format_serialize(allocator, target_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), K(item));
|
||||
} else {
|
||||
ret = OB_BACKUP_CONFLICT_VALUE;
|
||||
LOG_WARN("input remap tablespace is conflict", K(ret), K(item), KPC(dup_ts_item));
|
||||
LOG_USER_ERROR(OB_BACKUP_CONFLICT_VALUE, target_err_str.length(), target_err_str.ptr(), source_err_str.length(), source_err_str.ptr());
|
||||
}
|
||||
} else if (OB_FAIL(remap_tablespace_array_.add_item(item))) {
|
||||
LOG_WARN("failed to add remap tablespace item", K(ret), K(item));
|
||||
} else {
|
||||
LOG_INFO("add one remap tablespace", K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::check_remap_database_dup(
|
||||
const ObRemapDatabaseItem &item, bool &is_dup, ObSqlString &dup_item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObImportDatabaseItem *dup_item_ptr = nullptr;
|
||||
is_dup = false;
|
||||
if (remap_database_array_.is_src_exist(item.src_, dup_item_ptr)) {
|
||||
is_dup = true;
|
||||
if (OB_ISNULL(dup_item_ptr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("dup item ptr must not be nullptr", K(ret));
|
||||
} else if (OB_FAIL(dup_item.assign_fmt("remap duplicate src database, %.*s", item.src_.name_.length(), item.src_.name_.ptr()))) {
|
||||
LOG_WARN("failed to assign fmt", K(ret));
|
||||
}
|
||||
} else if (remap_database_array_.is_target_exist(item.target_, dup_item_ptr)) {
|
||||
is_dup = true;
|
||||
if (OB_ISNULL(dup_item_ptr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("dup item ptr must not be nullptr", K(ret));
|
||||
} else if (OB_FAIL(dup_item.assign_fmt("remap duplicate target database, %.*s", item.target_.name_.length(), item.target_.name_.ptr()))) {
|
||||
LOG_WARN("failed to assign fmt", K(ret));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int ObImportRemapArg::check_remap_table_dup(
|
||||
const ObRemapTableItem &item, bool &is_dup, ObSqlString &dup_item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObImportTableItem *dup_item_ptr = nullptr;
|
||||
is_dup = false;
|
||||
if (remap_table_array_.is_src_exist(item.src_, dup_item_ptr)) {
|
||||
is_dup = true;
|
||||
if (OB_ISNULL(dup_item_ptr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("dup item ptr must not be nullptr", K(ret));
|
||||
} else if (OB_FAIL(dup_item.assign_fmt("remap duplicate src table, %.*s.%.*s",
|
||||
item.src_.database_name_.length(), item.src_.database_name_.ptr(),
|
||||
item.src_.table_name_.length(), item.src_.table_name_.ptr()))) {
|
||||
LOG_WARN("failed to assign fmt", K(ret));
|
||||
}
|
||||
} else if (remap_table_array_.is_target_exist(item.target_, dup_item_ptr)) {
|
||||
is_dup = true;
|
||||
if (OB_ISNULL(dup_item_ptr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("dup item ptr must not be nullptr", K(ret));
|
||||
} else if (OB_FAIL(dup_item.assign_fmt("remap duplicate target table, %.*s.%.*s",
|
||||
item.target_.database_name_.length(), item.target_.database_name_.ptr(),
|
||||
item.target_.table_name_.length(), item.target_.table_name_.ptr()))) {
|
||||
LOG_WARN("failed to assign fmt", K(ret));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int ObImportRemapArg::check_remap_partition_dup(
|
||||
const ObRemapPartitionItem &item, bool &is_dup, ObSqlString &dup_item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObImportPartitionItem *src_dup_item_ptr = nullptr;
|
||||
const ObImportTableItem *target_dup_item_ptr = nullptr;
|
||||
is_dup = false;
|
||||
if (remap_partition_array_.is_src_exist(item.src_, src_dup_item_ptr)) {
|
||||
is_dup = true;
|
||||
if (OB_ISNULL(src_dup_item_ptr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("dup item ptr must not be nullptr", K(ret));
|
||||
} else if (OB_FAIL(dup_item.assign_fmt("remap duplicate src partition, %.*s.%.*s:%.*s",
|
||||
item.src_.database_name_.length(), item.src_.database_name_.ptr(),
|
||||
item.src_.table_name_.length(), item.src_.table_name_.ptr(),
|
||||
item.src_.partition_name_.length(), item.src_.partition_name_.ptr()))) {
|
||||
LOG_WARN("failed to assign fmt", K(ret));
|
||||
}
|
||||
} else if (remap_table_array_.is_target_exist(item.target_, target_dup_item_ptr)) {
|
||||
is_dup = true;
|
||||
if (OB_ISNULL(target_dup_item_ptr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("dup item ptr must not be nullptr", K(ret));
|
||||
} else if (OB_FAIL(dup_item.assign_fmt("remap duplicate target table, %.*s.%.*s",
|
||||
item.target_.database_name_.length(), item.target_.database_name_.ptr(),
|
||||
item.target_.table_name_.length(), item.target_.table_name_.ptr()))) {
|
||||
LOG_WARN("failed to assign fmt", K(ret));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int ObImportRemapArg::check_remap_tablegroup_dup(
|
||||
const ObRemapTablegroupItem &item, bool &is_dup, ObSqlString &dup_item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObImportTablegroupItem *dup_item_ptr = nullptr;
|
||||
is_dup = false;
|
||||
if (remap_tablegroup_array_.is_src_exist(item.src_, dup_item_ptr)) {
|
||||
is_dup = true;
|
||||
if (OB_ISNULL(dup_item_ptr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("dup item ptr must not be nullptr", K(ret));
|
||||
} else if (OB_FAIL(dup_item.assign_fmt("remap duplicate src tablegroup, %.*s", item.src_.name_.length(), item.src_.name_.ptr()))) {
|
||||
LOG_WARN("failed to assign fmt", K(ret));
|
||||
}
|
||||
} else if (remap_tablegroup_array_.is_target_exist(item.target_, dup_item_ptr)) {
|
||||
is_dup = true;
|
||||
if (OB_ISNULL(dup_item_ptr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("dup item ptr must not be nullptr", K(ret));
|
||||
} else if (OB_FAIL(dup_item.assign_fmt("remap duplicate target tablegroup, %.*s", item.target_.name_.length(), item.target_.name_.ptr()))) {
|
||||
LOG_WARN("failed to assign fmt", K(ret));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int ObImportRemapArg::check_remap_tablespace_dup(
|
||||
const ObRemapTablespaceItem &item, bool &is_dup, ObSqlString &dup_item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObImportTablespaceItem *dup_item_ptr = nullptr;
|
||||
is_dup = false;
|
||||
if (remap_tablespace_array_.is_src_exist(item.src_, dup_item_ptr)) {
|
||||
is_dup = true;
|
||||
if (OB_ISNULL(dup_item_ptr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("dup item ptr must not be nullptr", K(ret));
|
||||
} else if (OB_FAIL(dup_item.assign_fmt("remap duplicate src tablegroup, %.*s", item.src_.name_.length(), item.src_.name_.ptr()))) {
|
||||
LOG_WARN("failed to assign fmt", K(ret));
|
||||
}
|
||||
} else if (remap_tablespace_array_.is_target_exist(item.target_, dup_item_ptr)) {
|
||||
is_dup = true;
|
||||
if (OB_ISNULL(dup_item_ptr)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("dup item ptr must not be nullptr", K(ret));
|
||||
} else if (OB_FAIL(dup_item.assign_fmt("remap duplicate target tablegroup, %.*s", item.target_.name_.length(), item.target_.name_.ptr()))) {
|
||||
LOG_WARN("failed to assign fmt", K(ret));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::get_remap_database(const ObImportDatabaseItem &src, ObImportDatabaseItem &target) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
bool is_exist = false;
|
||||
const ObImportDatabaseItem *p = NULL;
|
||||
if (!remap_database_array_.is_remap_target_exist(src, p)) {
|
||||
ret = OB_ENTRY_NOT_EXIST;
|
||||
} else {
|
||||
target = *p;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::get_remap_table(const ObImportTableItem &src, ObImportTableItem &target) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
bool is_exist = false;
|
||||
const ObImportTableItem *p = NULL;
|
||||
if (!remap_table_array_.is_remap_target_exist(src, p)) {
|
||||
ret = OB_ENTRY_NOT_EXIST;
|
||||
} else {
|
||||
target = *p;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::get_remap_partition(const ObImportPartitionItem &src, ObImportTableItem &target) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
bool is_exist = false;
|
||||
const ObImportTableItem *p = NULL;
|
||||
if (!remap_partition_array_.is_remap_target_exist(src, p)) {
|
||||
ret = OB_ENTRY_NOT_EXIST;
|
||||
} else {
|
||||
target = *p;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::get_remap_tablegroup(const ObImportTablegroupItem &src, ObImportTablegroupItem &target) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
bool is_exist = false;
|
||||
const ObImportTablegroupItem *p = NULL;
|
||||
if (!remap_tablegroup_array_.is_remap_target_exist(src, p)) {
|
||||
ret = OB_ENTRY_NOT_EXIST;
|
||||
} else {
|
||||
target = *p;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::get_remap_tablespace(const ObImportTablespaceItem &src, ObImportTablespaceItem &target) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
bool is_exist = false;
|
||||
const ObImportTablespaceItem *p = NULL;
|
||||
if (!remap_tablespace_array_.is_remap_target_exist(src, p)) {
|
||||
ret = OB_ENTRY_NOT_EXIST;
|
||||
} else {
|
||||
target = *p;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::get_remap_db_list_format_str(
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_remap_item_array_format_str_(remap_database_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get remap db list format str", K(ret), K_(remap_database_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::get_remap_table_list_format_str(
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_remap_item_array_format_str_(remap_table_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get remap table list format str", K(ret), K_(remap_table_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::get_remap_partition_list_format_str(
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_remap_item_array_format_str_(remap_partition_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get remap partition list format str", K(ret), K_(remap_partition_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::get_remap_tablegroup_list_format_str(
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_remap_item_array_format_str_(remap_tablegroup_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get remap tablegroup list format str", K(ret), K_(remap_tablegroup_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::get_remap_tablespace_list_format_str(
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_remap_item_array_format_str_(remap_tablespace_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get remap tablespace list format str", K(ret), K_(remap_tablespace_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::get_remap_db_list_hex_format_str(
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_remap_item_array_hex_format_str_(remap_database_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get remap db list hex_format str", K(ret), K_(remap_database_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::get_remap_table_list_hex_format_str(
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_remap_item_array_hex_format_str_(remap_table_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get remap table list hex_format str", K(ret), K_(remap_table_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::get_remap_partition_list_hex_format_str(
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_remap_item_array_hex_format_str_(remap_partition_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get remap partition list hex format str", K(ret), K_(remap_partition_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::get_remap_tablegroup_list_hex_format_str(
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_remap_item_array_hex_format_str_(remap_tablegroup_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get remap tablegroup list hex format str", K(ret), K_(remap_tablegroup_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::get_remap_tablespace_list_hex_format_str(
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_remap_item_array_hex_format_str_(remap_tablespace_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get remap tablespace list hex format str", K(ret), K_(remap_tablespace_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::remap_db_list_deserialize_hex_format_str(const common::ObString &str)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(remap_item_array_deserialize_hex_format_str_(remap_database_array_, str))) {
|
||||
LOG_WARN("fail to deserialize hex format remap database array", K(ret), K(str));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::remap_table_list_deserialize_hex_format_str(const common::ObString &str)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(remap_item_array_deserialize_hex_format_str_(remap_table_array_, str))) {
|
||||
LOG_WARN("fail to deserialize hex format remap table array", K(ret), K(str));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::remap_partition_list_deserialize_hex_format_str(const common::ObString &str)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(remap_item_array_deserialize_hex_format_str_(remap_partition_array_, str))) {
|
||||
LOG_WARN("fail to deserialize hex format remap partition array", K(ret), K(str));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::remap_tablegroup_list_deserialize_hex_format_str(const common::ObString &str)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(remap_item_array_deserialize_hex_format_str_(remap_tablegroup_array_, str))) {
|
||||
LOG_WARN("fail to deserialize hex format remap tablegroup array", K(ret), K(str));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportRemapArg::remap_tablespace_list_deserialize_hex_format_str(const common::ObString &str)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(remap_item_array_deserialize_hex_format_str_(remap_tablespace_array_, str))) {
|
||||
LOG_WARN("fail to deserialize hex format remap tablespace array", K(ret), K(str));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
173
src/share/restore/ob_import_remap_arg.h
Normal file
173
src/share/restore/ob_import_remap_arg.h
Normal file
@ -0,0 +1,173 @@
|
||||
/**
|
||||
* 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 OCEANBASE_SHARE_IMPORT_REMAP_ARG_H
|
||||
#define OCEANBASE_SHARE_IMPORT_REMAP_ARG_H
|
||||
|
||||
#include "share/restore/ob_remap_schema_item.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
|
||||
class ObImportRemapArg final
|
||||
{
|
||||
OB_UNIS_VERSION(1);
|
||||
public:
|
||||
ObImportRemapArg();
|
||||
void reset();
|
||||
int assign(const ObImportRemapArg &other);
|
||||
const ObRemapDatabaseArray &get_remap_database_array() const { return remap_database_array_; }
|
||||
const ObRemapTableArray &get_remap_table_array() const { return remap_table_array_; }
|
||||
const ObRemapPartitionArray &get_remap_partition_array() const { return remap_partition_array_; }
|
||||
const ObRemapTablegroupArray &get_remap_tablegroup_array() const { return remap_tablegroup_array_; }
|
||||
const ObRemapTablespaceArray &get_remap_tablespace_array() const { return remap_tablespace_array_; }
|
||||
ObRemapDatabaseArray &get_remap_database_array() { return remap_database_array_; }
|
||||
ObRemapTableArray &get_remap_table_array() { return remap_table_array_; }
|
||||
ObRemapPartitionArray &get_remap_partition_array() { return remap_partition_array_; }
|
||||
ObRemapTablegroupArray &get_remap_tablegroup_array() { return remap_tablegroup_array_; }
|
||||
ObRemapTablespaceArray &get_remap_tablespace_array() { return remap_tablespace_array_; }
|
||||
int add_remap_database(const ObRemapDatabaseItem &item);
|
||||
int add_remap_table(const ObRemapTableItem &item);
|
||||
int add_remap_parition(const ObRemapPartitionItem &item);
|
||||
int add_remap_tablegroup(const ObRemapTablegroupItem &item);
|
||||
int add_remap_tablespace(const ObRemapTablespaceItem &item);
|
||||
int check_remap_database_dup(const ObRemapDatabaseItem &item, bool &is_dup, ObSqlString &dup_item_str);
|
||||
int check_remap_table_dup(const ObRemapTableItem &item, bool &is_dup, ObSqlString &dup_item_str);
|
||||
int check_remap_partition_dup(const ObRemapPartitionItem &item, bool &is_dup, ObSqlString &dup_item_str);
|
||||
int check_remap_tablegroup_dup(const ObRemapTablegroupItem &item, bool &is_dup, ObSqlString &dup_item_str);
|
||||
int check_remap_tablespace_dup(const ObRemapTablespaceItem &item, bool &is_dup, ObSqlString &dup_item_str);
|
||||
int get_remap_database(const ObImportDatabaseItem &src, ObImportDatabaseItem &target) const;
|
||||
int get_remap_table(const ObImportTableItem &src, ObImportTableItem &target) const;
|
||||
int get_remap_partition(const ObImportPartitionItem &src, ObImportTableItem &target) const;
|
||||
int get_remap_tablegroup(const ObImportTablegroupItem &src, ObImportTablegroupItem &target) const;
|
||||
int get_remap_tablespace(const ObImportTablespaceItem &src, ObImportTablespaceItem &target) const;
|
||||
|
||||
int get_remap_db_list_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
int get_remap_table_list_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
int get_remap_partition_list_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
int get_remap_tablegroup_list_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
int get_remap_tablespace_list_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
int get_remap_db_list_hex_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
int get_remap_table_list_hex_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
int get_remap_partition_list_hex_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
int get_remap_tablegroup_list_hex_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
int get_remap_tablespace_list_hex_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
|
||||
int remap_db_list_deserialize_hex_format_str(const common::ObString &str);
|
||||
int remap_table_list_deserialize_hex_format_str(const common::ObString &str);
|
||||
int remap_partition_list_deserialize_hex_format_str(const common::ObString &str);
|
||||
int remap_tablegroup_list_deserialize_hex_format_str(const common::ObString &str);
|
||||
int remap_tablespace_list_deserialize_hex_format_str(const common::ObString &str);
|
||||
|
||||
TO_STRING_KV(K_(remap_database_array), K_(remap_table_array), K_(remap_partition_array),
|
||||
K_(remap_tablegroup_array), K_(remap_tablespace_array));
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
int get_remap_item_array_format_str_(
|
||||
const T &array,
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const;
|
||||
|
||||
template <typename T>
|
||||
int get_remap_item_array_hex_format_str_(
|
||||
const T &array,
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const;
|
||||
|
||||
template <typename T>
|
||||
int remap_item_array_deserialize_hex_format_str_(
|
||||
T& array,
|
||||
const common::ObString &str);
|
||||
|
||||
private:
|
||||
ObRemapDatabaseArray remap_database_array_;
|
||||
ObRemapTableArray remap_table_array_;
|
||||
ObRemapPartitionArray remap_partition_array_;
|
||||
ObRemapTablegroupArray remap_tablegroup_array_;
|
||||
ObRemapTablespaceArray remap_tablespace_array_;
|
||||
DISALLOW_COPY_AND_ASSIGN(ObImportRemapArg);
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
int ObImportRemapArg::get_remap_item_array_format_str_(
|
||||
const T &array,
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t pos = 0;
|
||||
int64_t str_buf_len = array.get_format_serialize_size();
|
||||
char *str_buf = NULL;
|
||||
|
||||
if (str_buf_len >= OB_MAX_LONGTEXT_LENGTH) {
|
||||
ret = OB_SIZE_OVERFLOW;
|
||||
SHARE_LOG(WARN, "format str is too long", K(ret), K(str_buf_len));
|
||||
} else if (OB_ISNULL(str_buf = static_cast<char *>(allocator.alloc(str_buf_len)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
SHARE_LOG(WARN, "fail to alloc buf", K(ret), K(str_buf_len));
|
||||
} else if (OB_FAIL(array.format_serialize(str_buf, str_buf_len, pos))) {
|
||||
SHARE_LOG(WARN, "fail to format remap item array", K(ret), K(pos), K(str_buf_len));
|
||||
} else {
|
||||
str.assign_ptr(str_buf, str_buf_len);
|
||||
SHARE_LOG(INFO, "get format remap item array str", K(str));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int ObImportRemapArg::get_remap_item_array_hex_format_str_(
|
||||
const T &array,
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t pos = 0;
|
||||
int64_t str_buf_len = array.get_hex_format_serialize_size();
|
||||
char *str_buf = NULL;
|
||||
|
||||
if (str_buf_len >= OB_MAX_LONGTEXT_LENGTH) {
|
||||
ret = OB_SIZE_OVERFLOW;
|
||||
SHARE_LOG(WARN, "hex format str is too long", K(ret), K(str_buf_len));
|
||||
} else if (OB_ISNULL(str_buf = static_cast<char *>(allocator.alloc(str_buf_len)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
SHARE_LOG(WARN, "fail to alloc buf", K(ret), K(str_buf_len));
|
||||
} else if (OB_FAIL(array.hex_format_serialize(str_buf, str_buf_len, pos))) {
|
||||
SHARE_LOG(WARN, "fail to hex format remap item array", K(ret), K(pos), K(str_buf_len));
|
||||
} else {
|
||||
str.assign_ptr(str_buf, str_buf_len);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int ObImportRemapArg::remap_item_array_deserialize_hex_format_str_(
|
||||
T& array,
|
||||
const common::ObString &str)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t pos = 0;
|
||||
if (OB_FAIL(array.hex_format_deserialize(str.ptr(), str.length(), pos))) {
|
||||
SHARE_LOG(WARN, "fail to deserialize hex format remap item array", K(ret), K(str));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
179
src/share/restore/ob_import_schema_item.h
Normal file
179
src/share/restore/ob_import_schema_item.h
Normal file
@ -0,0 +1,179 @@
|
||||
/**
|
||||
* 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 OCEANBASE_SHARE_IMPORT_SCHEMA_ITEM_H
|
||||
#define OCEANBASE_SHARE_IMPORT_SCHEMA_ITEM_H
|
||||
|
||||
#include "lib/ob_define.h"
|
||||
#include "lib/utility/ob_print_utils.h"
|
||||
#include "lib/utility/ob_unify_serialize.h"
|
||||
#include "lib/oblog/ob_log_module.h"
|
||||
#include "lib/container/ob_array_serialization.h"
|
||||
#include "common/object/ob_object.h"
|
||||
#include "share/restore/ob_import_item_format_provider.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
class ObIImportItem : public ObIImportItemFormatProvider
|
||||
{
|
||||
OB_UNIS_VERSION_PV(); // pure virtual
|
||||
public:
|
||||
enum ItemType
|
||||
{
|
||||
DATABASE = 0,
|
||||
TABLE,
|
||||
PARTITION,
|
||||
TABLEGROUP,
|
||||
TABLESPACE,
|
||||
REMAP
|
||||
};
|
||||
|
||||
public:
|
||||
explicit ObIImportItem(ItemType item_type)
|
||||
: item_type_(item_type)
|
||||
{}
|
||||
virtual ~ObIImportItem() {}
|
||||
virtual void reset() = 0;
|
||||
virtual bool is_valid() const = 0;
|
||||
virtual int deep_copy(common::ObIAllocator &allocator, const ObIImportItem &src) = 0;
|
||||
virtual bool operator==(const ObIImportItem &other) const = 0;
|
||||
|
||||
ItemType get_item_type() const { return item_type_; }
|
||||
|
||||
DECLARE_PURE_VIRTUAL_TO_STRING;
|
||||
|
||||
private:
|
||||
ItemType item_type_;
|
||||
};
|
||||
|
||||
|
||||
struct ObIImportSchemaItem : public ObIImportItem
|
||||
{
|
||||
ObIImportSchemaItem(ItemType item_type) :
|
||||
ObIImportItem(item_type),
|
||||
mode_(common::OB_NAME_CASE_INVALID)
|
||||
{}
|
||||
|
||||
ObIImportSchemaItem(ItemType item_type, common::ObNameCaseMode mode) :
|
||||
ObIImportItem(item_type),
|
||||
mode_(mode)
|
||||
{}
|
||||
|
||||
virtual bool case_mode_equal(const ObIImportItem &other) const = 0;
|
||||
virtual bool operator==(const ObIImportItem &other) const override
|
||||
{
|
||||
return case_mode_equal(other);
|
||||
}
|
||||
|
||||
public:
|
||||
common::ObNameCaseMode mode_; // for compare
|
||||
};
|
||||
|
||||
|
||||
// Used for these schema which can be named with only one string, such as database, tablespace, tablegroup.
|
||||
template <int64_t MAX_SIZE, ObIImportItem::ItemType ITEM_TYPE>
|
||||
struct ObImportSimpleSchemaItem final : public ObIImportSchemaItem
|
||||
{
|
||||
OB_UNIS_VERSION(1);
|
||||
public:
|
||||
ObImportSimpleSchemaItem() :
|
||||
ObIImportSchemaItem(ITEM_TYPE),
|
||||
name_()
|
||||
{}
|
||||
|
||||
ObImportSimpleSchemaItem(common::ObNameCaseMode mode, const char *name, const int64_t len) :
|
||||
ObIImportSchemaItem(ITEM_TYPE, mode),
|
||||
name_(len, name)
|
||||
{}
|
||||
|
||||
virtual void reset() override;
|
||||
virtual bool is_valid() const override;
|
||||
virtual bool case_mode_equal(const ObIImportItem &other) const override;
|
||||
virtual int64_t get_format_serialize_size() const override;
|
||||
virtual int format_serialize(
|
||||
char *buf,
|
||||
const int64_t buf_len,
|
||||
int64_t &pos) const override;
|
||||
|
||||
virtual int deep_copy(common::ObIAllocator &allocator, const ObIImportItem &src);
|
||||
|
||||
using ObIImportSchemaItem::format_serialize;
|
||||
int assign(const ObImportSimpleSchemaItem &other);
|
||||
|
||||
TO_STRING_KV(K_(mode), K_(name));
|
||||
|
||||
public:
|
||||
// "name_" is c_style string, and '\0' is not included
|
||||
// into the length.
|
||||
common::ObString name_;
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
class ObImportSchemaItemArray : public ObIImportItemFormatProvider, public ObImportItemHexFormatImpl
|
||||
{
|
||||
OB_UNIS_VERSION(1);
|
||||
public:
|
||||
ObImportSchemaItemArray() {}
|
||||
virtual int64_t get_format_serialize_size() const override;
|
||||
virtual int format_serialize(
|
||||
char *buf,
|
||||
const int64_t buf_len,
|
||||
int64_t &pos) const override;
|
||||
|
||||
virtual void reset();
|
||||
|
||||
int assign(const ObImportSchemaItemArray<T> &other);
|
||||
int add_item(const T& item);
|
||||
bool is_empty() const { return items_.empty(); }
|
||||
const common::ObSArray<T> &get_items() const { return items_; }
|
||||
bool is_exist(const T& item) const;
|
||||
bool is_exist(const T& item, const T *&out) const;
|
||||
|
||||
template<class Operator>
|
||||
int foreach(Operator &op) const
|
||||
{
|
||||
int ret = common::OB_SUCCESS;
|
||||
ARRAY_FOREACH(items_, idx) {
|
||||
const T &item = items_.at(idx);
|
||||
if (OB_FAIL(op(item))) {
|
||||
SHARE_LOG(WARN, "fail to do operator", K(ret), K(item));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
TO_STRING_KV(K_(items));
|
||||
|
||||
protected:
|
||||
common::ObArenaAllocator allocator_;
|
||||
common::ObSArray<T> items_;
|
||||
};
|
||||
|
||||
|
||||
using ObImportDatabaseItem = ObImportSimpleSchemaItem<OB_MAX_DATABASE_NAME_LENGTH, ObIImportItem::ItemType::DATABASE>;
|
||||
using ObImportTablegroupItem = ObImportSimpleSchemaItem<OB_MAX_TABLEGROUP_NAME_LENGTH, ObIImportItem::ItemType::TABLEGROUP>;
|
||||
using ObImportTablespaceItem = ObImportSimpleSchemaItem<OB_MAX_TABLESPACE_NAME_LENGTH, ObIImportItem::ItemType::TABLESPACE>;
|
||||
using ObImportDatabaseArray = ObImportSchemaItemArray<ObImportDatabaseItem>;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifndef INCLUDE_OB_IMPORT_SCHEMA_ITEM_HPP
|
||||
#define INCLUDE_OB_IMPORT_SCHEMA_ITEM_HPP
|
||||
#include "ob_import_schema_item.hpp"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
325
src/share/restore/ob_import_schema_item.hpp
Normal file
325
src/share/restore/ob_import_schema_item.hpp
Normal file
@ -0,0 +1,325 @@
|
||||
/**
|
||||
* 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 INCLUDE_OB_IMPORT_SCHEMA_ITEM_HPP
|
||||
#define INCLUDE_OB_IMPORT_SCHEMA_ITEM_HPP
|
||||
#include "share/restore/ob_import_schema_item.h"
|
||||
#include "lib/charset/ob_charset.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
// ObImportSimpleSchemaItem
|
||||
template<int64_t MAX_SIZE, ObIImportItem::ItemType ITEM_TYPE>
|
||||
int64_t ObImportSimpleSchemaItem<MAX_SIZE, ITEM_TYPE>::get_serialize_size() const
|
||||
{
|
||||
int64_t len = 0;
|
||||
len += serialization::encoded_length_vi32(mode_);
|
||||
len += name_.get_serialize_size();
|
||||
return len;
|
||||
}
|
||||
|
||||
template<int64_t MAX_SIZE, ObIImportItem::ItemType ITEM_TYPE>
|
||||
int ObImportSimpleSchemaItem<MAX_SIZE, ITEM_TYPE>::serialize(SERIAL_PARAMS) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t new_pos = pos;
|
||||
if ((NULL == buf) || (buf_len <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid arguments.", K(ret), KP(buf), K(buf_len));
|
||||
} else if (OB_FAIL(serialization::encode_vi32(buf, buf_len, new_pos, mode_))) {
|
||||
SHARE_LOG(WARN, "fail to serialize name case mode", K(ret));
|
||||
} else if (OB_FAIL(name_.serialize(buf, buf_len, new_pos))) {
|
||||
SHARE_LOG(WARN, "serialize name failed", K(ret));
|
||||
} else {
|
||||
pos = new_pos;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<int64_t MAX_SIZE, ObIImportItem::ItemType ITEM_TYPE>
|
||||
int ObImportSimpleSchemaItem<MAX_SIZE, ITEM_TYPE>::deserialize(DESERIAL_PARAMS)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t new_pos = pos;
|
||||
if ((NULL == buf) || (data_len <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid arguments.", K(ret), KP(buf), K(data_len));
|
||||
} else if (OB_FAIL(serialization::decode_vi32(buf, data_len, new_pos, ((int32_t *)(&mode_))))) {
|
||||
SHARE_LOG(WARN, "fail to deserialize name case mode, ", K(ret));
|
||||
} else if (OB_FAIL(name_.deserialize(buf, data_len, new_pos))) {
|
||||
SHARE_LOG(WARN, "deserialize name failed", K(ret));
|
||||
} else {
|
||||
pos = new_pos;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<int64_t MAX_SIZE, ObIImportItem::ItemType ITEM_TYPE>
|
||||
void ObImportSimpleSchemaItem<MAX_SIZE, ITEM_TYPE>::reset()
|
||||
{
|
||||
mode_ = common::OB_NAME_CASE_INVALID;
|
||||
name_.reset();
|
||||
}
|
||||
|
||||
template<int64_t MAX_SIZE, ObIImportItem::ItemType ITEM_TYPE>
|
||||
bool ObImportSimpleSchemaItem<MAX_SIZE, ITEM_TYPE>::is_valid() const
|
||||
{
|
||||
return common::OB_NAME_CASE_INVALID != mode_
|
||||
&& !name_.empty()
|
||||
&& 0 < name_.length()
|
||||
&& MAX_SIZE >= name_.length();
|
||||
}
|
||||
|
||||
template<int64_t MAX_SIZE, ObIImportItem::ItemType ITEM_TYPE>
|
||||
bool ObImportSimpleSchemaItem<MAX_SIZE, ITEM_TYPE>::case_mode_equal(const ObIImportItem &other) const
|
||||
{
|
||||
bool is_equal = false;
|
||||
if (get_item_type() == other.get_item_type()) {
|
||||
const ObImportSimpleSchemaItem<MAX_SIZE, ITEM_TYPE> &the_other = static_cast<const ObImportSimpleSchemaItem<MAX_SIZE, ITEM_TYPE> &>(other);
|
||||
is_equal = ObCharset::case_mode_equal(mode_, name_, the_other.name_);
|
||||
}
|
||||
return is_equal;
|
||||
}
|
||||
|
||||
template<int64_t MAX_SIZE, ObIImportItem::ItemType ITEM_TYPE>
|
||||
int64_t ObImportSimpleSchemaItem<MAX_SIZE, ITEM_TYPE>::get_format_serialize_size() const
|
||||
{
|
||||
// For example, db1 is formated as `db1`
|
||||
// Pre allocate twice the size to handle escape character.
|
||||
return name_.length() * 2 + 2;
|
||||
}
|
||||
|
||||
template<int64_t MAX_SIZE, ObIImportItem::ItemType ITEM_TYPE>
|
||||
int ObImportSimpleSchemaItem<MAX_SIZE, ITEM_TYPE>::format_serialize(
|
||||
char *buf,
|
||||
const int64_t buf_len,
|
||||
int64_t &pos) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if ((NULL == buf) || (buf_len <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid arguments.", K(ret), KP(buf), K(buf_len));
|
||||
} else if (!is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid argument", K(ret));
|
||||
} else {
|
||||
const bool skip_escape = false;
|
||||
const bool do_oracle_mode_escape = false;
|
||||
int64_t string_size = 0;
|
||||
common::ObHexEscapeSqlStr hex_escape_name(name_, skip_escape, do_oracle_mode_escape);
|
||||
if (OB_FAIL(databuff_printf(buf, buf_len, pos, "%s", "`"))) {
|
||||
SHARE_LOG(WARN, "fail to format str", K(ret), K(pos), K(buf_len));
|
||||
} else if (OB_FALSE_IT(string_size = hex_escape_name.to_string(buf + pos, buf_len - pos))) {
|
||||
} else if (OB_FALSE_IT(pos += string_size)) {
|
||||
} else if (OB_FAIL(databuff_printf(buf, buf_len, pos, "%s", "`"))) {
|
||||
SHARE_LOG(WARN, "fail to format str", K(ret), K(pos), K(buf_len));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<int64_t MAX_SIZE, ObIImportItem::ItemType ITEM_TYPE>
|
||||
int ObImportSimpleSchemaItem<MAX_SIZE, ITEM_TYPE>::deep_copy(common::ObIAllocator &allocator, const ObIImportItem &src)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!src.is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid argument", K(ret), K(src));
|
||||
} else if (get_item_type() != src.get_item_type()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "item type not match", K(ret), "src", src.get_item_type(), "dest", get_item_type());
|
||||
} else {
|
||||
const ObImportSimpleSchemaItem<MAX_SIZE, ITEM_TYPE> &other = static_cast<const ObImportSimpleSchemaItem<MAX_SIZE, ITEM_TYPE> &>(src);
|
||||
if (OB_FAIL(ob_write_string(allocator, other.name_, name_))) {
|
||||
SHARE_LOG(WARN, "failed to copy item", K(ret), K(other));
|
||||
} else {
|
||||
mode_ = other.mode_;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<int64_t MAX_SIZE, ObIImportItem::ItemType ITEM_TYPE>
|
||||
int ObImportSimpleSchemaItem<MAX_SIZE, ITEM_TYPE>::assign(const ObImportSimpleSchemaItem &other)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!other.is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid argument", K(ret), K(other));
|
||||
} else {
|
||||
mode_ = other.mode_;
|
||||
name_ = other.name_;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// ObImportSchemaItemArray
|
||||
OB_DEF_SERIALIZE_SIZE(ObImportSchemaItemArray<T>, template <typename T>)
|
||||
{
|
||||
return items_.get_serialize_size();
|
||||
}
|
||||
|
||||
OB_DEF_SERIALIZE(ObImportSchemaItemArray<T>, template <typename T>)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if ((NULL == buf) || (buf_len <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid argument", K(ret), KP(buf), K(buf_len), K(pos));
|
||||
} else if (OB_FAIL(items_.serialize(buf, buf_len, pos))) {
|
||||
SHARE_LOG(WARN, "failed to serialize", K(ret), KP(buf), K(buf_len), K(pos));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
OB_DEF_DESERIALIZE(ObImportSchemaItemArray<T>, template <typename T>)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
common::ObSArray<T> tmp_items;
|
||||
if ((NULL == buf) || (data_len <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid argument", K(ret), KP(buf), K(data_len), K(pos));
|
||||
} else if (OB_FALSE_IT(reset())) {
|
||||
} else if (OB_FAIL(tmp_items.deserialize(buf, data_len, pos))) {
|
||||
SHARE_LOG(WARN, "failed to deserialize", K(ret), KP(buf), K(data_len), K(pos));
|
||||
}
|
||||
ARRAY_FOREACH(tmp_items, idx) {
|
||||
const T &item = tmp_items.at(idx);
|
||||
if (OB_FAIL(add_item(item))) {
|
||||
SHARE_LOG(WARN, "failed to add item", K(ret), K(idx), K(item));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int64_t ObImportSchemaItemArray<T>::get_format_serialize_size() const
|
||||
{
|
||||
int64_t size = 1; // include '\0'
|
||||
ARRAY_FOREACH_NORET(items_, idx) {
|
||||
const T &item = items_.at(idx);
|
||||
// item is concatenated with ','
|
||||
size += 0 == idx ? 0 : 1;
|
||||
size += item.get_format_serialize_size();
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int ObImportSchemaItemArray<T>::format_serialize(
|
||||
char *buf,
|
||||
const int64_t buf_len,
|
||||
int64_t &pos) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t new_pos = pos;
|
||||
if ((NULL == buf) || (buf_len <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid arguments.", K(ret), KP(buf), K(buf_len));
|
||||
} else if (items_.empty()) {
|
||||
buf[new_pos++] = 0;
|
||||
}
|
||||
|
||||
ARRAY_FOREACH(items_, idx) {
|
||||
const T &item = items_.at(idx);
|
||||
// concatenated items with ','
|
||||
if (0 < idx && OB_FAIL(databuff_printf(buf, buf_len, new_pos, "%s", ","))) {
|
||||
SHARE_LOG(WARN, "fail to format str", K(ret), K(new_pos), K(buf_len));
|
||||
} else if (OB_FAIL(item.format_serialize(buf, buf_len, new_pos))) {
|
||||
SHARE_LOG(WARN, "fail to format str", K(ret), K(new_pos), K(buf_len));
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
pos = new_pos;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void ObImportSchemaItemArray<T>::reset()
|
||||
{
|
||||
items_.reset();
|
||||
allocator_.reset();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int ObImportSchemaItemArray<T>::assign(const ObImportSchemaItemArray<T> &other)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const common::ObSArray<T> &items = other.get_items();
|
||||
|
||||
reset();
|
||||
ARRAY_FOREACH(items, idx) {
|
||||
const T &item = items.at(idx);
|
||||
if (OB_FAIL(add_item(item))) {
|
||||
SHARE_LOG(WARN, "failed to add item", K(ret), K(idx), K(item));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int ObImportSchemaItemArray<T>::add_item(const T& item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
T tmp_item;
|
||||
if (!item.is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid argument", K(ret), K(item));
|
||||
} else if (OB_FAIL(tmp_item.deep_copy(allocator_, item))) {
|
||||
SHARE_LOG(WARN, "failed to copy item", K(ret), K(item));
|
||||
} else if (OB_FAIL(items_.push_back(tmp_item))) {
|
||||
SHARE_LOG(WARN, "failed to push back item", K(ret), K(item));
|
||||
} else {
|
||||
SHARE_LOG(INFO, "add one item", K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
bool ObImportSchemaItemArray<T>::is_exist(const T& item) const
|
||||
{
|
||||
bool ret = false;
|
||||
const T *out = NULL;
|
||||
ret = is_exist(item, out);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool ObImportSchemaItemArray<T>::is_exist(const T& item, const T *&out) const
|
||||
{
|
||||
bool ret = false;
|
||||
ARRAY_FOREACH_NORET(items_, idx) {
|
||||
const T &tmp = items_.at(idx);
|
||||
if (tmp == item) {
|
||||
ret = true;
|
||||
out = &tmp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
288
src/share/restore/ob_import_table_arg.cpp
Normal file
288
src/share/restore/ob_import_table_arg.cpp
Normal file
@ -0,0 +1,288 @@
|
||||
/**
|
||||
* 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_import_table_arg.h"
|
||||
#include "lib/string/ob_sql_string.h"
|
||||
#include "lib/oblog/ob_log_module.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
// ObImportTableArg
|
||||
OB_SERIALIZE_MEMBER(
|
||||
ObImportTableArg,
|
||||
is_import_all_,
|
||||
database_array_,
|
||||
table_array_,
|
||||
partition_array_);
|
||||
|
||||
ObImportTableArg::ObImportTableArg()
|
||||
: is_import_all_(false),
|
||||
database_array_(),
|
||||
table_array_(),
|
||||
partition_array_()
|
||||
{}
|
||||
|
||||
int ObImportTableArg::set_import_all()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
is_import_all_ = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ObImportTableArg::reset()
|
||||
{
|
||||
is_import_all_ = false;
|
||||
database_array_.reset();
|
||||
table_array_.reset();
|
||||
partition_array_.reset();
|
||||
}
|
||||
|
||||
int ObImportTableArg::assign(const ObImportTableArg &other)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(database_array_.assign(other.get_import_database_array()))) {
|
||||
LOG_WARN("failed to assign database array", K(ret), "database array", other.get_import_database_array());
|
||||
} else if (OB_FAIL(table_array_.assign(other.get_import_table_array()))) {
|
||||
LOG_WARN("failed to assign database array", K(ret), "table array", other.get_import_table_array());
|
||||
} else if (OB_FAIL(partition_array_.assign(other.get_import_partition_array()))) {
|
||||
LOG_WARN("failed to assign database array", K(ret), "partition array", other.get_import_partition_array());
|
||||
} else {
|
||||
is_import_all_ = other.is_import_all();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableArg::add_database(const ObImportDatabaseItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObImportDatabaseItem *dup_db_item = NULL;
|
||||
const ObImportTableItem *dup_table_item = NULL;
|
||||
common::ObArenaAllocator allocator;
|
||||
ObString source_err_str;
|
||||
ObString target_err_str;
|
||||
|
||||
if (database_array_.is_exist(item, dup_db_item)) {
|
||||
if (OB_FAIL(dup_db_item->format_serialize(allocator, source_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), KPC(dup_db_item));
|
||||
} else if (OB_FAIL(item.format_serialize(allocator, target_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), K(item));
|
||||
} else {
|
||||
ret = OB_BACKUP_CONFLICT_VALUE;
|
||||
LOG_WARN("input database is conflict", K(ret), K(item), KPC(dup_db_item));
|
||||
LOG_USER_ERROR(OB_BACKUP_CONFLICT_VALUE, target_err_str.length(), target_err_str.ptr(), source_err_str.length(), source_err_str.ptr());
|
||||
}
|
||||
} else if (table_array_.is_exist_table_in_database(item, dup_table_item)) {
|
||||
if (OB_FAIL(dup_table_item->format_serialize(allocator, source_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), KPC(dup_table_item));
|
||||
} else if (OB_FAIL(item.format_serialize(allocator, target_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), K(item));
|
||||
} else {
|
||||
ret = OB_BACKUP_CONFLICT_VALUE;
|
||||
LOG_WARN("input database is conflict", K(ret), K(item), KPC(dup_db_item));
|
||||
LOG_USER_ERROR(OB_BACKUP_CONFLICT_VALUE, target_err_str.length(), target_err_str.ptr(), source_err_str.length(), source_err_str.ptr());
|
||||
}
|
||||
} else if (OB_FAIL(database_array_.add_item(item))) {
|
||||
LOG_WARN("failed to add table", K(ret), K(item));
|
||||
} else {
|
||||
LOG_INFO("add one database", K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableArg::add_table(const ObImportTableItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const ObImportDatabaseItem *dup_db_item = NULL;
|
||||
const ObImportTableItem *dup_table_item = NULL;
|
||||
common::ObArenaAllocator allocator;
|
||||
ObString source_err_str;
|
||||
ObString target_err_str;
|
||||
const ObImportDatabaseItem db_item = item.get_database();
|
||||
if (database_array_.is_exist(db_item, dup_db_item)) {
|
||||
if (OB_FAIL(dup_db_item->format_serialize(allocator, source_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), KPC(dup_db_item));
|
||||
} else if (OB_FAIL(item.format_serialize(allocator, target_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), K(item));
|
||||
} else {
|
||||
ret = OB_BACKUP_CONFLICT_VALUE;
|
||||
LOG_WARN("input table is conflict", K(ret), K(item), KPC(dup_db_item));
|
||||
LOG_USER_ERROR(OB_BACKUP_CONFLICT_VALUE, target_err_str.length(), target_err_str.ptr(), source_err_str.length(), source_err_str.ptr());
|
||||
}
|
||||
} else if (table_array_.is_exist(item, dup_table_item)) {
|
||||
if (OB_FAIL(dup_table_item->format_serialize(allocator, source_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), KPC(dup_table_item));
|
||||
} else if (OB_FAIL(item.format_serialize(allocator, target_err_str))) {
|
||||
LOG_WARN("failed to format serialize", K(ret), K(item));
|
||||
} else {
|
||||
ret = OB_BACKUP_CONFLICT_VALUE;
|
||||
LOG_WARN("input table is conflict", K(ret), K(item), KPC(dup_db_item));
|
||||
LOG_USER_ERROR(OB_BACKUP_CONFLICT_VALUE, target_err_str.length(), target_err_str.ptr(), source_err_str.length(), source_err_str.ptr());
|
||||
}
|
||||
} else if (OB_FAIL(table_array_.add_item(item))) {
|
||||
LOG_WARN("failed to add table", K(ret), K(item));
|
||||
} else {
|
||||
LOG_INFO("add one table", K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableArg::add_partition(const ObImportPartitionItem &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
bool is_dup = false;
|
||||
ObSqlString dup_item;
|
||||
if (OB_FAIL(check_partion_dup(item, is_dup, dup_item))) {
|
||||
LOG_WARN("failed to check able dup", K(ret), K(item));
|
||||
} else if (is_dup) {
|
||||
ret = OB_ENTRY_EXIST;
|
||||
LOG_WARN("duplicate partition", K(ret), K(item));
|
||||
LOG_USER_ERROR(OB_ENTRY_EXIST, dup_item.ptr());
|
||||
} else if (OB_FAIL(partition_array_.add_item(item))) {
|
||||
LOG_WARN("failed to add table", K(ret), K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableArg::check_database_dup(const ObImportDatabaseItem &item, bool &is_dup, ObSqlString &dup_item) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
is_dup = false;
|
||||
if (database_array_.is_exist(item)) {
|
||||
is_dup = true;
|
||||
if (OB_FAIL(dup_item.assign_fmt("duplicate recover database, %.*s", item.name_.length(), item.name_.ptr()))) {
|
||||
LOG_WARN("failed to assign fmt", K(ret));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int ObImportTableArg::check_table_dup(const ObImportTableItem &item, bool &is_dup, ObSqlString &dup_item) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
is_dup = false;
|
||||
if (table_array_.is_exist(item)) {
|
||||
is_dup = true;
|
||||
if (OB_FAIL(dup_item.assign_fmt("duplicate recover table, %.*s.%.*s",
|
||||
item.database_name_.length(), item.database_name_.ptr(),
|
||||
item.table_name_.length(), item.table_name_.ptr()))) {
|
||||
LOG_WARN("failed to assign fmt", K(ret));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int ObImportTableArg::check_partion_dup(const ObImportPartitionItem &item, bool &is_dup, ObSqlString &dup_item) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
is_dup = false;
|
||||
if (partition_array_.is_exist(item)) {
|
||||
is_dup = true;
|
||||
if (OB_FAIL(dup_item.assign_fmt("duplicate recover partition, %.*s.%.*s:%.*s",
|
||||
item.database_name_.length(), item.database_name_.ptr(),
|
||||
item.table_name_.length(), item.table_name_.ptr(),
|
||||
item.partition_name_.length(), item.partition_name_.ptr()))) {
|
||||
LOG_WARN("failed to assign fmt", K(ret));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableArg::get_db_list_format_str(
|
||||
common::ObIAllocator &allocator, common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_item_array_format_str_(database_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get import database list format str", K(ret), K_(database_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableArg::get_table_list_format_str(
|
||||
common::ObIAllocator &allocator, common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_item_array_format_str_(table_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get import table list format str", K(ret), K_(table_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableArg::get_partition_list_format_str(
|
||||
common::ObIAllocator &allocator, common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_item_array_format_str_(partition_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get import partition list format str", K(ret), K_(partition_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ObImportTableArg::get_db_list_hex_format_str(
|
||||
common::ObIAllocator &allocator, common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_item_array_hex_format_str_(database_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get import database list hex format str", K(ret), K_(database_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableArg::get_table_list_hex_format_str(
|
||||
common::ObIAllocator &allocator, common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_item_array_hex_format_str_(table_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get import table list hex format str", K(ret), K_(table_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableArg::get_partition_list_hex_format_str(
|
||||
common::ObIAllocator &allocator, common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(get_item_array_hex_format_str_(partition_array_, allocator, str))) {
|
||||
LOG_WARN("failed to get import partition list hex format str", K(ret), K_(partition_array));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableArg::db_list_deserialize_hex_format_str(const common::ObString &str)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(item_array_deserialize_hex_format_str_(database_array_, str))) {
|
||||
LOG_WARN("fail to deserialize hex format import database array", K(ret), K(str));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableArg::table_list_deserialize_hex_format_str(const common::ObString &str)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(item_array_deserialize_hex_format_str_(table_array_, str))) {
|
||||
LOG_WARN("fail to deserialize hex format import table array", K(ret), K(str));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableArg::partition_list_deserialize_hex_format_str(const common::ObString &str)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(item_array_deserialize_hex_format_str_(partition_array_, str))) {
|
||||
LOG_WARN("fail to deserialize hex format import partition array", K(ret), K(str));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
156
src/share/restore/ob_import_table_arg.h
Normal file
156
src/share/restore/ob_import_table_arg.h
Normal file
@ -0,0 +1,156 @@
|
||||
/**
|
||||
* 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 OCEANBASE_SHARE_IMPORT_TABLE_ARG_H
|
||||
#define OCEANBASE_SHARE_IMPORT_TABLE_ARG_H
|
||||
|
||||
#include "lib/ob_define.h"
|
||||
#include "share/restore/ob_import_table_item.h"
|
||||
#include "share/restore/ob_import_partition_item.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
|
||||
class ObImportTableArg final
|
||||
{
|
||||
OB_UNIS_VERSION(1);
|
||||
public:
|
||||
ObImportTableArg();
|
||||
void reset();
|
||||
int assign(const ObImportTableArg &other);
|
||||
int set_import_all();
|
||||
bool is_import_all() const { return is_import_all_; }
|
||||
const ObImportDatabaseArray &get_import_database_array() const { return database_array_; }
|
||||
const ObImportTableArray &get_import_table_array() const { return table_array_; }
|
||||
const ObImportPartitionArray &get_import_partition_array() const { return partition_array_; }
|
||||
ObImportDatabaseArray &get_import_database_array() { return database_array_; }
|
||||
ObImportTableArray &get_import_table_array() { return table_array_; }
|
||||
ObImportPartitionArray &get_import_partition_array() { return partition_array_; }
|
||||
int add_database(const ObImportDatabaseItem &item);
|
||||
int add_table(const ObImportTableItem &item);
|
||||
int add_partition(const ObImportPartitionItem &item);
|
||||
int check_database_dup(const ObImportDatabaseItem &item, bool &is_dup, ObSqlString &dup_item) const;
|
||||
int check_table_dup(const ObImportTableItem &item, bool &is_dup, ObSqlString &dup_item) const;
|
||||
int check_partion_dup(const ObImportPartitionItem &item, bool &is_dup, ObSqlString &dup_item) const;
|
||||
int get_db_list_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
int get_table_list_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
int get_partition_list_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
int get_db_list_hex_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
int get_table_list_hex_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
int get_partition_list_hex_format_str(common::ObIAllocator &allocator, common::ObString &str) const;
|
||||
|
||||
int db_list_deserialize_hex_format_str(const common::ObString &str);
|
||||
int table_list_deserialize_hex_format_str(const common::ObString &str);
|
||||
int partition_list_deserialize_hex_format_str(const common::ObString &str);
|
||||
|
||||
TO_STRING_KV(K_(is_import_all), K_(database_array), K_(table_array), K_(partition_array));
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
int get_item_array_format_str_(
|
||||
const T &array,
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const;
|
||||
|
||||
template <typename T>
|
||||
int get_item_array_hex_format_str_(
|
||||
const T &array,
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const;
|
||||
|
||||
template <typename T>
|
||||
int item_array_deserialize_hex_format_str_(
|
||||
T& array,
|
||||
const common::ObString &str);
|
||||
|
||||
private:
|
||||
bool is_import_all_;
|
||||
ObImportDatabaseArray database_array_;
|
||||
ObImportTableArray table_array_;
|
||||
ObImportPartitionArray partition_array_;
|
||||
DISALLOW_COPY_AND_ASSIGN(ObImportTableArg);
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
int ObImportTableArg::get_item_array_format_str_(
|
||||
const T &array,
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t pos = 0;
|
||||
int64_t str_buf_len = array.get_format_serialize_size();
|
||||
char *str_buf = NULL;
|
||||
|
||||
if (str_buf_len >= OB_MAX_LONGTEXT_LENGTH) {
|
||||
ret = OB_SIZE_OVERFLOW;
|
||||
SHARE_LOG(WARN, "format str is too long", K(ret), K(str_buf_len));
|
||||
} else if (OB_ISNULL(str_buf = static_cast<char *>(allocator.alloc(str_buf_len)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
SHARE_LOG(WARN, "fail to alloc buf", K(ret), K(str_buf_len));
|
||||
} else if (OB_FAIL(array.format_serialize(str_buf, str_buf_len, pos))) {
|
||||
SHARE_LOG(WARN, "fail to format import item array", K(ret), K(pos), K(str_buf_len));
|
||||
} else {
|
||||
str.assign_ptr(str_buf, str_buf_len);
|
||||
SHARE_LOG(INFO, "get format import item array str", K(str));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int ObImportTableArg::get_item_array_hex_format_str_(
|
||||
const T &array,
|
||||
common::ObIAllocator &allocator,
|
||||
common::ObString &str) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t pos = 0;
|
||||
int64_t str_buf_len = array.get_hex_format_serialize_size();
|
||||
char *str_buf = NULL;
|
||||
|
||||
if (str_buf_len >= OB_MAX_LONGTEXT_LENGTH) {
|
||||
ret = OB_SIZE_OVERFLOW;
|
||||
SHARE_LOG(WARN, "hex format str is too long", K(ret), K(str_buf_len));
|
||||
} else if (OB_ISNULL(str_buf = static_cast<char *>(allocator.alloc(str_buf_len)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
SHARE_LOG(WARN, "fail to alloc buf", K(ret), K(str_buf_len));
|
||||
} else if (OB_FAIL(array.hex_format_serialize(str_buf, str_buf_len, pos))) {
|
||||
SHARE_LOG(WARN, "fail to hex format import item array", K(ret), K(pos), K(str_buf_len));
|
||||
} else {
|
||||
str.assign_ptr(str_buf, str_buf_len);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
int ObImportTableArg::item_array_deserialize_hex_format_str_(
|
||||
T& array,
|
||||
const common::ObString &str)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t pos = 0;
|
||||
if (OB_FAIL(array.hex_format_deserialize(str.ptr(), str.length(), pos))) {
|
||||
SHARE_LOG(WARN, "fail to deserialize hex format import item array", K(ret), K(str));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
164
src/share/restore/ob_import_table_item.cpp
Normal file
164
src/share/restore/ob_import_table_item.cpp
Normal file
@ -0,0 +1,164 @@
|
||||
/**
|
||||
* 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_import_table_item.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
|
||||
// ObImportTableItem
|
||||
OB_SERIALIZE_MEMBER(ObImportTableItem, mode_, database_name_, table_name_);
|
||||
|
||||
void ObImportTableItem::reset()
|
||||
{
|
||||
mode_ = common::OB_NAME_CASE_INVALID;
|
||||
database_name_.reset();
|
||||
table_name_.reset();
|
||||
}
|
||||
|
||||
bool ObImportTableItem::is_valid() const
|
||||
{
|
||||
return common::OB_NAME_CASE_INVALID != mode_
|
||||
&& !database_name_.empty()
|
||||
&& !table_name_.empty();
|
||||
}
|
||||
|
||||
bool ObImportTableItem::case_mode_equal(const ObIImportItem &other) const
|
||||
{
|
||||
bool is_equal = false;
|
||||
if (get_item_type() == other.get_item_type()) {
|
||||
const ObImportTableItem &dest = static_cast<const ObImportTableItem &>(other);
|
||||
is_equal = ObCharset::case_mode_equal(mode_, database_name_, dest.database_name_)
|
||||
&& ObCharset::case_mode_equal(mode_, table_name_, dest.table_name_);
|
||||
}
|
||||
return is_equal;
|
||||
}
|
||||
|
||||
int64_t ObImportTableItem::get_format_serialize_size() const
|
||||
{
|
||||
// For example, database name is SH, and table name is SALES.
|
||||
// The format string is `SH`.`SALES`.
|
||||
// Pre allocate twice the size to handle escape character.
|
||||
int64_t size = 0;
|
||||
size += database_name_.length() * 2;
|
||||
size += table_name_.length() * 2;
|
||||
size += 5;
|
||||
return size;
|
||||
}
|
||||
|
||||
int ObImportTableItem::format_serialize(
|
||||
char *buf,
|
||||
const int64_t buf_len,
|
||||
int64_t &pos) const
|
||||
{
|
||||
// For example, database name is SH, and table name is SALES.
|
||||
// The format string is `SH`.`SALES`.
|
||||
int ret = OB_SUCCESS;
|
||||
if ((NULL == buf) || (buf_len <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid arguments.", K(ret), KP(buf), K(buf_len));
|
||||
} else if (!is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret));
|
||||
} else {
|
||||
const bool skip_escape = false;
|
||||
const bool do_oracle_mode_escape = false;
|
||||
int64_t string_size = 0;
|
||||
common::ObHexEscapeSqlStr hex_escape_db_name(database_name_, skip_escape, do_oracle_mode_escape);
|
||||
common::ObHexEscapeSqlStr hex_escape_table_name(table_name_, skip_escape, do_oracle_mode_escape);
|
||||
if (OB_FAIL(databuff_printf(buf, buf_len, pos, "%s", "`"))) {
|
||||
LOG_WARN("fail to format str", K(ret), K(pos), K(buf_len));
|
||||
} else if (OB_FALSE_IT(string_size = hex_escape_db_name.to_string(buf + pos, buf_len - pos))) {
|
||||
} else if (OB_FALSE_IT(pos += string_size)) {
|
||||
} else if (OB_FAIL(databuff_printf(buf, buf_len, pos, "%s", "`.`"))) {
|
||||
LOG_WARN("fail to format str", K(ret), K(pos), K(buf_len));
|
||||
} else if (OB_FALSE_IT(string_size = hex_escape_table_name.to_string(buf + pos, buf_len - pos))) {
|
||||
} else if (OB_FALSE_IT(pos += string_size)) {
|
||||
} else if (OB_FAIL(databuff_printf(buf, buf_len, pos, "%s", "`"))) {
|
||||
LOG_WARN("fail to format str", K(ret), K(pos), K(buf_len));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableItem::deep_copy(common::ObIAllocator &allocator, const ObIImportItem &src)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!src.is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(src));
|
||||
} else if (get_item_type() != src.get_item_type()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("item type not match", K(ret), "src", src.get_item_type(), "dest", get_item_type());
|
||||
} else {
|
||||
const ObImportTableItem &other = static_cast<const ObImportTableItem &>(src);
|
||||
if (OB_FAIL(ob_write_string(allocator, other.database_name_, database_name_))) {
|
||||
LOG_WARN("failed to copy item", K(ret), K(other));
|
||||
} else if (OB_FAIL(ob_write_string(allocator, other.table_name_, table_name_))) {
|
||||
LOG_WARN("failed to copy item", K(ret), K(other));
|
||||
} else {
|
||||
mode_ = other.mode_;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableItem::assign(const ObImportTableItem &other)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!other.is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(other));
|
||||
} else {
|
||||
mode_ = other.mode_;
|
||||
database_name_ = other.database_name_;
|
||||
table_name_ = other.table_name_;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ObImportTableItem::is_database_equal(const ObImportDatabaseItem &other) const
|
||||
{
|
||||
const ObImportDatabaseItem db_item = get_database();
|
||||
return db_item == other;
|
||||
}
|
||||
|
||||
const ObImportDatabaseItem ObImportTableItem::get_database() const
|
||||
{
|
||||
ObImportDatabaseItem db_item;
|
||||
db_item.name_ = database_name_;
|
||||
db_item.mode_ = mode_;
|
||||
return db_item;
|
||||
}
|
||||
|
||||
// ObImportTableArray
|
||||
bool ObImportTableArray::is_exist_table_in_database(const ObImportDatabaseItem &db_item, const ObImportTableItem *&out) const
|
||||
{
|
||||
bool ret = false;
|
||||
ARRAY_FOREACH_NORET(items_, idx) {
|
||||
const ObImportTableItem &table_item = items_.at(idx);
|
||||
if (table_item.is_database_equal(db_item)) {
|
||||
ret = true;
|
||||
out = &table_item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
76
src/share/restore/ob_import_table_item.h
Normal file
76
src/share/restore/ob_import_table_item.h
Normal file
@ -0,0 +1,76 @@
|
||||
/**
|
||||
* 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 OCEANBASE_SHARE_IMPORT_TABLE_ITEM_H
|
||||
#define OCEANBASE_SHARE_IMPORT_TABLE_ITEM_H
|
||||
|
||||
#include "share/restore/ob_import_schema_item.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
|
||||
struct ObImportTableItem final : public ObIImportSchemaItem
|
||||
{
|
||||
OB_UNIS_VERSION(1);
|
||||
public:
|
||||
ObImportTableItem() :
|
||||
ObIImportSchemaItem(ItemType::TABLE),
|
||||
database_name_(),
|
||||
table_name_()
|
||||
{}
|
||||
|
||||
ObImportTableItem(common::ObNameCaseMode mode, const char *db_name, const int64_t db_len,
|
||||
const char *table_name, const int64_t table_len) :
|
||||
ObIImportSchemaItem(ItemType::TABLE, mode),
|
||||
database_name_(db_len, db_name),
|
||||
table_name_(table_len, table_name)
|
||||
{}
|
||||
|
||||
virtual void reset() override;
|
||||
virtual bool is_valid() const override;
|
||||
virtual bool case_mode_equal(const ObIImportItem &other) const override;
|
||||
// ignore case
|
||||
virtual int64_t get_format_serialize_size() const override;
|
||||
virtual int format_serialize(
|
||||
char *buf,
|
||||
const int64_t buf_len,
|
||||
int64_t &pos) const override;
|
||||
|
||||
virtual int deep_copy(common::ObIAllocator &allocator, const ObIImportItem &src) override;
|
||||
|
||||
using ObIImportSchemaItem::format_serialize;
|
||||
int assign(const ObImportTableItem &other);
|
||||
bool is_database_equal(const ObImportDatabaseItem &other) const;
|
||||
const ObImportDatabaseItem get_database() const;
|
||||
|
||||
TO_STRING_KV(K_(mode), K_(database_name), K_(table_name));
|
||||
|
||||
public:
|
||||
// The following 2 names both are c_style string, and '\0' is not included
|
||||
// into the length.
|
||||
common::ObString database_name_;
|
||||
common::ObString table_name_;
|
||||
};
|
||||
|
||||
|
||||
class ObImportTableArray final : public ObImportSchemaItemArray<ObImportTableItem>
|
||||
{
|
||||
public:
|
||||
bool is_exist_table_in_database(const ObImportDatabaseItem &db_item, const ObImportTableItem *&out) const;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
488
src/share/restore/ob_import_table_persist_helper.cpp
Normal file
488
src/share/restore/ob_import_table_persist_helper.cpp
Normal file
@ -0,0 +1,488 @@
|
||||
/**
|
||||
* 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 "ob_import_table_persist_helper.h"
|
||||
#include "ob_import_table_struct.h"
|
||||
#include "share/inner_table/ob_inner_table_schema_constants.h"
|
||||
|
||||
using namespace oceanbase;
|
||||
using namespace share;
|
||||
ObImportTableJobPersistHelper::ObImportTableJobPersistHelper()
|
||||
: is_inited_(false), tenant_id_(), table_op_()
|
||||
{
|
||||
}
|
||||
|
||||
int ObImportTableJobPersistHelper::init(const uint64_t tenant_id)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if(!is_sys_tenant(tenant_id) && !is_user_tenant(tenant_id)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid tenant id", K(ret), K(tenant_id));
|
||||
} else if (OB_FAIL(table_op_.init(OB_ALL_IMPORT_TABLE_JOB_TNAME, *this))) {
|
||||
LOG_WARN("failed to init table op", K(ret));
|
||||
} else {
|
||||
tenant_id_ = tenant_id;
|
||||
is_inited_ = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ObImportTableJobPersistHelper::insert_import_table_job(
|
||||
common::ObISQLClient &proxy, const ObImportTableJob &job) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t affect_rows = 0;
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObRecoverTablePersistHelper not init", K(ret));
|
||||
} else if (OB_FAIL(table_op_.insert_or_update_row(proxy, job, affect_rows))) {
|
||||
LOG_WARN("failed to insert or update row", K(ret), K(job));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableJobPersistHelper::get_import_table_job(
|
||||
common::ObISQLClient &proxy, const uint64_t tenant_id, const int64_t job_id, ObImportTableJob &job) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObImportTableJob::Key key;
|
||||
key.tenant_id_ = tenant_id;
|
||||
key.job_id_ = job_id;
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObImportTableJobPersistHelper not init", K(ret));
|
||||
} else if (OB_FAIL(table_op_.get_row(proxy, false, key, job))) {
|
||||
LOG_WARN("failed to get row", KR(ret), K(key));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableJobPersistHelper::get_all_import_table_jobs(
|
||||
common::ObISQLClient &proxy, common::ObIArray<ObImportTableJob> &jobs) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
const uint64_t exec_tenant_id = get_exec_tenant_id();
|
||||
jobs.reset();
|
||||
if (OB_FAIL(sql.assign_fmt("select * from %s", OB_ALL_IMPORT_TABLE_JOB_TNAME))) {
|
||||
LOG_WARN("fail to assign sql", K(ret));
|
||||
} else {
|
||||
HEAP_VAR(ObMySQLProxy::ReadResult, res) {
|
||||
ObMySQLResult *result = NULL;
|
||||
if (OB_FAIL(proxy.read(res, exec_tenant_id, sql.ptr()))) {
|
||||
LOG_WARN("failed to exec sql", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else if (OB_ISNULL(result = res.get_result())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("result is null", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else {
|
||||
while (OB_SUCC(ret)) {
|
||||
ObImportTableJob job;
|
||||
job.reset();
|
||||
if (OB_FAIL(result->next())) {
|
||||
if (OB_ITER_END == ret) {
|
||||
ret = OB_SUCCESS;
|
||||
break;
|
||||
} else {
|
||||
LOG_WARN("failed to get next row", K(ret));
|
||||
}
|
||||
} else if (OB_FAIL(job.parse_from(*result))) {
|
||||
LOG_WARN("failed to parse job result", K(ret));
|
||||
} else if (OB_FAIL(jobs.push_back(job))) {
|
||||
LOG_WARN("failed to push back job", K(ret), K(job));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG_INFO("get targets", K(ret), K(jobs), K(exec_tenant_id), K(sql));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableJobPersistHelper::advance_status(
|
||||
common::ObISQLClient &proxy, const ObImportTableJob &job, const ObImportTableJobStatus &next_status) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
int64_t affected_rows = -1;
|
||||
ObDMLSqlSplicer dml;
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObImportTableJobPersistHelper not init", K(ret));
|
||||
} else if (OB_FAIL(dml.add_pk_column(OB_STR_JOB_ID, job.get_job_id()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (OB_FAIL(dml.add_pk_column(OB_STR_TENANT_ID, job.get_tenant_id()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (next_status.is_finish() && OB_FAIL(dml.add_column(OB_STR_RESULT, job.get_result().get_result_str()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (next_status.is_finish() && OB_FAIL(dml.add_column(OB_STR_COMMENT, job.get_result().get_comment()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (next_status.is_finish() && OB_FAIL(dml.add_column(OB_STR_END_TS, job.get_end_ts()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (OB_FAIL(dml.add_column(OB_STR_STATUS, next_status.get_str()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (OB_FAIL(dml.splice_update_sql(OB_ALL_IMPORT_TABLE_JOB_TNAME, sql))) {
|
||||
LOG_WARN("failed to splice update sql", K(ret));
|
||||
} else if (OB_FAIL(sql.append_fmt(" and %s='%s'", OB_STR_STATUS, job.get_status().get_str()))) {
|
||||
LOG_WARN("failed to append fmt", K(ret));
|
||||
} else if (OB_FAIL(proxy.write(get_exec_tenant_id(), sql.ptr(), affected_rows))) {
|
||||
LOG_WARN("failed to write", K(ret), K(sql));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableJobPersistHelper::force_cancel_import_job(common::ObISQLClient &proxy) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
int64_t affected_rows = -1;
|
||||
ObDMLSqlSplicer dml;
|
||||
ObRecoverTableStatus status(ObRecoverTableStatus::CANCELING);
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObImportTableJobPersistHelper not init", K(ret));
|
||||
} else if (OB_FAIL(dml.add_pk_column(OB_STR_TENANT_ID, tenant_id_))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (OB_FAIL(dml.add_column(OB_STR_STATUS, status.get_str()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (OB_FAIL(dml.splice_update_sql(OB_ALL_IMPORT_TABLE_JOB_TNAME, sql))) {
|
||||
LOG_WARN("failed to splice update sql", K(ret));
|
||||
} else if (OB_FAIL(proxy.write(get_exec_tenant_id(), sql.ptr(), affected_rows))) {
|
||||
LOG_WARN("failed to exec sql", K(ret), K(sql));
|
||||
} else {
|
||||
LOG_INFO("success cancel import job", K(tenant_id_));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableJobPersistHelper::move_import_job_to_history(
|
||||
common::ObISQLClient &proxy, const uint64_t tenant_id, const int64_t job_id) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
int64_t affected_rows = -1;
|
||||
if (tenant_id == OB_INVALID_TENANT_ID || job_id <= 0) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(tenant_id), K(job_id));
|
||||
} else if (OB_FAIL(sql.assign_fmt(
|
||||
"insert into %s select * from %s where %s=%lu",
|
||||
OB_ALL_IMPORT_TABLE_JOB_HISTORY_TNAME, OB_ALL_IMPORT_TABLE_JOB_TNAME,
|
||||
OB_STR_JOB_ID, job_id))) {
|
||||
LOG_WARN("failed to init sql", K(ret));
|
||||
} else if (OB_FAIL(proxy.write(gen_meta_tenant_id(tenant_id), sql.ptr(), affected_rows))) {
|
||||
LOG_WARN("failed to exec sql", K(ret), K(sql));
|
||||
} else if (OB_FALSE_IT(sql.reset())) {
|
||||
} else if (OB_FAIL(sql.assign_fmt("delete from %s where %s=%lu",
|
||||
OB_ALL_IMPORT_TABLE_JOB_TNAME, OB_STR_JOB_ID, job_id))) {
|
||||
LOG_WARN("failed to init sql", K(ret));
|
||||
} else if (OB_FAIL(proxy.write(gen_meta_tenant_id(tenant_id), sql.ptr(), affected_rows))) {
|
||||
LOG_WARN("failed to exec sql", K(ret), K(sql));
|
||||
} else {
|
||||
LOG_INFO("succeed move import job to history table", K(tenant_id), K(job_id));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableJobPersistHelper::get_import_table_job_history_by_initiator(common::ObISQLClient &proxy,
|
||||
const uint64_t initiator_tenant_id, const uint64_t initiator_job_id, ObImportTableJob &job) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
const uint64_t exec_tenant_id = get_exec_tenant_id();
|
||||
if (OB_FAIL(sql.assign_fmt("select * from %s", OB_ALL_IMPORT_TABLE_JOB_HISTORY_TNAME))) {
|
||||
LOG_WARN("fail to assign sql", K(ret));
|
||||
} else if (OB_FAIL(sql.append_fmt(" where initiator_tenant_id =%lu and initiator_job_id=%ld", initiator_tenant_id, initiator_job_id))) {
|
||||
LOG_WARN("failed to append sql", K(ret), K(sql), K(initiator_tenant_id), K(initiator_job_id));
|
||||
} else {
|
||||
HEAP_VAR(ObMySQLProxy::ReadResult, res) {
|
||||
ObMySQLResult *result = NULL;
|
||||
if (OB_FAIL(proxy.read(res, exec_tenant_id, sql.ptr()))) {
|
||||
LOG_WARN("failed to exec sql", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else if (OB_ISNULL(result = res.get_result())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("result is null", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else if (OB_FAIL(result->next())) {
|
||||
if (OB_ITER_END == ret) {
|
||||
ret = OB_ENTRY_NOT_EXIST;
|
||||
} else {
|
||||
LOG_WARN("failed to get next", K(ret));
|
||||
}
|
||||
} else if (OB_FAIL(job.parse_from(*result))) {
|
||||
LOG_WARN("failed to parse row", K(ret));
|
||||
} else if (OB_ITER_END != result->next()) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("multi value exist", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else {
|
||||
ret = OB_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG_INFO("get import table job history", K(ret), K(job), K(sql));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableJobPersistHelper::get_import_table_job_by_initiator(common::ObISQLClient &proxy,
|
||||
const uint64_t initiator_tenant_id, const uint64_t initiator_job_id, ObImportTableJob &job) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
const uint64_t exec_tenant_id = get_exec_tenant_id();
|
||||
if (OB_FAIL(sql.assign_fmt("select * from %s", OB_ALL_IMPORT_TABLE_JOB_TNAME))) {
|
||||
LOG_WARN("fail to assign sql", K(ret));
|
||||
} else if (OB_FAIL(sql.append_fmt(" where initiator_tenant_id =%lu and initiator_job_id=%ld", initiator_tenant_id, initiator_job_id))) {
|
||||
LOG_WARN("failed to append sql", K(ret), K(sql), K(initiator_tenant_id), K(initiator_job_id));
|
||||
} else {
|
||||
HEAP_VAR(ObMySQLProxy::ReadResult, res) {
|
||||
ObMySQLResult *result = NULL;
|
||||
if (OB_FAIL(proxy.read(res, exec_tenant_id, sql.ptr()))) {
|
||||
LOG_WARN("failed to exec sql", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else if (OB_ISNULL(result = res.get_result())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("result is null", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else if (OB_FAIL(result->next())) {
|
||||
if (OB_ITER_END == ret) {
|
||||
ret = OB_ENTRY_NOT_EXIST;
|
||||
} else {
|
||||
LOG_WARN("failed to get next", K(ret));
|
||||
}
|
||||
} else if (OB_FAIL(job.parse_from(*result))) {
|
||||
LOG_WARN("failed to parse row", K(ret));
|
||||
} else if (OB_ITER_END != result->next()) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("multi value exist", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else {
|
||||
ret = OB_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG_INFO("get import table job", K(ret), K(job), K(sql));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableJobPersistHelper::report_import_job_statistics(
|
||||
common::ObISQLClient &proxy, const ObImportTableJob &job) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t affected_rows = 0;
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObImportTableJobPersistHelper not init", K(ret));
|
||||
} else if (OB_FAIL(table_op_.update_row(proxy, job, affected_rows))) {
|
||||
LOG_WARN("failed to compare and swap status", K(ret), K(job));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
ObImportTableTaskPersistHelper::ObImportTableTaskPersistHelper()
|
||||
: is_inited_(false), tenant_id_(), table_op_()
|
||||
{
|
||||
}
|
||||
|
||||
int ObImportTableTaskPersistHelper::init(const uint64_t tenant_id)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if(!is_sys_tenant(tenant_id) && !is_user_tenant(tenant_id)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid tenant id", K(ret), K(tenant_id));
|
||||
} else if (OB_FAIL(table_op_.init(OB_ALL_IMPORT_TABLE_TASK_TNAME, *this))) {
|
||||
LOG_WARN("failed to init table op", K(ret));
|
||||
} else {
|
||||
tenant_id_ = tenant_id;
|
||||
is_inited_ = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int ObImportTableTaskPersistHelper::insert_import_table_task(
|
||||
common::ObISQLClient &proxy, const ObImportTableTask &task) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t affect_rows = 0;
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObRecoverTablePersistHelper not init", K(ret));
|
||||
} else if (OB_FAIL(table_op_.insert_or_update_row(proxy, task, affect_rows))) {
|
||||
LOG_WARN("failed to insert or update row", K(ret), K(task));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableTaskPersistHelper::get_recover_table_task(
|
||||
common::ObISQLClient &proxy, const uint64_t tenant_id, const int64_t task_id, ObImportTableTask &task) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObImportTableTask::Key key;
|
||||
key.tenant_id_ = tenant_id;
|
||||
key.task_id_ = task_id;
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObImportTableTaskPersistHelper not init", K(ret));
|
||||
} else if (OB_FAIL(table_op_.get_row(proxy, false, key, task))) {
|
||||
LOG_WARN("failed to get row", KR(ret), K(key));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableTaskPersistHelper::advance_status(
|
||||
common::ObISQLClient &proxy, const ObImportTableTask &task, const ObImportTableTaskStatus &next_status) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
int64_t affected_rows = -1;
|
||||
ObDMLSqlSplicer dml;
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObImportTableTaskPersistHelper not init", K(ret));
|
||||
} else if (OB_FAIL(dml.add_pk_column(OB_STR_TASK_ID, task.get_task_id()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (OB_FAIL(dml.add_pk_column(OB_STR_TENANT_ID, task.get_tenant_id()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (next_status.is_finish() && OB_FAIL(dml.add_column(OB_STR_RESULT, task.get_result().get_result_str()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (next_status.is_finish() && OB_FAIL(dml.add_column(OB_STR_COMMENT, task.get_result().get_comment()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (OB_FAIL(dml.add_column(OB_STR_STATUS, next_status.get_str()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (OB_FAIL(dml.splice_update_sql(OB_ALL_IMPORT_TABLE_TASK_TNAME, sql))) {
|
||||
LOG_WARN("failed to splice update sql", K(ret));
|
||||
} else if (OB_FAIL(sql.append_fmt(" and %s='%s'", OB_STR_STATUS, task.get_status().get_str()))) {
|
||||
LOG_WARN("failed to append fmt", K(ret));
|
||||
} else if (OB_FAIL(proxy.write(get_exec_tenant_id(), sql.ptr(), affected_rows))) {
|
||||
LOG_WARN("failed to write", K(ret), K(sql));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableTaskPersistHelper::get_all_import_table_tasks_by_initiator(common::ObISQLClient &proxy,
|
||||
const ObImportTableJob &job, common::ObIArray<ObImportTableTask> &tasks) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
const uint64_t exec_tenant_id = get_exec_tenant_id();
|
||||
tasks.reset();
|
||||
const int64_t job_id = job.get_job_id();
|
||||
if (OB_FAIL(sql.assign_fmt("select * from %s", OB_ALL_IMPORT_TABLE_TASK_TNAME))) {
|
||||
LOG_WARN("fail to assign sql", K(ret));
|
||||
} else if (OB_FAIL(sql.append_fmt(" where job_id=%ld", job_id))) {
|
||||
LOG_WARN("failed to append sql", K(ret), K(sql), K(job_id));
|
||||
} else {
|
||||
HEAP_VAR(ObMySQLProxy::ReadResult, res) {
|
||||
ObMySQLResult *result = NULL;
|
||||
if (OB_FAIL(proxy.read(res, exec_tenant_id, sql.ptr()))) {
|
||||
LOG_WARN("failed to exec sql", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else if (OB_ISNULL(result = res.get_result())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("result is null", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else {
|
||||
while (OB_SUCC(ret)) {
|
||||
ObImportTableTask task;
|
||||
if (OB_FAIL(result->next())) {
|
||||
if (OB_ITER_END == ret) {
|
||||
ret = OB_SUCCESS;
|
||||
break;
|
||||
} else {
|
||||
LOG_WARN("failed to get next row", K(ret));
|
||||
}
|
||||
} else if (OB_FAIL(task.parse_from(*result))) {
|
||||
LOG_WARN("failed to parse job result", K(ret));
|
||||
} else if (OB_FAIL(tasks.push_back(task))) {
|
||||
LOG_WARN("failed to push back job", K(ret), K(task));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG_INFO("get import table tasks", K(ret), K(tasks));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableTaskPersistHelper::get_one_not_finish_task_by_initiator(
|
||||
common::ObISQLClient &proxy, const ObImportTableJob &job, bool &all_finish, ObImportTableTask &task) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
const uint64_t exec_tenant_id = get_exec_tenant_id();
|
||||
task.reset();
|
||||
all_finish = false;
|
||||
const int64_t job_id = job.get_job_id();
|
||||
if (OB_FAIL(sql.assign_fmt("select * from %s", OB_ALL_IMPORT_TABLE_TASK_TNAME))) {
|
||||
LOG_WARN("fail to assign sql", K(ret));
|
||||
} else if (OB_FAIL(sql.append_fmt(" where job_id=%ld and status != 'FINISH' order by task_id limit 1", job_id))) {
|
||||
LOG_WARN("failed to append sql", K(ret), K(sql), K(job_id));
|
||||
} else {
|
||||
HEAP_VAR(ObMySQLProxy::ReadResult, res) {
|
||||
ObMySQLResult *result = NULL;
|
||||
if (OB_FAIL(proxy.read(res, exec_tenant_id, sql.ptr()))) {
|
||||
LOG_WARN("failed to exec sql", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else if (OB_ISNULL(result = res.get_result())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("result is null", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else if (OB_FAIL(result->next())) {
|
||||
if (OB_ITER_END == ret) {
|
||||
all_finish = true;
|
||||
ret = OB_SUCCESS;
|
||||
} else {
|
||||
LOG_WARN("failed to get next", K(ret));
|
||||
}
|
||||
} else if (OB_FAIL(task.parse_from(*result))) {
|
||||
LOG_WARN("failed to parse from result", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG_INFO("get import table tasks", K(ret), K(task));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableTaskPersistHelper::move_import_task_to_history(
|
||||
common::ObISQLClient &proxy, const uint64_t tenant_id, const int64_t job_id) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
int64_t affected_rows = -1;
|
||||
if (tenant_id == OB_INVALID_TENANT_ID || job_id <= 0) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid argument", K(ret), K(tenant_id), K(job_id));
|
||||
} else if (OB_FAIL(sql.assign_fmt(
|
||||
"insert into %s select * from %s where %s=%lu",
|
||||
OB_ALL_IMPORT_TABLE_TASK_HISTORY_TNAME, OB_ALL_IMPORT_TABLE_TASK_TNAME,
|
||||
OB_STR_JOB_ID, job_id))) {
|
||||
LOG_WARN("failed to init sql", K(ret));
|
||||
} else if (OB_FAIL(proxy.write(gen_meta_tenant_id(tenant_id), sql.ptr(), affected_rows))) {
|
||||
LOG_WARN("failed to exec sql", K(ret), K(sql));
|
||||
} else if (OB_FALSE_IT(sql.reset())) {
|
||||
} else if (OB_FAIL(sql.assign_fmt("delete from %s where %s=%lu",
|
||||
OB_ALL_IMPORT_TABLE_TASK_TNAME, OB_STR_JOB_ID, job_id))) {
|
||||
LOG_WARN("failed to init sql", K(ret));
|
||||
} else if (OB_FAIL(proxy.write(gen_meta_tenant_id(tenant_id), sql.ptr(), affected_rows))) {
|
||||
LOG_WARN("failed to exec sql", K(ret), K(sql));
|
||||
} else {
|
||||
LOG_INFO("succeed move import task to history table", K(tenant_id), K(job_id));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableTaskPersistHelper::report_import_task_statistics(
|
||||
common::ObISQLClient &proxy, const ObImportTableTask &task) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t affected_rows = 0;
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObImportTableTaskPersistHelper not init", K(ret));
|
||||
} else if (OB_FAIL(table_op_.update_row(proxy, task, affected_rows))) {
|
||||
LOG_WARN("failed to compare and swap status", K(ret), K(task));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
89
src/share/restore/ob_import_table_persist_helper.h
Normal file
89
src/share/restore/ob_import_table_persist_helper.h
Normal file
@ -0,0 +1,89 @@
|
||||
/**
|
||||
* 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 OCEANBASE_SHARE_IMPORT_TABLE_PERSIST_HELPER_H
|
||||
#define OCEANBASE_SHARE_IMPORT_TABLE_PERSIST_HELPER_H
|
||||
|
||||
#include "lib/ob_define.h"
|
||||
#include "share/ob_inner_table_operator.h"
|
||||
#include "share/restore/ob_import_table_struct.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
|
||||
class ObImportTableJobPersistHelper final : public ObIExecTenantIdProvider
|
||||
{
|
||||
public:
|
||||
ObImportTableJobPersistHelper();
|
||||
virtual ~ObImportTableJobPersistHelper() {}
|
||||
int init(const uint64_t tenant_id);
|
||||
void reset() { is_inited_ = false; }
|
||||
uint64_t get_exec_tenant_id() const override { return gen_meta_tenant_id(tenant_id_); }
|
||||
int insert_import_table_job(common::ObISQLClient &proxy, const ObImportTableJob &job) const;
|
||||
|
||||
int get_import_table_job(common::ObISQLClient &proxy, const uint64_t tenant_id, const int64_t job_id,
|
||||
ObImportTableJob &job) const;
|
||||
int get_all_import_table_jobs(common::ObISQLClient &proxy, common::ObIArray<ObImportTableJob> &jobs) const;
|
||||
int advance_status(common::ObISQLClient &proxy,
|
||||
const ObImportTableJob &job, const ObImportTableJobStatus &next_status) const;
|
||||
|
||||
int report_import_job_statistics(common::ObISQLClient &proxy, const ObImportTableJob &job) const;
|
||||
int move_import_job_to_history(common::ObISQLClient &proxy, const uint64_t tenant_id, const int64_t job_id) const;
|
||||
int get_import_table_job_history_by_initiator(common::ObISQLClient &proxy,
|
||||
const uint64_t initiator_tenant_id, const uint64_t initiator_job_id, ObImportTableJob &job) const;
|
||||
int get_import_table_job_by_initiator(common::ObISQLClient &proxy,
|
||||
const uint64_t initiator_tenant_id, const uint64_t initiator_job_id, ObImportTableJob &job) const;
|
||||
int force_cancel_import_job(common::ObISQLClient &proxy) const;
|
||||
TO_STRING_KV(K_(is_inited), K_(tenant_id));
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(ObImportTableJobPersistHelper);
|
||||
bool is_inited_;
|
||||
uint64_t tenant_id_; // sys or user tenant id
|
||||
ObInnerTableOperator table_op_;
|
||||
};
|
||||
|
||||
class ObImportTableTaskPersistHelper final : public ObIExecTenantIdProvider
|
||||
{
|
||||
public:
|
||||
ObImportTableTaskPersistHelper();
|
||||
virtual ~ObImportTableTaskPersistHelper() {}
|
||||
int init(const uint64_t tenant_id);
|
||||
void reset() { is_inited_ = false; }
|
||||
uint64_t get_exec_tenant_id() const override { return gen_meta_tenant_id(tenant_id_); }
|
||||
int insert_import_table_task(common::ObISQLClient &proxy, const ObImportTableTask &task) const;
|
||||
|
||||
int get_all_import_table_tasks_by_initiator(common::ObISQLClient &proxy,
|
||||
const ObImportTableJob &job, common::ObIArray<ObImportTableTask> &tasks) const;
|
||||
int get_one_not_finish_task_by_initiator(common::ObISQLClient &proxy,
|
||||
const ObImportTableJob &job, bool &all_finish, ObImportTableTask &task) const;
|
||||
int get_recover_table_task(common::ObISQLClient &proxy, const uint64_t tenant_id, const int64_t task_id,
|
||||
ObImportTableTask &task) const;
|
||||
|
||||
int advance_status(common::ObISQLClient &proxy,
|
||||
const ObImportTableTask &task, const ObImportTableTaskStatus &next_status) const;
|
||||
|
||||
int move_import_task_to_history(common::ObISQLClient &proxy, const uint64_t tenant_id, const int64_t job_id) const;
|
||||
int report_import_task_statistics(common::ObISQLClient &proxy, const ObImportTableTask &task) const;
|
||||
TO_STRING_KV(K_(is_inited), K_(tenant_id));
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(ObImportTableTaskPersistHelper);
|
||||
bool is_inited_;
|
||||
uint64_t tenant_id_; // sys or user tenant id
|
||||
ObInnerTableOperator table_op_;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
1390
src/share/restore/ob_import_table_struct.cpp
Normal file
1390
src/share/restore/ob_import_table_struct.cpp
Normal file
File diff suppressed because it is too large
Load Diff
441
src/share/restore/ob_import_table_struct.h
Normal file
441
src/share/restore/ob_import_table_struct.h
Normal file
@ -0,0 +1,441 @@
|
||||
/**
|
||||
* 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 OCEANBASE_SHARE_IMPORT_TABLE_STRUCT_H
|
||||
#define OCEANBASE_SHARE_IMPORT_TABLE_STRUCT_H
|
||||
|
||||
#include "lib/ob_define.h"
|
||||
#include "share/backup/ob_backup_struct.h"
|
||||
#include "share/ob_inner_table_operator.h"
|
||||
#include "share/restore/ob_import_arg.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
class ObImportResult final
|
||||
{
|
||||
public:
|
||||
using Comment = common::ObFixedLengthString<OB_COMMENT_LENGTH>;
|
||||
ObImportResult(): is_succeed_(true), comment_() {}
|
||||
~ObImportResult() {}
|
||||
void set_result(const bool is_succeed, const Comment &comment = "");
|
||||
int set_result(const bool is_succeed, const char *buf);
|
||||
int set_result(const int err_code, const share::ObTaskId &trace_id, const ObAddr &addr, const ObString &extra_info = ObString());
|
||||
void reset();
|
||||
const char *get_result_str() const { return is_succeed_ ? "SUCCEESS" : "FAILED"; }
|
||||
const char *get_comment() const { return comment_.ptr(); }
|
||||
bool is_succeed() const { return is_succeed_; }
|
||||
bool is_comment_setted() const { return !comment_.is_empty(); }
|
||||
ObImportResult &operator=(const ObImportResult &result);
|
||||
TO_STRING_KV(K_(is_succeed), K_(comment));
|
||||
private:
|
||||
bool is_succeed_;
|
||||
Comment comment_;
|
||||
};
|
||||
|
||||
#ifdef Property_declare_int
|
||||
#undef Property_declare_int
|
||||
#endif
|
||||
|
||||
#define Property_declare_int(variable_type, variable_name)\
|
||||
private:\
|
||||
variable_type variable_name##_;\
|
||||
public:\
|
||||
variable_type get_##variable_name() const\
|
||||
{ return variable_name##_;}\
|
||||
void set_##variable_name(variable_type other)\
|
||||
{ variable_name##_ = other;}
|
||||
|
||||
#ifdef Property_declare_ObString
|
||||
#undef Property_declare_ObString
|
||||
#endif
|
||||
#define Property_declare_ObString(variable_name)\
|
||||
private:\
|
||||
ObString variable_name##_;\
|
||||
public:\
|
||||
const ObString &get_##variable_name() const\
|
||||
{ return variable_name##_;}\
|
||||
int set_##variable_name(const ObString &str)\
|
||||
{ return deep_copy_ob_string(allocator_, str, variable_name##_);}
|
||||
|
||||
#ifdef Property_declare_struct
|
||||
#undef Property_declare_struct
|
||||
#endif
|
||||
|
||||
#define Property_declare_struct(variable_type, variable_name)\
|
||||
private:\
|
||||
variable_type variable_name##_;\
|
||||
public:\
|
||||
const variable_type &get_##variable_name() const\
|
||||
{ return variable_name##_;}\
|
||||
variable_type &get_##variable_name() \
|
||||
{ return variable_name##_;}\
|
||||
void set_##variable_name(variable_type other)\
|
||||
{ variable_name##_ = other;}
|
||||
|
||||
class ObImportTableTaskStatus final
|
||||
{
|
||||
public:
|
||||
enum Status
|
||||
{
|
||||
INIT = 0,
|
||||
DOING = 1,
|
||||
FINISH = 2,
|
||||
MAX
|
||||
};
|
||||
ObImportTableTaskStatus(): status_(MAX) {}
|
||||
~ObImportTableTaskStatus() {}
|
||||
ObImportTableTaskStatus(const Status &status): status_(status) {}
|
||||
ObImportTableTaskStatus(const ObImportTableTaskStatus &status): status_(status.status_) {}
|
||||
ObImportTableTaskStatus &operator=(const ObImportTableTaskStatus &status) {
|
||||
if (this != &status) {
|
||||
status_ = status.status_;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
ObImportTableTaskStatus &operator=(const Status &status) { status_ = status; return *this; }
|
||||
bool operator ==(const ObImportTableTaskStatus &other) const { return status_ == other.status_; }
|
||||
bool operator !=(const ObImportTableTaskStatus &other) const { return status_ != other.status_; }
|
||||
operator Status() const { return status_; }
|
||||
bool is_valid() const { return status_ >= INIT && status_ < MAX; }
|
||||
bool is_finish() const { return FINISH == status_; }
|
||||
|
||||
Status get_status() const { return status_; }
|
||||
ObImportTableTaskStatus get_next_status(const int err_code);
|
||||
const char* get_str() const;
|
||||
int set_status(const char *str);
|
||||
TO_STRING_KV(K_(status))
|
||||
private:
|
||||
Status status_;
|
||||
};
|
||||
|
||||
struct ObImportTableTask final : public ObIInnerTableRow
|
||||
{
|
||||
public:
|
||||
struct Key final : public ObIInnerTableKey
|
||||
{
|
||||
Key() : tenant_id_(OB_INVALID_TENANT_ID), task_id_() {}
|
||||
~Key() {}
|
||||
void reset() { tenant_id_ = OB_INVALID_TENANT_ID; task_id_ = 0; }
|
||||
bool is_pkey_valid() const override { return (is_user_tenant(tenant_id_) || is_sys_tenant(tenant_id_)) && task_id_ != 0; }
|
||||
bool operator==(const Key &other) const
|
||||
{
|
||||
return task_id_ == other.task_id_ && tenant_id_ == other.tenant_id_;
|
||||
}
|
||||
bool operator!=(const Key &other) const
|
||||
{
|
||||
return task_id_ != other.task_id_ || tenant_id_ != other.tenant_id_;
|
||||
}
|
||||
int fill_pkey_dml(share::ObDMLSqlSplicer &dml) const override;
|
||||
TO_STRING_KV(K_(tenant_id), K_(task_id));
|
||||
uint64_t tenant_id_;
|
||||
int64_t task_id_;
|
||||
};
|
||||
public:
|
||||
ObImportTableTask() { reset(); }
|
||||
virtual ~ObImportTableTask() {}
|
||||
bool is_valid() const { return is_pkey_valid(); }
|
||||
void reset();
|
||||
int assign(const ObImportTableTask &that);
|
||||
int get_pkey(Key &key) const;
|
||||
bool is_pkey_valid() const override { return (is_user_tenant(tenant_id_) || is_sys_tenant(tenant_id_)) && task_id_ != 0; }
|
||||
int fill_pkey_dml(share::ObDMLSqlSplicer &dml) const override;
|
||||
int parse_from(common::sqlclient::ObMySQLResult &result) override;
|
||||
int fill_dml(share::ObDMLSqlSplicer &dml) const override;
|
||||
|
||||
TO_STRING_KV(K_(tenant_id), K_(task_id), K_(job_id), K_(src_tenant_id), K_(src_tablespace), K_(src_tablegroup),
|
||||
K_(src_database), K_(src_table), K_(src_partition), K_(target_tablespace), K_(target_tablegroup), K_(target_database),
|
||||
K_(target_table), K_(table_column), K_(status), K_(start_ts), K_(completion_ts), K_(cumulative_ts), K_(total_bytes),
|
||||
K_(total_rows), K_(imported_bytes), K_(imported_rows), K_(total_index_count), K_(imported_index_count),
|
||||
K_(failed_index_count), K_(total_constraint_count), K_(imported_constraint_count), K_(failed_constraint_count),
|
||||
K_(total_ref_constraint_count), K_(imported_ref_constraint_count), K_(failed_ref_constraint_count),
|
||||
K_(total_trigger_count), K_(imported_trigger_count), K_(failed_trigger_count), K_(result));
|
||||
|
||||
Property_declare_int(uint64_t, tenant_id)
|
||||
Property_declare_int(int64_t, task_id)
|
||||
Property_declare_int(int64_t, job_id)
|
||||
Property_declare_int(uint64_t, src_tenant_id)
|
||||
Property_declare_ObString(src_tablespace)
|
||||
Property_declare_ObString(src_tablegroup)
|
||||
Property_declare_ObString(src_database)
|
||||
Property_declare_ObString(src_table)
|
||||
Property_declare_ObString(src_partition)
|
||||
Property_declare_ObString(target_tablespace)
|
||||
Property_declare_ObString(target_tablegroup)
|
||||
Property_declare_ObString(target_database)
|
||||
Property_declare_ObString(target_table)
|
||||
Property_declare_int(int64_t, table_column)
|
||||
Property_declare_int(ObImportTableTaskStatus, status)
|
||||
Property_declare_int(int64_t, start_ts)
|
||||
Property_declare_int(int64_t, completion_ts)
|
||||
Property_declare_int(int64_t, cumulative_ts)
|
||||
Property_declare_int(int64_t, total_bytes)
|
||||
Property_declare_int(int64_t, total_rows)
|
||||
Property_declare_int(int64_t, imported_bytes)
|
||||
Property_declare_int(int64_t, imported_rows)
|
||||
Property_declare_int(int64_t, total_index_count)
|
||||
Property_declare_int(int64_t, imported_index_count)
|
||||
Property_declare_int(int64_t, failed_index_count)
|
||||
Property_declare_int(int64_t, total_constraint_count)
|
||||
Property_declare_int(int64_t, imported_constraint_count)
|
||||
Property_declare_int(int64_t, failed_constraint_count)
|
||||
Property_declare_int(int64_t, total_ref_constraint_count)
|
||||
Property_declare_int(int64_t, imported_ref_constraint_count)
|
||||
Property_declare_int(int64_t, failed_ref_constraint_count)
|
||||
Property_declare_int(int64_t, total_trigger_count)
|
||||
Property_declare_int(int64_t, imported_trigger_count)
|
||||
Property_declare_int(int64_t, failed_trigger_count)
|
||||
Property_declare_struct(ObImportResult, result)
|
||||
|
||||
private:
|
||||
common::ObArenaAllocator allocator_;
|
||||
};
|
||||
|
||||
class ObImportTableJobStatus final
|
||||
{
|
||||
public:
|
||||
enum Status
|
||||
{
|
||||
INIT = 0,
|
||||
IMPORT_TABLE = 1,
|
||||
RECONSTRUCT_REF_CONSTRAINT = 2,
|
||||
CANCELING = 3,
|
||||
IMPORT_FINISH = 4,
|
||||
MAX_STATUS
|
||||
};
|
||||
ObImportTableJobStatus(): status_(MAX_STATUS) {}
|
||||
~ObImportTableJobStatus() {}
|
||||
ObImportTableJobStatus(const Status &status): status_(status) {}
|
||||
ObImportTableJobStatus(const ObImportTableJobStatus &status): status_(status.status_) {}
|
||||
ObImportTableJobStatus &operator=(const ObImportTableJobStatus &status) {
|
||||
if (this != &status) {
|
||||
status_ = status.status_;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
ObImportTableJobStatus &operator=(const Status &status) { status_ = status; return *this; }
|
||||
bool operator ==(const ObImportTableJobStatus &other) const { return status_ == other.status_; }
|
||||
bool operator ==(const Status &other) const { return status_ == other; }
|
||||
bool operator !=(const ObImportTableJobStatus &other) const { return status_ != other.status_; }
|
||||
bool operator !=(const Status &other) const { return status_ != other; }
|
||||
operator Status() const { return status_; }
|
||||
bool is_valid() const { return status_ >= INIT && status_ < MAX_STATUS; }
|
||||
bool is_finish() const { return IMPORT_FINISH == status_; }
|
||||
|
||||
Status get_status() const { return status_; }
|
||||
static ObImportTableJobStatus get_next_status(const ObImportTableJobStatus &cur_status);
|
||||
|
||||
const char* get_str() const;
|
||||
int set_status(const char *str);
|
||||
|
||||
TO_STRING_KV(K_(status))
|
||||
private:
|
||||
Status status_;
|
||||
};
|
||||
|
||||
|
||||
struct ObImportTableJob final : public ObIInnerTableRow
|
||||
{
|
||||
public:
|
||||
|
||||
struct Key final : public ObIInnerTableKey
|
||||
{
|
||||
Key() : tenant_id_(OB_INVALID_TENANT_ID), job_id_(-1) {}
|
||||
~Key() {}
|
||||
void reset() { tenant_id_ = OB_INVALID_TENANT_ID; job_id_ = -1; }
|
||||
bool is_pkey_valid() const override { return (is_user_tenant(tenant_id_) || is_sys_tenant(tenant_id_)) && job_id_ >= 0; }
|
||||
bool operator==(const Key &other) const
|
||||
{
|
||||
return job_id_ == other.job_id_ && tenant_id_ == other.tenant_id_;
|
||||
}
|
||||
bool operator!=(const Key &other) const
|
||||
{
|
||||
return job_id_ != other.job_id_ || tenant_id_ != other.tenant_id_;
|
||||
}
|
||||
int fill_pkey_dml(share::ObDMLSqlSplicer &dml) const override;
|
||||
TO_STRING_KV(K_(tenant_id), K_(job_id));
|
||||
uint64_t tenant_id_;
|
||||
int64_t job_id_;
|
||||
};
|
||||
|
||||
public:
|
||||
ObImportTableJob() { reset(); }
|
||||
virtual ~ObImportTableJob() {}
|
||||
bool is_valid() const override { return is_pkey_valid(); }
|
||||
void reset();
|
||||
int get_pkey(Key &key) const;
|
||||
bool is_pkey_valid() const override { return (is_user_tenant(tenant_id_) || is_sys_tenant(tenant_id_)) && job_id_ >= 0; }
|
||||
int fill_pkey_dml(share::ObDMLSqlSplicer &dml) const override;
|
||||
int parse_from(common::sqlclient::ObMySQLResult &result) override;
|
||||
int fill_dml(share::ObDMLSqlSplicer &dml) const override;
|
||||
int assign(const ObImportTableJob &that);
|
||||
|
||||
TO_STRING_KV(K_(tenant_id), K_(job_id), K_(initiator_tenant_id), K_(initiator_job_id), K_(start_ts), K_(end_ts),
|
||||
K_(src_tenant_name), K_(src_tenant_id), K_(status), K_(total_table_count), K_(finished_table_count),
|
||||
K_(failed_table_count), K_(total_bytes), K_(finished_bytes), K_(failed_bytes), K_(result), K_(import_arg));
|
||||
|
||||
Property_declare_int(uint64_t, tenant_id)
|
||||
Property_declare_int(int64_t, job_id)
|
||||
Property_declare_int(uint64_t, initiator_tenant_id)
|
||||
Property_declare_int(int64_t, initiator_job_id)
|
||||
Property_declare_int(int64_t, start_ts)
|
||||
Property_declare_int(int64_t, end_ts)
|
||||
Property_declare_ObString(src_tenant_name)
|
||||
Property_declare_int(uint64_t, src_tenant_id)
|
||||
Property_declare_int(ObImportTableJobStatus, status)
|
||||
Property_declare_int(int64_t, total_table_count)
|
||||
Property_declare_int(int64_t, finished_table_count)
|
||||
Property_declare_int(int64_t, failed_table_count)
|
||||
Property_declare_int(int64_t, total_bytes)
|
||||
Property_declare_int(int64_t, finished_bytes)
|
||||
Property_declare_int(int64_t, failed_bytes)
|
||||
Property_declare_struct(ObImportResult, result)
|
||||
Property_declare_ObString(description)
|
||||
|
||||
const share::ObImportArg &get_import_arg() const { return import_arg_; }
|
||||
share::ObImportArg &get_import_arg() { return import_arg_; }
|
||||
|
||||
private:
|
||||
share::ObImportArg import_arg_;
|
||||
common::ObArenaAllocator allocator_;
|
||||
DISALLOW_COPY_AND_ASSIGN(ObImportTableJob);
|
||||
};
|
||||
|
||||
class ObRecoverTableStatus final
|
||||
{
|
||||
public:
|
||||
enum Status
|
||||
{
|
||||
PREPARE = 0,
|
||||
RECOVERING = 1,
|
||||
RESTORE_AUX_TENANT = 2,
|
||||
PRECHECK_IMPORT = 3,
|
||||
GEN_IMPORT_JOB = 4,
|
||||
IMPORTING = 5,
|
||||
CANCELING = 6,
|
||||
COMPLETED = 7,
|
||||
FAILED = 8,
|
||||
MAX_STATUS
|
||||
};
|
||||
public:
|
||||
ObRecoverTableStatus(): status_(MAX_STATUS) {}
|
||||
~ObRecoverTableStatus() {}
|
||||
ObRecoverTableStatus(const Status &status): status_(status) {}
|
||||
ObRecoverTableStatus(const ObRecoverTableStatus &status): status_(status.status_) {}
|
||||
ObRecoverTableStatus &operator=(const ObRecoverTableStatus &status) {
|
||||
if (this != &status) {
|
||||
status_ = status.status_;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
ObRecoverTableStatus &operator=(const Status &status) { status_ = status; return *this; }
|
||||
bool operator ==(const ObRecoverTableStatus &other) const { return status_ == other.status_; }
|
||||
bool operator ==(const ObRecoverTableStatus::Status &other) const { return status_ == other; }
|
||||
bool operator !=(const ObRecoverTableStatus::Status &other) const { return status_ != other; }
|
||||
bool operator !=(const ObRecoverTableStatus &other) const { return status_ != other.status_; }
|
||||
operator Status() const { return status_; }
|
||||
bool is_valid() const { return status_ >= PREPARE && status_ < MAX_STATUS; }
|
||||
bool is_finish() const { return COMPLETED == status_ || FAILED == status_; }
|
||||
bool is_completed() const { return COMPLETED == status_; }
|
||||
|
||||
Status get_status() const { return status_; }
|
||||
static ObRecoverTableStatus get_sys_next_status(const ObRecoverTableStatus &cur_status); // used by sys job
|
||||
static ObRecoverTableStatus get_user_next_status(const ObRecoverTableStatus &cur_status); // used by user job
|
||||
|
||||
const char* get_str() const;
|
||||
int set_status(const char *str);
|
||||
|
||||
TO_STRING_KV(K_(status))
|
||||
|
||||
private:
|
||||
Status status_;
|
||||
};
|
||||
|
||||
struct ObRecoverTableJob final : public ObIInnerTableRow
|
||||
{
|
||||
public:
|
||||
struct Key final : public ObIInnerTableKey
|
||||
{
|
||||
Key() : tenant_id_(OB_INVALID_TENANT_ID), job_id_(-1) {}
|
||||
~Key() {}
|
||||
void reset() { tenant_id_ = OB_INVALID_TENANT_ID; job_id_ = -1; }
|
||||
bool is_pkey_valid() const override {
|
||||
return (is_user_tenant(tenant_id_) || is_sys_tenant(tenant_id_)) && job_id_ >= 0; }
|
||||
|
||||
bool operator==(const Key &other) const
|
||||
{
|
||||
return job_id_ == other.job_id_ && tenant_id_ == other.tenant_id_;
|
||||
}
|
||||
bool operator!=(const Key &other) const
|
||||
{
|
||||
return job_id_ != other.job_id_ || tenant_id_ != other.tenant_id_;
|
||||
}
|
||||
int fill_pkey_dml(share::ObDMLSqlSplicer &dml) const override;
|
||||
TO_STRING_KV(K_(tenant_id), K_(job_id));
|
||||
uint64_t tenant_id_;
|
||||
int64_t job_id_;
|
||||
};
|
||||
|
||||
public:
|
||||
ObRecoverTableJob() { reset(); }
|
||||
virtual ~ObRecoverTableJob() {}
|
||||
bool is_valid() const override { return is_pkey_valid(); }
|
||||
void reset();
|
||||
int assign(const ObRecoverTableJob &that);
|
||||
bool is_pkey_valid() const override { return (is_user_tenant(tenant_id_) || is_sys_tenant(tenant_id_)) && job_id_ >= 0; }
|
||||
|
||||
int get_pkey(Key &key) const;
|
||||
int fill_pkey_dml(share::ObDMLSqlSplicer &dml) const override;
|
||||
int parse_from(common::sqlclient::ObMySQLResult &result) override;
|
||||
int fill_dml(share::ObDMLSqlSplicer &dml) const override;
|
||||
|
||||
TO_STRING_KV(K_(tenant_id), K_(job_id), K_(initiator_tenant_id), K_(initiator_job_id), K_(start_ts), K_(end_ts), K_(status),
|
||||
K_(aux_tenant_name), K_(target_tenant_name), K_(target_tenant_id), K_(restore_scn), K_(restore_option),
|
||||
K_(backup_dest), K_(backup_dest), K_(backup_passwd), K_(external_kms_info), K_(result),
|
||||
K_(import_arg), K_(multi_restore_path_list));
|
||||
|
||||
Property_declare_int(uint64_t, tenant_id)
|
||||
Property_declare_int(int64_t, job_id)
|
||||
Property_declare_int(uint64_t, initiator_tenant_id)
|
||||
Property_declare_int(int64_t, initiator_job_id)
|
||||
Property_declare_int(int64_t, start_ts)
|
||||
Property_declare_int(int64_t, end_ts)
|
||||
Property_declare_int(ObRecoverTableStatus, status)
|
||||
Property_declare_ObString(aux_tenant_name)
|
||||
Property_declare_ObString(target_tenant_name)
|
||||
Property_declare_int(uint64_t, target_tenant_id)
|
||||
Property_declare_int(share::SCN, restore_scn)
|
||||
Property_declare_ObString(restore_option)
|
||||
Property_declare_ObString(backup_dest)
|
||||
Property_declare_ObString(backup_passwd)
|
||||
Property_declare_ObString(external_kms_info)
|
||||
Property_declare_struct(ObImportResult, result)
|
||||
Property_declare_ObString(description)
|
||||
ObPhysicalRestoreBackupDestList& get_multi_restore_path_list() { return multi_restore_path_list_; }
|
||||
const ObPhysicalRestoreBackupDestList& get_multi_restore_path_list() const { return multi_restore_path_list_; }
|
||||
share::ObImportArg &get_import_arg() { return import_arg_; }
|
||||
const share::ObImportArg &get_import_arg() const { return import_arg_; }
|
||||
private:
|
||||
share::ObImportArg import_arg_;
|
||||
share::ObPhysicalRestoreBackupDestList multi_restore_path_list_;
|
||||
common::ObArenaAllocator allocator_;
|
||||
};
|
||||
|
||||
#undef Property_declare_int
|
||||
#undef Property_declare_ObString
|
||||
#undef Property_declare_struct
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
155
src/share/restore/ob_import_util.cpp
Normal file
155
src/share/restore/ob_import_util.cpp
Normal file
@ -0,0 +1,155 @@
|
||||
/**
|
||||
* 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 "ob_import_util.h"
|
||||
|
||||
using namespace oceanbase;
|
||||
using namespace share;
|
||||
|
||||
bool ObImportTableUtil::can_retrieable_err(const int err_code)
|
||||
{
|
||||
bool bret = true;
|
||||
switch(err_code) {
|
||||
case OB_NOT_INIT :
|
||||
case OB_INIT_TWICE:
|
||||
case OB_INVALID_ARGUMENT :
|
||||
case OB_ERR_UNEXPECTED :
|
||||
case OB_ERR_SYS :
|
||||
case OB_CANCELED :
|
||||
case OB_NOT_SUPPORTED :
|
||||
case OB_TENANT_HAS_BEEN_DROPPED :
|
||||
case OB_TENANT_NOT_EXIST:
|
||||
case OB_ERR_INVALID_TENANT_NAME:
|
||||
case OB_HASH_EXIST:
|
||||
case OB_HASH_NOT_EXIST:
|
||||
case OB_ENTRY_EXIST:
|
||||
case OB_ENTRY_NOT_EXIST:
|
||||
case OB_VERSION_NOT_MATCH:
|
||||
case OB_STATE_NOT_MATCH:
|
||||
case OB_TABLE_NOT_EXIST:
|
||||
case OB_ERR_BAD_DATABASE:
|
||||
case OB_LS_RESTORE_FAILED:
|
||||
case OB_OP_NOT_ALLOW:
|
||||
case OB_TABLEGROUP_NOT_EXIST:
|
||||
case OB_TABLESPACE_NOT_EXIST:
|
||||
case OB_ERR_TABLE_EXIST:
|
||||
bret = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return bret;
|
||||
}
|
||||
|
||||
int ObImportTableUtil::get_tenant_schema_guard(share::schema::ObMultiVersionSchemaService &schema_service, uint64_t tenant_id,
|
||||
share::schema::ObSchemaGetterGuard &guard)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
schema::ObTenantStatus status;
|
||||
if (OB_FAIL(schema_service.get_tenant_schema_guard(tenant_id, guard))) {
|
||||
LOG_WARN("faield to get tenant schema guard", K(ret));
|
||||
} else if (OB_FAIL(guard.get_tenant_status(tenant_id, status))) {
|
||||
LOG_WARN("failed to get tenant status", K(ret));
|
||||
} else if (schema::ObTenantStatus::TENANT_STATUS_NORMAL != status) {
|
||||
ret = OB_STATE_NOT_MATCH;
|
||||
LOG_WARN("tenant status is not normal", K(ret), K(tenant_id));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableUtil::check_database_schema_exist(share::schema::ObMultiVersionSchemaService &schema_service,
|
||||
uint64_t tenant_id, const ObString &db_name, bool &is_exist)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
schema::ObSchemaGetterGuard guard;
|
||||
if (OB_FAIL(schema_service.get_tenant_schema_guard(tenant_id, guard))) {
|
||||
LOG_WARN("faield to get tenant schema guard", K(ret));
|
||||
} else if (OB_FAIL(guard.check_database_exist(tenant_id, db_name, is_exist))) {
|
||||
LOG_WARN("failed to check database exist", K(ret), K(tenant_id), K(db_name));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableUtil::check_table_schema_exist(share::schema::ObMultiVersionSchemaService &schema_service,
|
||||
uint64_t tenant_id, const ObString &db_name, const ObString &table_name, bool &is_exist)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
schema::ObSchemaGetterGuard guard;
|
||||
uint64_t database_id = OB_INVALID_ID;
|
||||
is_exist = false;
|
||||
if (OB_FAIL(schema_service.get_tenant_schema_guard(tenant_id, guard))) {
|
||||
LOG_WARN("faield to get tenant schema guard", K(ret));
|
||||
} else if (OB_FAIL(guard.get_database_id(tenant_id, db_name, database_id))) {
|
||||
LOG_WARN("failed to get database id", K(ret), K(tenant_id));
|
||||
} else if (OB_INVALID_ID == database_id) {
|
||||
LOG_WARN("database not exist", K(tenant_id), K(db_name));
|
||||
} else if (OB_FAIL(guard.check_table_exist(tenant_id, database_id, table_name, false,
|
||||
schema::ObSchemaGetterGuard::CheckTableType::ALL_NON_HIDDEN_TYPES, is_exist))) {
|
||||
LOG_WARN("failed to check table exist", K(ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableUtil::check_tablegroup_exist(share::schema::ObMultiVersionSchemaService &schema_service,
|
||||
uint64_t tenant_id, const ObString &tablegroup, bool &is_exist)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
schema::ObSchemaGetterGuard guard;
|
||||
uint64_t table_group_id = OB_INVALID_ID;
|
||||
is_exist = false;
|
||||
if (OB_FAIL(schema_service.get_tenant_schema_guard(tenant_id, guard))) {
|
||||
LOG_WARN("faield to get tenant schema guard", K(ret));
|
||||
} else if (OB_FAIL(guard.get_tablegroup_id(tenant_id, tablegroup, table_group_id))) {
|
||||
LOG_WARN("failed to get tablegroup id", K(ret), K(tenant_id));
|
||||
} else if (OB_INVALID_ID == table_group_id) {
|
||||
LOG_INFO("tablegroup not exist", K(tenant_id), K(tablegroup));
|
||||
} else {
|
||||
is_exist = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableUtil::check_tablespace_exist(share::schema::ObMultiVersionSchemaService &schema_service,
|
||||
uint64_t tenant_id, const ObString &tablespace, bool &is_exist)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
schema::ObSchemaGetterGuard guard;
|
||||
const schema::ObTablespaceSchema *schema = nullptr;
|
||||
is_exist = false;
|
||||
if (OB_FAIL(schema_service.get_tenant_schema_guard(tenant_id, guard))) {
|
||||
LOG_WARN("faield to get tenant schema guard", K(ret));
|
||||
} else if (OB_FAIL(guard.get_tablespace_schema_with_name(tenant_id, tablespace, schema))) {
|
||||
LOG_WARN("failed to get tablespace id", K(ret), K(tenant_id));
|
||||
} else if (OB_ISNULL(schema)) {
|
||||
LOG_INFO("tablespace not exist", K(tenant_id), K(tablespace));
|
||||
} else {
|
||||
is_exist = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObImportTableUtil::get_tenant_name_case_mode(const uint64_t tenant_id, ObNameCaseMode &name_case_mode)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
schema::ObSchemaGetterGuard guard;
|
||||
share::schema::ObMultiVersionSchemaService *schema_service = nullptr;
|
||||
if (!is_valid_tenant_id(tenant_id)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid tenant id", K(ret), K(tenant_id));
|
||||
} else if (OB_ISNULL(schema_service = GCTX.schema_service_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("schema service must not be null", K(ret));
|
||||
} else if (OB_FAIL(schema_service->get_tenant_name_case_mode(tenant_id, name_case_mode))) {
|
||||
LOG_WARN("faield to get tenant schema guard", K(ret), K(tenant_id));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
41
src/share/restore/ob_import_util.h
Normal file
41
src/share/restore/ob_import_util.h
Normal file
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* 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 OCEANBASE_SHARE_IMPORT_TABLE_UTIL_H
|
||||
#define OCEANBASE_SHARE_IMPORT_TABLE_UTIL_H
|
||||
#include "lib/ob_define.h"
|
||||
#include "share/schema/ob_multi_version_schema_service.h"
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
class ObImportTableUtil final
|
||||
{
|
||||
public:
|
||||
static bool can_retrieable_err(const int err_code);
|
||||
static int get_tenant_schema_guard(share::schema::ObMultiVersionSchemaService &schema_service, uint64_t tenant_id,
|
||||
share::schema::ObSchemaGetterGuard &guard);
|
||||
static int check_database_schema_exist(share::schema::ObMultiVersionSchemaService &schema_service,
|
||||
uint64_t tenant_id, const ObString &db_name, bool &is_exist);
|
||||
static int check_table_schema_exist(share::schema::ObMultiVersionSchemaService &schema_service,
|
||||
uint64_t tenant_id, const ObString &db_name, const ObString &table_name, bool &is_exist);
|
||||
static int check_tablegroup_exist(share::schema::ObMultiVersionSchemaService &schema_service,
|
||||
uint64_t tenant_id, const ObString &tablegroup, bool &is_exist);
|
||||
static int check_tablespace_exist(share::schema::ObMultiVersionSchemaService &schema_service,
|
||||
uint64_t tenant_id, const ObString &tablespace, bool &is_exist);
|
||||
static int get_tenant_name_case_mode(const uint64_t tenant_id, ObNameCaseMode &name_case_mode);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -518,6 +518,16 @@ int ObPhysicalRestoreTableOperator::retrieve_restore_option(
|
||||
RETRIEVE_STR_VALUE(kms_encrypt_key, job);
|
||||
RETRIEVE_INT_VALUE(concurrency, job);
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
if (name == "backup_dest") {
|
||||
ObString value;
|
||||
EXTRACT_VARCHAR_FIELD_MYSQL_WITH_DEFAULT_VALUE(result, "value", value, true, false, value);
|
||||
if (FAILEDx((job).set_backup_dest(value))) {
|
||||
LOG_WARN("failed to set column value", KR(ret), K(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
if (name == "kms_encrypt") {
|
||||
int64_t kms_encrypt = 0;
|
||||
@ -955,6 +965,31 @@ int ObPhysicalRestoreTableOperator::get_job_by_tenant_name(
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPhysicalRestoreTableOperator::get_job_by_restore_tenant_name(
|
||||
const ObString &tenant_name,
|
||||
ObPhysicalRestoreJob &job_info)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
const uint64_t exec_tenant_id = get_exec_tenant_id(tenant_id_);
|
||||
if (!inited_) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("sql proxy is null", K(ret));
|
||||
} else if (OB_UNLIKELY(tenant_name.empty())) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid exec_tenant_id", K(ret), K(tenant_name));
|
||||
} else if (OB_FAIL(sql.assign_fmt("SELECT * FROM %s WHERE job_id in (SELECT job_id "
|
||||
"FROM %s WHERE name = 'restore_tenant_name' AND value = '%.*s')",
|
||||
OB_ALL_RESTORE_JOB_TNAME,
|
||||
OB_ALL_RESTORE_JOB_TNAME,
|
||||
tenant_name.length(), tenant_name.ptr()))) {
|
||||
LOG_WARN("failed to assign sql", K(ret), K(tenant_name));
|
||||
} else if (OB_FAIL(get_restore_job_by_sql_(exec_tenant_id, sql, job_info))) {
|
||||
LOG_WARN("failed to get restore job by sql", KR(ret), K(sql), K(exec_tenant_id));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
int ObPhysicalRestoreTableOperator::get_restore_job_by_sql_(
|
||||
const uint64_t exec_tenant_id,
|
||||
const ObSqlString &sql, ObPhysicalRestoreJob &job_info)
|
||||
|
||||
@ -115,6 +115,8 @@ public:
|
||||
* */
|
||||
int get_job_by_tenant_name(const ObString &tenant_name,
|
||||
ObPhysicalRestoreJob &job_info);
|
||||
int get_job_by_restore_tenant_name(const ObString &tenant_name,
|
||||
ObPhysicalRestoreJob &job_info);
|
||||
|
||||
/*
|
||||
* description: check all ls has restored to consistent_scn
|
||||
|
||||
313
src/share/restore/ob_recover_table_persist_helper.cpp
Normal file
313
src/share/restore/ob_recover_table_persist_helper.cpp
Normal file
@ -0,0 +1,313 @@
|
||||
/**
|
||||
* 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 "ob_recover_table_persist_helper.h"
|
||||
#include "ob_import_table_struct.h"
|
||||
#include "share/inner_table/ob_inner_table_schema_constants.h"
|
||||
|
||||
using namespace oceanbase;
|
||||
using namespace share;
|
||||
ObRecoverTablePersistHelper::ObRecoverTablePersistHelper()
|
||||
: is_inited_(false), tenant_id_()
|
||||
{
|
||||
}
|
||||
|
||||
int ObRecoverTablePersistHelper::init(const uint64_t tenant_id)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if(!is_sys_tenant(tenant_id) && !is_user_tenant(tenant_id)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid tenant id", K(ret), K(tenant_id));
|
||||
} else if (OB_FAIL(table_op_.init(OB_ALL_RECOVER_TABLE_JOB_TNAME, *this))) {
|
||||
LOG_WARN("failed to init table op", K(ret));
|
||||
} else {
|
||||
tenant_id_ = tenant_id;
|
||||
is_inited_ = true;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRecoverTablePersistHelper::insert_recover_table_job(
|
||||
common::ObISQLClient &proxy, const ObRecoverTableJob &job) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t affect_rows = 0;
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObRecoverTablePersistHelper not init", K(ret));
|
||||
} else if (OB_FAIL(table_op_.insert_or_update_row(proxy, job, affect_rows))) {
|
||||
LOG_WARN("failed to insert or update row", K(ret), K(job));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRecoverTablePersistHelper::get_recover_table_job(
|
||||
common::ObISQLClient &proxy, const uint64_t tenant_id, const int64_t job_id,
|
||||
ObRecoverTableJob &job) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObRecoverTableJob::Key key;
|
||||
key.tenant_id_ = tenant_id;
|
||||
key.job_id_ = job_id;
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObRecoverTablePersistHelper not init", K(ret));
|
||||
} else if (OB_FAIL(table_op_.get_row(proxy, false, key, job))) {
|
||||
LOG_WARN("failed to get row", KR(ret), K(key));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRecoverTablePersistHelper::is_recover_table_job_exist(
|
||||
common::ObISQLClient &proxy,
|
||||
const uint64_t target_tenant_id,
|
||||
bool &is_exist) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
const uint64_t exec_tenant_id = get_exec_tenant_id();
|
||||
if (OB_FAIL(sql.assign_fmt("select count(*) cnt from %s where target_tenant_id=%lu", OB_ALL_RECOVER_TABLE_JOB_TNAME, target_tenant_id))) {
|
||||
LOG_WARN("fail to assign sql", K(ret));
|
||||
} else {
|
||||
HEAP_VAR(ObMySQLProxy::ReadResult, res) {
|
||||
ObMySQLResult *result = NULL;
|
||||
if (OB_FAIL(proxy.read(res, exec_tenant_id, sql.ptr()))) {
|
||||
LOG_WARN("failed to exec sql", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else if (OB_ISNULL(result = res.get_result())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("result is null", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else if (OB_FAIL(result->next())) {
|
||||
LOG_WARN("failed to get next row", K(ret));
|
||||
} else {
|
||||
int64_t cnt = 0;
|
||||
EXTRACT_INT_FIELD_MYSQL(*result, "cnt", cnt, int64_t);
|
||||
if (OB_FAIL(ret)) {
|
||||
} else {
|
||||
is_exist = 0 != cnt;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRecoverTablePersistHelper::advance_status(
|
||||
common::ObISQLClient &proxy, const ObRecoverTableJob &job, const ObRecoverTableStatus &next_status) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
int64_t affected_rows = -1;
|
||||
ObDMLSqlSplicer dml;
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObRecoverTablePersistHelper not init", K(ret));
|
||||
} else if (OB_FAIL(dml.add_pk_column(OB_STR_JOB_ID, job.get_job_id()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (OB_FAIL(dml.add_pk_column(OB_STR_TENANT_ID, job.get_tenant_id()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (next_status.is_finish() && OB_FAIL(dml.add_column(OB_STR_RESULT, job.get_result().get_result_str()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (next_status.is_finish() && OB_FAIL(dml.add_column(OB_STR_COMMENT, job.get_result().get_comment()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (next_status.is_finish() && OB_FAIL(dml.add_column(OB_STR_END_TS, job.get_end_ts()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (OB_FAIL(dml.add_column(OB_STR_STATUS, next_status.get_str()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (OB_FAIL(dml.splice_update_sql(OB_ALL_RECOVER_TABLE_JOB_TNAME, sql))) {
|
||||
LOG_WARN("failed to splice update sql", K(ret));
|
||||
} else if (OB_FAIL(sql.append_fmt(" and %s='%s'", OB_STR_STATUS, job.get_status().get_str()))) {
|
||||
LOG_WARN("failed to append fmt", K(ret));
|
||||
} else if (OB_FAIL(proxy.write(get_exec_tenant_id(), sql.ptr(), affected_rows))) {
|
||||
LOG_WARN("failed to write", K(ret), K(sql));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRecoverTablePersistHelper::force_cancel_recover_job(common::ObISQLClient &proxy) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
int64_t affected_rows = -1;
|
||||
ObDMLSqlSplicer dml;
|
||||
ObRecoverTableStatus status(ObRecoverTableStatus::CANCELING);
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObRecoverTablePersistHelper not init", K(ret));
|
||||
} else if (OB_FAIL(dml.add_pk_column(OB_STR_TENANT_ID, tenant_id_))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (OB_FAIL(dml.add_column(OB_STR_STATUS, status.get_str()))) {
|
||||
LOG_WARN("failed to add column", K(ret));
|
||||
} else if (OB_FAIL(dml.splice_update_sql(OB_ALL_RECOVER_TABLE_JOB_TNAME, sql))) {
|
||||
LOG_WARN("failed to splice update sql", K(ret));
|
||||
} else if (OB_FAIL(proxy.write(get_exec_tenant_id(), sql.ptr(), affected_rows))) {
|
||||
LOG_WARN("failed to exec sql", K(ret), K(sql));
|
||||
} else {
|
||||
LOG_INFO("success cancel recover job", K(tenant_id_));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRecoverTablePersistHelper::get_all_recover_table_job(
|
||||
common::ObISQLClient &proxy, common::ObIArray<ObRecoverTableJob> &jobs) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
const uint64_t exec_tenant_id = get_exec_tenant_id();
|
||||
jobs.reset();
|
||||
if (OB_FAIL(sql.assign_fmt("select * from %s", OB_ALL_RECOVER_TABLE_JOB_TNAME))) {
|
||||
LOG_WARN("fail to assign sql", K(ret));
|
||||
} else {
|
||||
HEAP_VAR(ObMySQLProxy::ReadResult, res) {
|
||||
ObMySQLResult *result = NULL;
|
||||
if (OB_FAIL(proxy.read(res, exec_tenant_id, sql.ptr()))) {
|
||||
LOG_WARN("failed to exec sql", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else if (OB_ISNULL(result = res.get_result())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("result is null", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else {
|
||||
while (OB_SUCC(ret)) {
|
||||
ObRecoverTableJob job;
|
||||
job.reset();
|
||||
if (OB_FAIL(result->next())) {
|
||||
if (OB_ITER_END == ret) {
|
||||
ret = OB_SUCCESS;
|
||||
break;
|
||||
} else {
|
||||
LOG_WARN("failed to get next row", K(ret));
|
||||
}
|
||||
} else if (OB_FAIL(job.parse_from(*result))) {
|
||||
LOG_WARN("failed to parse job result", K(ret));
|
||||
} else if (OB_FAIL(jobs.push_back(job))) {
|
||||
LOG_WARN("failed to push back job", K(ret), K(job));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG_INFO("get targets", K(ret), K(jobs), K(exec_tenant_id), K(sql));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRecoverTablePersistHelper::get_recover_table_job_by_initiator(common::ObISQLClient &proxy,
|
||||
const ObRecoverTableJob &initiator_job, ObRecoverTableJob &target_job) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
uint64_t initiator_tenant_id = initiator_job.get_tenant_id();
|
||||
int64_t initiator_job_id = initiator_job.get_job_id();
|
||||
const uint64_t exec_tenant_id = get_exec_tenant_id();
|
||||
if (OB_FAIL(sql.assign_fmt("select * from %s", OB_ALL_RECOVER_TABLE_JOB_TNAME))) {
|
||||
LOG_WARN("fail to assign sql", K(ret));
|
||||
} else if (OB_FAIL(sql.append_fmt(" where initiator_tenant_id =%lu and initiator_job_id=%ld", initiator_tenant_id, initiator_job_id))) {
|
||||
LOG_WARN("failed to append sql", K(ret), K(sql), K(initiator_tenant_id), K(initiator_job_id));
|
||||
} else {
|
||||
HEAP_VAR(ObMySQLProxy::ReadResult, res) {
|
||||
ObMySQLResult *result = NULL;
|
||||
if (OB_FAIL(proxy.read(res, exec_tenant_id, sql.ptr()))) {
|
||||
LOG_WARN("failed to exec sql", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else if (OB_ISNULL(result = res.get_result())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("result is null", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else if (OB_FAIL(result->next())) {
|
||||
if (OB_ITER_END == ret) {
|
||||
ret = OB_ENTRY_NOT_EXIST;
|
||||
}
|
||||
LOG_WARN("no row exist", K(ret));
|
||||
} else if (OB_FAIL(target_job.parse_from(*result))) {
|
||||
LOG_WARN("failed to parse row", K(ret));
|
||||
} else if (OB_ITER_END != result->next()) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("multi value exist", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else {
|
||||
ret = OB_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG_INFO("get recover table job", K(ret), K(target_job), K(sql));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRecoverTablePersistHelper::delete_recover_table_job(
|
||||
common::ObISQLClient &proxy, const ObRecoverTableJob &job) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t affect_rows = 0;
|
||||
ObRecoverTableJob::Key key;
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObRecoverTablePersistHelper not init", K(ret));
|
||||
} else if (OB_FAIL(job.get_pkey(key))) {
|
||||
LOG_WARN("failed to get pkey", K(ret));
|
||||
} else if (OB_FAIL(table_op_.delete_row(proxy, key, affect_rows))) {
|
||||
LOG_WARN("failed to delete row", K(ret), K(job));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRecoverTablePersistHelper::insert_recover_table_job_history(
|
||||
common::ObISQLClient &proxy, const ObRecoverTableJob &job) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t affect_rows = 0;
|
||||
ObInnerTableOperator table_op;
|
||||
if (IS_NOT_INIT) {
|
||||
ret = OB_NOT_INIT;
|
||||
LOG_WARN("ObRecoverTablePersistHelper not init", K(ret));
|
||||
} else if (OB_FAIL(table_op.init(OB_ALL_RECOVER_TABLE_JOB_HISTORY_TNAME, *this))) {
|
||||
LOG_WARN("failed to init table op", K(ret));
|
||||
} else if (OB_FAIL(table_op.insert_or_update_row(proxy, job, affect_rows))) {
|
||||
LOG_WARN("failed to insert or update row", K(ret), K(job));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRecoverTablePersistHelper::get_recover_table_job_history_by_initiator(common::ObISQLClient &proxy,
|
||||
const ObRecoverTableJob &initiator_job, ObRecoverTableJob &target_job) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSqlString sql;
|
||||
uint64_t initiator_tenant_id = initiator_job.get_tenant_id();
|
||||
int64_t initiator_job_id = initiator_job.get_job_id();
|
||||
const uint64_t exec_tenant_id = get_exec_tenant_id();
|
||||
if (OB_FAIL(sql.assign_fmt("select * from %s", OB_ALL_RECOVER_TABLE_JOB_HISTORY_TNAME))) {
|
||||
LOG_WARN("fail to assign sql", K(ret));
|
||||
} else if (OB_FAIL(sql.append_fmt(" where initiator_tenant_id =%lu and initiator_job_id=%ld", initiator_tenant_id, initiator_job_id))) {
|
||||
LOG_WARN("failed to append sql", K(ret), K(sql), K(initiator_tenant_id), K(initiator_job_id));
|
||||
} else {
|
||||
HEAP_VAR(ObMySQLProxy::ReadResult, res) {
|
||||
ObMySQLResult *result = NULL;
|
||||
if (OB_FAIL(proxy.read(res, exec_tenant_id, sql.ptr()))) {
|
||||
LOG_WARN("failed to exec sql", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else if (OB_ISNULL(result = res.get_result())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("result is null", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else if (OB_FAIL(result->next())) {
|
||||
if (OB_ITER_END == ret) {
|
||||
ret = OB_ENTRY_NOT_EXIST;
|
||||
}
|
||||
LOG_WARN("no row exist", K(ret));
|
||||
} else if (OB_FAIL(target_job.parse_from(*result))) {
|
||||
LOG_WARN("failed to parse row", K(ret));
|
||||
} else if (OB_ITER_END != result->next()) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("multi value exist", K(ret), K(sql), K(exec_tenant_id));
|
||||
} else {
|
||||
ret = OB_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
LOG_INFO("get recover table job history", K(ret), K(target_job), K(sql));
|
||||
return ret;
|
||||
}
|
||||
64
src/share/restore/ob_recover_table_persist_helper.h
Normal file
64
src/share/restore/ob_recover_table_persist_helper.h
Normal file
@ -0,0 +1,64 @@
|
||||
/**
|
||||
* 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 OCEANBASE_SHARE_RECOVER_TABLE_PERSIST_HELPER_H
|
||||
#define OCEANBASE_SHARE_RECOVER_TABLE_PERSIST_HELPER_H
|
||||
|
||||
#include "lib/ob_define.h"
|
||||
#include "share/ob_inner_table_operator.h"
|
||||
#include "share/restore/ob_import_table_struct.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
class ObRecoverTablePersistHelper final : public ObIExecTenantIdProvider
|
||||
{
|
||||
public:
|
||||
ObRecoverTablePersistHelper();
|
||||
virtual ~ObRecoverTablePersistHelper() {}
|
||||
int init(const uint64_t tenant_id);
|
||||
void reset() { is_inited_ = false; }
|
||||
uint64_t get_exec_tenant_id() const override { return gen_meta_tenant_id(tenant_id_); }
|
||||
int insert_recover_table_job(common::ObISQLClient &proxy, const ObRecoverTableJob &job) const;
|
||||
|
||||
int get_all_recover_table_job(common::ObISQLClient &proxy, common::ObIArray<ObRecoverTableJob> &jobs) const;
|
||||
|
||||
int get_recover_table_job(common::ObISQLClient &proxy, const uint64_t tenant_id, const int64_t job_id,
|
||||
ObRecoverTableJob &job) const;
|
||||
|
||||
int is_recover_table_job_exist(common::ObISQLClient &proxy, const uint64_t target_tenant_id, bool &is_exist) const;
|
||||
|
||||
int advance_status(common::ObISQLClient &proxy,
|
||||
const ObRecoverTableJob &job, const ObRecoverTableStatus &next_status) const;
|
||||
int force_cancel_recover_job(common::ObISQLClient &proxy) const;
|
||||
|
||||
int get_recover_table_job_by_initiator(common::ObISQLClient &proxy,
|
||||
const ObRecoverTableJob &initiator_job, ObRecoverTableJob &target_job) const;
|
||||
|
||||
int delete_recover_table_job(common::ObISQLClient &proxy, const ObRecoverTableJob &job) const;
|
||||
int insert_recover_table_job_history(common::ObISQLClient &proxy, const ObRecoverTableJob &job) const;
|
||||
|
||||
int get_recover_table_job_history_by_initiator(common::ObISQLClient &proxy,
|
||||
const ObRecoverTableJob &initiator_job, ObRecoverTableJob &target_job) const;
|
||||
TO_STRING_KV(K_(is_inited), K_(tenant_id));
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(ObRecoverTablePersistHelper);
|
||||
bool is_inited_;
|
||||
uint64_t tenant_id_; // sys or user tenant id
|
||||
ObInnerTableOperator table_op_;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
49
src/share/restore/ob_recover_table_util.cpp
Normal file
49
src/share/restore/ob_recover_table_util.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/**
|
||||
* 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_recover_table_util.h"
|
||||
|
||||
using namespace oceanbase;
|
||||
using namespace share;
|
||||
|
||||
int ObRecoverTableUtil::check_compatible(const uint64_t target_tenant_id)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
uint64_t data_version = 0;
|
||||
// 1. check sys tenant data version
|
||||
if (OB_FAIL(GET_MIN_DATA_VERSION(OB_SYS_TENANT_ID, data_version))) {
|
||||
LOG_WARN("fail to get sys data version", K(ret));
|
||||
} else if (data_version < DATA_VERSION_4_2_1_0) {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
LOG_WARN("Tenant COMPATIBLE is below 4.2.1.0, recover table is not supported", K(ret), K(data_version));
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "Tenant COMPATIBLE is below 4.2.1.0, recover table is");
|
||||
}
|
||||
|
||||
// 2. check target meta tenant data version
|
||||
if (FAILEDx(GET_MIN_DATA_VERSION(gen_meta_tenant_id(target_tenant_id), data_version))) {
|
||||
LOG_WARN("fail to get meta tenant data version", K(ret), K(target_tenant_id));
|
||||
} else if (data_version < DATA_VERSION_4_2_1_0) {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
LOG_WARN("Tenant COMPATIBLE is below 4.2.1.0, recover table is not supported", K(ret), K(data_version));
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "Tenant COMPATIBLE is below 4.2.1.0, recover table is");
|
||||
}
|
||||
|
||||
// 3. check target user tenant data version
|
||||
if (FAILEDx(GET_MIN_DATA_VERSION(target_tenant_id, data_version))) {
|
||||
LOG_WARN("fail to get user tenant data version", K(ret), K(target_tenant_id));
|
||||
} else if (data_version < DATA_VERSION_4_2_1_0) {
|
||||
ret = OB_NOT_SUPPORTED;
|
||||
LOG_WARN("Tenant COMPATIBLE is below 4.2.1.0, recover table is not supported", K(ret), K(data_version));
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "Tenant COMPATIBLE is below 4.2.1.0, recover table is");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
29
src/share/restore/ob_recover_table_util.h
Normal file
29
src/share/restore/ob_recover_table_util.h
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* 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 OCEANBASE_SHARE_RECOVER_TABLE_UTIL_H
|
||||
#define OCEANBASE_SHARE_RECOVER_TABLE_UTIL_H
|
||||
#include "lib/ob_define.h"
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
class ObRecoverTableUtil final
|
||||
{
|
||||
public:
|
||||
static int check_compatible(const uint64_t target_tenant_id);
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
122
src/share/restore/ob_remap_schema_item.h
Normal file
122
src/share/restore/ob_remap_schema_item.h
Normal file
@ -0,0 +1,122 @@
|
||||
/**
|
||||
* 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 OCEANBASE_SHARE_REMAP_SCHEMA_ITEM_H
|
||||
#define OCEANBASE_SHARE_REMAP_SCHEMA_ITEM_H
|
||||
|
||||
#include "share/restore/ob_import_table_item.h"
|
||||
#include "share/restore/ob_import_partition_item.h"
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
|
||||
template <typename S, typename T>
|
||||
struct ObRemapSchemaItem : public ObIImportItem
|
||||
{
|
||||
OB_UNIS_VERSION(1);
|
||||
public:
|
||||
ObRemapSchemaItem() : ObIImportItem(ItemType::REMAP)
|
||||
{}
|
||||
|
||||
virtual void reset() override;
|
||||
virtual bool is_valid() const override;
|
||||
virtual int64_t get_format_serialize_size() const override;
|
||||
virtual int format_serialize(
|
||||
char *buf,
|
||||
const int64_t buf_len,
|
||||
int64_t &pos) const override;
|
||||
virtual int deep_copy(common::ObIAllocator &allocator, const ObIImportItem &src) override;
|
||||
virtual bool operator==(const ObIImportItem &other) const override;
|
||||
|
||||
using ObIImportItem::format_serialize;
|
||||
int assign(const ObRemapSchemaItem &other);
|
||||
|
||||
TO_STRING_KV(K_(src), K_(target));
|
||||
|
||||
public:
|
||||
S src_;
|
||||
T target_;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <typename S, typename T>
|
||||
class ObRemapSchemaItemArray : public ObIImportItemFormatProvider, public ObImportItemHexFormatImpl
|
||||
{
|
||||
OB_UNIS_VERSION(1);
|
||||
public:
|
||||
ObRemapSchemaItemArray() {}
|
||||
virtual int64_t get_format_serialize_size() const override;
|
||||
virtual int format_serialize(
|
||||
char *buf,
|
||||
const int64_t buf_len,
|
||||
int64_t &pos) const override;
|
||||
|
||||
virtual void reset();
|
||||
|
||||
int assign(const ObRemapSchemaItemArray<S, T> &other);
|
||||
int add_item(const ObRemapSchemaItem<S, T> &item);
|
||||
bool is_empty() const { return remap_items_.empty(); }
|
||||
bool is_src_exist(const S &src) const;
|
||||
bool is_src_exist(const S &src, const S *&out) const;
|
||||
bool is_target_exist(const T &target) const;
|
||||
bool is_target_exist(const T &target, const T *&out) const;
|
||||
const common::ObSArray<ObRemapSchemaItem<S, T>> &get_remap_items() const { return remap_items_; }
|
||||
bool is_remap_target_exist(const S &src, const T *&out) const;
|
||||
|
||||
template<class Operator>
|
||||
int foreach(Operator &op) const
|
||||
{
|
||||
int ret = common::OB_SUCCESS;
|
||||
ARRAY_FOREACH(remap_items_, idx) {
|
||||
const ObRemapSchemaItem<S, T> &remap_item = remap_items_.at(idx);
|
||||
if (OB_FAIL(op(remap_item))) {
|
||||
SHARE_LOG(WARN, "fail to do operator", K(ret), K(remap_item));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
TO_STRING_KV(K_(remap_items));
|
||||
|
||||
protected:
|
||||
common::ObArenaAllocator allocator_;
|
||||
|
||||
private:
|
||||
common::ObSArray<ObRemapSchemaItem<S, T>> remap_items_;
|
||||
};
|
||||
|
||||
using ObRemapDatabaseItem = ObRemapSchemaItem<ObImportDatabaseItem, ObImportDatabaseItem>;
|
||||
using ObRemapTableItem = ObRemapSchemaItem<ObImportTableItem, ObImportTableItem>;
|
||||
using ObRemapPartitionItem = ObRemapSchemaItem<ObImportPartitionItem, ObImportTableItem>;
|
||||
using ObRemapTablespaceItem = ObRemapSchemaItem<ObImportTablespaceItem, ObImportTablespaceItem>;
|
||||
using ObRemapTablegroupItem = ObRemapSchemaItem<ObImportTablegroupItem, ObImportTablegroupItem>;
|
||||
|
||||
|
||||
using ObRemapDatabaseArray = ObRemapSchemaItemArray<ObImportDatabaseItem, ObImportDatabaseItem>;
|
||||
using ObRemapTableArray = ObRemapSchemaItemArray<ObImportTableItem, ObImportTableItem>;
|
||||
using ObRemapPartitionArray = ObRemapSchemaItemArray<ObImportPartitionItem, ObImportTableItem>;
|
||||
using ObRemapTablespaceArray = ObRemapSchemaItemArray<ObImportTablespaceItem, ObImportTablespaceItem>;
|
||||
using ObRemapTablegroupArray = ObRemapSchemaItemArray<ObImportTablegroupItem, ObImportTablegroupItem>;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef INCLUDE_OB_REMAP_SCHEMA_ITEM_HPP
|
||||
#define INCLUDE_OB_REMAP_SCHEMA_ITEM_HPP
|
||||
#include "ob_remap_schema_item.hpp"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
376
src/share/restore/ob_remap_schema_item.hpp
Normal file
376
src/share/restore/ob_remap_schema_item.hpp
Normal file
@ -0,0 +1,376 @@
|
||||
/**
|
||||
* 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 INCLUDE_OB_REMAP_SCHEMA_ITEM_HPP
|
||||
#define INCLUDE_OB_REMAP_SCHEMA_ITEM_HPP
|
||||
#include "share/restore/ob_remap_schema_item.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace oceanbase
|
||||
{
|
||||
namespace share
|
||||
{
|
||||
|
||||
// ObRemapSchemaItem
|
||||
template<typename S, typename T>
|
||||
int64_t ObRemapSchemaItem<S, T>::get_serialize_size() const
|
||||
{
|
||||
int64_t size = 0;
|
||||
size += src_.get_serialize_size();
|
||||
size += target_.get_serialize_size();
|
||||
return size;
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
int ObRemapSchemaItem<S, T>::serialize(SERIAL_PARAMS) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t new_pos = pos;
|
||||
if ((NULL == buf) || (buf_len <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid arguments.", K(ret), KP(buf), K(buf_len));
|
||||
} else if (OB_FAIL(src_.serialize(buf, buf_len, new_pos))) {
|
||||
SHARE_LOG(WARN, "serialize src item failed", K(ret));
|
||||
} else if (OB_FAIL(target_.serialize(buf, buf_len, new_pos))) {
|
||||
SHARE_LOG(WARN, "serialize target item failed", K(ret));
|
||||
} else {
|
||||
pos = new_pos;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
int ObRemapSchemaItem<S, T>::deserialize(DESERIAL_PARAMS)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t new_pos = pos;
|
||||
if ((NULL == buf) || (data_len <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid arguments.", K(ret), KP(buf), K(data_len));
|
||||
} else if (OB_FAIL(src_.deserialize(buf, data_len, new_pos))) {
|
||||
SHARE_LOG(WARN, "deserialize src item failed", K(ret));
|
||||
} else if (OB_FAIL(target_.deserialize(buf, data_len, new_pos))) {
|
||||
SHARE_LOG(WARN, "deserialize target item failed", K(ret));
|
||||
} else {
|
||||
pos = new_pos;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
template<typename S, typename T>
|
||||
void ObRemapSchemaItem<S, T>::reset()
|
||||
{
|
||||
src_.reset();
|
||||
target_.reset();
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
bool ObRemapSchemaItem<S, T>::is_valid() const
|
||||
{
|
||||
return src_.is_valid() && target_.is_valid();
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
int64_t ObRemapSchemaItem<S, T>::get_format_serialize_size() const
|
||||
{
|
||||
// Concatenate src and target with ':'.
|
||||
return src_.get_format_serialize_size() + target_.get_format_serialize_size() + 1;
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
int ObRemapSchemaItem<S, T>::format_serialize(
|
||||
char *buf,
|
||||
const int64_t buf_len,
|
||||
int64_t &pos) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if ((NULL == buf) || (buf_len <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid arguments.", K(ret), KP(buf), K(buf_len));
|
||||
} else if (!is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid argument", K(ret));
|
||||
} else if (OB_FAIL(src_.format_serialize(buf, buf_len, pos))) {
|
||||
SHARE_LOG(WARN, "fail to format str", K(ret), K(pos), K(buf_len), K_(src));
|
||||
} else if (OB_FAIL(databuff_printf(buf, buf_len, pos, "%s", ":"))) {
|
||||
SHARE_LOG(WARN, "fail to format str", K(ret), K(pos), K(buf_len));
|
||||
} else if (OB_FAIL(target_.format_serialize(buf, buf_len, pos))) {
|
||||
SHARE_LOG(WARN, "fail to format str", K(ret), K(pos), K(buf_len), K_(target));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
int ObRemapSchemaItem<S, T>::deep_copy(
|
||||
common::ObIAllocator &allocator,
|
||||
const ObIImportItem &src)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!src.is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid argument", K(ret), K(src));
|
||||
} else if (get_item_type() != src.get_item_type()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "item type not match", K(ret), "src", src.get_item_type(), "dest", get_item_type());
|
||||
} else {
|
||||
const ObRemapSchemaItem<S, T> &other = static_cast<const ObRemapSchemaItem<S, T> &>(src);
|
||||
if (OB_FAIL(src_.deep_copy(allocator, other.src_))) {
|
||||
SHARE_LOG(WARN, "failed to copy src", K(ret), K(src));
|
||||
} else if (OB_FAIL(target_.deep_copy(allocator, other.target_))) {
|
||||
SHARE_LOG(WARN, "failed to copy target", K(ret), K(src));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
bool ObRemapSchemaItem<S, T>::operator==(const ObIImportItem &other) const
|
||||
{
|
||||
bool is_equal = false;
|
||||
if (get_item_type() == other.get_item_type()) {
|
||||
const ObRemapSchemaItem<S, T> &the_other = static_cast<const ObRemapSchemaItem<S, T> &>(other);
|
||||
|
||||
is_equal = src_ == the_other.src_ && target_ == the_other.target_;
|
||||
}
|
||||
return is_equal;
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
int ObRemapSchemaItem<S, T>::assign(const ObRemapSchemaItem &other)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!other.is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid argument", K(ret), K(other));
|
||||
} else if (OB_FAIL(src_.assign(other.src_))) {
|
||||
SHARE_LOG(WARN, "failed to assign src", K(ret), K(other));
|
||||
} else if (OB_FAIL(target_.assign(other.target_))) {
|
||||
SHARE_LOG(WARN, "failed to assign target", K(ret), K(other));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// ObRemapSchemaItemArray
|
||||
template<typename S, typename T>
|
||||
int64_t ObRemapSchemaItemArray<S, T>::get_serialize_size(void) const
|
||||
{
|
||||
return remap_items_.get_serialize_size();
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
int ObRemapSchemaItemArray<S, T>::serialize(SERIAL_PARAMS) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if ((NULL == buf) || (buf_len <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid argument", K(ret), KP(buf), K(buf_len), K(pos));
|
||||
} else if (OB_FAIL(remap_items_.serialize(buf, buf_len, pos))) {
|
||||
SHARE_LOG(WARN, "failed to serialize", K(ret), KP(buf), K(buf_len), K(pos));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
int ObRemapSchemaItemArray<S, T>::deserialize(DESERIAL_PARAMS)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
common::ObSArray<ObRemapSchemaItem<S, T>> tmp_remap_items;
|
||||
if ((NULL == buf) || (data_len <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid argument", K(ret), KP(buf), K(data_len), K(pos));
|
||||
} else if (OB_FALSE_IT(reset())) {
|
||||
} else if (OB_FAIL(tmp_remap_items.deserialize(buf, data_len, pos))) {
|
||||
SHARE_LOG(WARN, "failed to deserialize", K(ret), K(buf), K(data_len), K(pos));
|
||||
}
|
||||
ARRAY_FOREACH(tmp_remap_items, idx) {
|
||||
const ObRemapSchemaItem<S, T> &item = tmp_remap_items.at(idx);
|
||||
if (OB_FAIL(add_item(item))) {
|
||||
SHARE_LOG(WARN, "failed to add item", K(ret), K(idx), K(item));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
template<typename S, typename T>
|
||||
int64_t ObRemapSchemaItemArray<S, T>::get_format_serialize_size() const
|
||||
{
|
||||
int64_t size = 1; // include '\0'
|
||||
ARRAY_FOREACH_NORET(remap_items_, idx) {
|
||||
const ObRemapSchemaItem<S, T> &item = remap_items_.at(idx);
|
||||
// item is concatenated with ','
|
||||
size += 0 == idx ? 0 : 1;
|
||||
size += item.get_format_serialize_size();
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
int ObRemapSchemaItemArray<S, T>::format_serialize(
|
||||
char *buf,
|
||||
const int64_t buf_len,
|
||||
int64_t &pos) const
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t new_pos = pos;
|
||||
if ((NULL == buf) || (buf_len <= 0)) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid arguments.", K(ret), KP(buf), K(buf_len));
|
||||
} else if (remap_items_.empty()) {
|
||||
buf[new_pos++] = 0;
|
||||
}
|
||||
|
||||
ARRAY_FOREACH(remap_items_, idx) {
|
||||
const ObRemapSchemaItem<S, T> &remap_item = remap_items_.at(idx);
|
||||
// concatenated items with ','
|
||||
if (0 < idx && OB_FAIL(databuff_printf(buf, buf_len, new_pos, "%s", ","))) {
|
||||
SHARE_LOG(WARN, "fail to append str", K(ret), K(new_pos), K(buf_len));
|
||||
} else if (OB_FAIL(remap_item.format_serialize(buf, buf_len, new_pos))) {
|
||||
SHARE_LOG(WARN, "fail to format str", K(ret), K(new_pos), K(buf_len));
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
pos = new_pos;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
void ObRemapSchemaItemArray<S, T>::reset()
|
||||
{
|
||||
remap_items_.reset();
|
||||
allocator_.reset();
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
int ObRemapSchemaItemArray<S, T>::assign(const ObRemapSchemaItemArray<S, T> &other)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
const common::ObSArray<ObRemapSchemaItem<S, T>> &remap_items = other.get_remap_items();
|
||||
|
||||
reset();
|
||||
ARRAY_FOREACH(remap_items, idx) {
|
||||
const ObRemapSchemaItem<S, T> &item = remap_items.at(idx);
|
||||
if (OB_FAIL(add_item(item))) {
|
||||
SHARE_LOG(WARN, "failed to add item", K(ret), K(idx), K(item));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
bool ObRemapSchemaItemArray<S, T>::is_src_exist(const S &src) const
|
||||
{
|
||||
bool is_exist = false;
|
||||
ARRAY_FOREACH_NORET(remap_items_, idx) {
|
||||
const ObRemapSchemaItem<S, T> &tmp = remap_items_.at(idx);
|
||||
if (tmp.src_ == src) {
|
||||
is_exist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return is_exist;
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
bool ObRemapSchemaItemArray<S, T>::is_src_exist(
|
||||
const S &src,
|
||||
const S *&out) const
|
||||
{
|
||||
bool is_exist = false;
|
||||
ARRAY_FOREACH_NORET(remap_items_, idx) {
|
||||
const ObRemapSchemaItem<S, T> &tmp = remap_items_.at(idx);
|
||||
if (tmp.src_ == src) {
|
||||
is_exist = true;
|
||||
out = &tmp.src_;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return is_exist;
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
bool ObRemapSchemaItemArray<S, T>::is_target_exist(const T &target) const
|
||||
{
|
||||
bool is_exist = false;
|
||||
ARRAY_FOREACH_NORET(remap_items_, idx) {
|
||||
const ObRemapSchemaItem<S, T> &tmp = remap_items_.at(idx);
|
||||
if (tmp.target_ == target) {
|
||||
is_exist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return is_exist;
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
bool ObRemapSchemaItemArray<S, T>::is_target_exist(
|
||||
const T &target,
|
||||
const T *&out) const
|
||||
{
|
||||
bool is_exist = false;
|
||||
ARRAY_FOREACH_NORET(remap_items_, idx) {
|
||||
const ObRemapSchemaItem<S, T> &tmp = remap_items_.at(idx);
|
||||
if (tmp.target_ == target) {
|
||||
is_exist = true;
|
||||
out = &tmp.target_;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return is_exist;
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
bool ObRemapSchemaItemArray<S, T>::is_remap_target_exist(const S &src, const T *&out) const
|
||||
{
|
||||
bool is_exist = false;
|
||||
ARRAY_FOREACH_NORET(remap_items_, idx) {
|
||||
const ObRemapSchemaItem<S, T> &tmp = remap_items_.at(idx);
|
||||
if (tmp.src_ == src) {
|
||||
out = &tmp.target_;
|
||||
is_exist = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return is_exist;
|
||||
}
|
||||
|
||||
template<typename S, typename T>
|
||||
int ObRemapSchemaItemArray<S, T>::add_item(const ObRemapSchemaItem<S, T> &item)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObRemapSchemaItem<S, T> remap_item;
|
||||
if (!item.is_valid()) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
SHARE_LOG(WARN, "invalid argument", K(ret), K(item));
|
||||
} else if (OB_FAIL(remap_item.deep_copy(allocator_, item))) {
|
||||
SHARE_LOG(WARN, "failed to copy item", K(ret), K(item));
|
||||
} else if (OB_FAIL(remap_items_.push_back(remap_item))) {
|
||||
SHARE_LOG(WARN, "failed to push back item", K(ret), K(item));
|
||||
} else {
|
||||
SHARE_LOG(INFO, "add one remap item", K(item));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user