[SCHEMA] Fix memory expansion problem while refresh full schema

This commit is contained in:
tino247 2023-08-07 13:18:19 +00:00 committed by ob-robot
parent b70f0e35b7
commit 7c789f265f
12 changed files with 363 additions and 180 deletions

View File

@ -1783,10 +1783,14 @@ int ObMultiVersionSchemaService::broadcast_tenant_schema(
LOG_INFO("add sys table schema", KR(ret), K(tenant_id), KPC(table_schema));
}
}
ObArray<ObSimpleTableSchemaV2> simple_table_schemas;
auto attr = SET_USE_500("BroFullSchema", ObCtxIds::SCHEMA_SERVICE);
ObArenaAllocator allocator(attr);
ObArray<ObSimpleTableSchemaV2*> simple_table_schemas(
common::OB_MALLOC_NORMAL_BLOCK_SIZE,
common::ModulePageAllocator(allocator));
ObSchemaMgr *schema_mgr_for_cache = NULL;
const bool refresh_full_schema = true;
if (FAILEDx(convert_to_simple_schema(table_schemas, simple_table_schemas))) {
if (FAILEDx(convert_to_simple_schema(allocator, table_schemas, simple_table_schemas))) {
LOG_WARN("failed to convert", KR(ret), K(tenant_id));
} else if (OB_FAIL(schema_mgr_for_cache_map_.get_refactored(
tenant_id, schema_mgr_for_cache))) {

View File

@ -1416,37 +1416,32 @@ int ObSchemaFetcher::fetch_table_schema(const ObRefreshSchemaStatus &schema_stat
int ret = OB_SUCCESS;
table_schema = NULL;
ObSimpleTableSchemaV2 *tmp_table_schema = NULL;
SchemaKey table_schema_key;
table_schema_key.tenant_id_ = schema_status.tenant_id_;
table_schema_key.table_id_ = table_id;
ObArray<SchemaKey> schema_keys;
ObArray<ObSimpleTableSchemaV2> schema_array;
ObArray<ObSimpleTableSchemaV2 *> schema_array;
if (!check_inner_stat()) {
ret = OB_INNER_STAT_ERROR;
LOG_WARN("inner stat error", K(ret));
LOG_WARN("inner stat error", KR(ret));
} else if (OB_INVALID_ID == table_id || schema_version < 0) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid argument", K(ret), K(table_id), K(schema_version));
LOG_WARN("invalid argument", KR(ret), K(table_id), K(schema_version));
} else if (OB_FAIL(schema_keys.push_back(table_schema_key))) {
LOG_WARN("fail to push back schema key", K(ret), K(table_id), K(schema_version));
LOG_WARN("fail to push back schema key", KR(ret), K(table_id), K(schema_version));
} else if (OB_FAIL(schema_service_->get_batch_tables(schema_status,
*sql_client_,
allocator,
schema_version,
schema_keys,
schema_array))) {
LOG_WARN("get table schema failed", K(ret), K(table_id), K(schema_version));
LOG_WARN("get table schema failed", KR(ret), K(table_id), K(schema_version));
} else if (OB_UNLIKELY(1 != schema_array.count())) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("unexpected schema count", K(ret), K(table_id), K(schema_version));
} else if (OB_FAIL(ObSchemaUtils::alloc_schema(allocator, schema_array.at(0), tmp_table_schema))) {
LOG_WARN("fail to alloc new var", K(ret), K(table_id), K(schema_version));
} else if (OB_ISNULL(tmp_table_schema)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("table schema is NULL", K(ret), K(table_id), K(schema_version));
LOG_WARN("unexpected schema count", KR(ret), K(table_id), K(schema_version));
} else {
table_schema = tmp_table_schema;
LOG_TRACE("fetch table schema succeed", K(ret), K(table_id), K(schema_version), KPC(table_schema));
table_schema = schema_array.at(0);
LOG_TRACE("fetch table schema succeed", KR(ret), K(table_id), K(schema_version), KPC(table_schema));
}
return ret;
}

View File

@ -2295,7 +2295,7 @@ int ObSchemaMgr::get_tablegroup_schema(
}
int ObSchemaMgr::add_tables(
const ObIArray<ObSimpleTableSchemaV2> &table_schemas,
const ObIArray<ObSimpleTableSchemaV2 *> &table_schemas,
const bool refresh_full_schema/*= false*/)
{
int ret = OB_SUCCESS;
@ -2311,26 +2311,37 @@ int ObSchemaMgr::add_tables(
} else {
bool desc_order = true;
if (OB_SUCC(ret) && table_schemas.count() >= 2) {
// 1. when refresh user simple table schemas, table_schemas will be sorted in desc order by sql.
// 2. when broadcast schema or refresh core/system tables or other situations, table_schemas will be sorted in asc order.
// Because table_infos_ are sorted in asc order, we should also add table in asc order to reduce performance lost.
// Normally, we consider table_schemas are in desc order in most situations.
desc_order = table_schemas.at(0).get_table_id() > table_schemas.at(1).get_table_id();
if (OB_ISNULL(table_schemas.at(0)) || OB_ISNULL(table_schemas.at(1))) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("table is null", KR(ret), KP(table_schemas.at(0)), K(table_schemas.at(1)));
} else {
// 1. when refresh user simple table schemas, table_schemas will be sorted in desc order by sql.
// 2. when broadcast schema or refresh core/system tables or other situations, table_schemas will be sorted in asc order.
// Because table_infos_ are sorted in asc order, we should also add table in asc order to reduce performance lost.
// Normally, we consider table_schemas are in desc order in most situations.
desc_order = table_schemas.at(0)->get_table_id() > table_schemas.at(1)->get_table_id();
}
}
if (OB_SUCC(ret)) {
if (desc_order) {
for (int64_t i = table_schemas.count() - 1; OB_SUCC(ret) && i >= 0; i--) {
const ObSimpleTableSchemaV2 &table = table_schemas.at(i);
if (OB_FAIL(add_table(table, &cost_array))) {
LOG_WARN("add table failed", KR(ret), K(table));
const ObSimpleTableSchemaV2 *table = table_schemas.at(i);
if (OB_ISNULL(table)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("table is null", KR(ret), K(i));
} else if (OB_FAIL(add_table(*table, &cost_array))) {
LOG_WARN("add table failed", KR(ret), KPC(table));
}
} // end for
} else {
for (int64_t i = 0; OB_SUCC(ret) && i < table_schemas.count(); i++) {
const ObSimpleTableSchemaV2 &table = table_schemas.at(i);
if (OB_FAIL(add_table(table, &cost_array))) {
LOG_WARN("add table failed", KR(ret), K(table));
const ObSimpleTableSchemaV2 *table = table_schemas.at(i);
if (OB_ISNULL(table)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("table is null", KR(ret), K(i));
} else if (OB_FAIL(add_table(*table, &cost_array))) {
LOG_WARN("add table failed", KR(ret), KPC(table));
}
} // end for
}
@ -2343,7 +2354,7 @@ int ObSchemaMgr::add_tables(
}
int ObSchemaMgr::reserved_mem_for_tables_(
const ObIArray<ObSimpleTableSchemaV2> &table_schemas)
const ObIArray<ObSimpleTableSchemaV2*> &table_schemas)
{
int ret = OB_SUCCESS;
int64_t start_time = ObTimeUtility::current_time();
@ -2359,37 +2370,42 @@ int ObSchemaMgr::reserved_mem_for_tables_(
const int64_t OBJECT_SIZE = sizeof(void*);
if (!check_inner_stat()) {
ret = OB_NOT_INIT;
LOG_WARN("not init", K(ret));
LOG_WARN("not init", KR(ret));
} else if (OB_FAIL(table_infos_.reserve(table_cnt))) {
LOG_WARN("fail to reserved array", KR(ret), K(table_cnt));
} else {
//(void) table_id_map_.set_sub_map_mem_size(table_cnt * OBJECT_SIZE);
for (int64_t i = 0; OB_SUCC(ret) && i < table_schemas.count(); i++) {
const ObSimpleTableSchemaV2 &table = table_schemas.at(i);
if (table.is_index_table() || table.is_materialized_view()) {
index_cnt++;
} else if (table.is_aux_vp_table()) {
vp_cnt++;
} else if (table.is_aux_lob_meta_table()) {
lob_meta_cnt++;
} else if (table.is_aux_lob_piece_table()) {
lob_piece_cnt++;
} else if (table.is_user_hidden_table()) {
hidden_table_cnt++;
const ObSimpleTableSchemaV2 *table = table_schemas.at(i);
if (OB_ISNULL(table)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("table is null", KR(ret), K(i));
} else {
other_table_cnt++;
}
if (table->is_index_table() || table->is_materialized_view()) {
index_cnt++;
} else if (table->is_aux_vp_table()) {
vp_cnt++;
} else if (table->is_aux_lob_meta_table()) {
lob_meta_cnt++;
} else if (table->is_aux_lob_piece_table()) {
lob_piece_cnt++;
} else if (table->is_user_hidden_table()) {
hidden_table_cnt++;
} else {
other_table_cnt++;
}
if ((table.is_table() || table.is_oracle_tmp_table())
&& !table.is_user_hidden_table()) {
fk_cnt += table.get_simple_foreign_key_info_array().count();
}
if ((table->is_table() || table->is_oracle_tmp_table())
&& !table->is_user_hidden_table()) {
fk_cnt += table->get_simple_foreign_key_info_array().count();
}
if ((table.is_table() || table.is_oracle_tmp_table())
&& !table.is_user_hidden_table()
&& !table.is_mysql_tmp_table()) {
cst_cnt += table.get_simple_constraint_info_array().count();
if ((table->is_table() || table->is_oracle_tmp_table())
&& !table->is_user_hidden_table()
&& !table->is_mysql_tmp_table()) {
cst_cnt += table->get_simple_constraint_info_array().count();
}
}
} // end for

View File

@ -575,7 +575,7 @@ public:
int get_tablegroup_ids_in_tenant(const uint64_t tenant_id,
common::ObIArray<uint64_t> &tablegroup_id_array);
// table
int add_tables(const common::ObIArray<ObSimpleTableSchemaV2> &table_schemas,
int add_tables(const common::ObIArray<ObSimpleTableSchemaV2 *> &table_schemas,
const bool refresh_full_schema = false);
int del_tables(const common::ObIArray<ObTenantTableId> &tables);
int add_table(const ObSimpleTableSchemaV2 &table_schema,
@ -897,7 +897,7 @@ private:
int get_table_statistics(ObSchemaStatisticsInfo &schema_info) const;
int reserved_mem_for_tables_(
const common::ObIArray<share::schema::ObSimpleTableSchemaV2> &table_schemas);
const common::ObIArray<share::schema::ObSimpleTableSchemaV2*> &table_schemas);
private:
common::ObArenaAllocator local_allocator_;
common::ObIAllocator &allocator_;

View File

@ -229,12 +229,12 @@ public:
ObObj &out_var_obj);
//for batch table
template<typename T>
template<typename T, typename TABLE_SCHEMA>
static int retrieve_table_schema(const uint64_t tenant_id,
const bool check_deleted,
T &result,
common::ObIAllocator &allocator,
common::ObIArray<ObTableSchema *> &table_schema_array);
common::ObIArray<TABLE_SCHEMA *> &table_schema_array);
template<typename TABLE_SCHEMA, typename SCHEMA, typename T>
static int retrieve_schema(const uint64_t tenant_id,
@ -359,7 +359,6 @@ public:
RETRIEVE_SCHEMA_FUNC_DECLARE(user);
RETRIEVE_SCHEMA_FUNC_DECLARE(database);
RETRIEVE_SCHEMA_FUNC_DECLARE(tablegroup);
RETRIEVE_SCHEMA_FUNC_DECLARE(table);
RETRIEVE_SCHEMA_FUNC_DECLARE(outline);
RETRIEVE_SCHEMA_FUNC_DECLARE(db_priv);
RETRIEVE_SCHEMA_FUNC_DECLARE(table_priv);
@ -444,7 +443,6 @@ public:
FILL_SCHEMA_FUNC_DECLARE(user, ObSimpleUserSchema);
FILL_SCHEMA_FUNC_DECLARE(database, ObSimpleDatabaseSchema);
FILL_SCHEMA_FUNC_DECLARE(tablegroup, ObSimpleTablegroupSchema);
FILL_SCHEMA_FUNC_DECLARE(table, ObSimpleTableSchemaV2);
FILL_SCHEMA_FUNC_DECLARE(outline, ObSimpleOutlineSchema);
FILL_SCHEMA_FUNC_DECLARE(routine, ObSimpleRoutineSchema);
FILL_SCHEMA_FUNC_DECLARE(synonym, ObSimpleSynonymSchema);
@ -503,7 +501,7 @@ public:
template<typename T>
static int fill_sys_priv_schema(
const uint64_t tenant_id,
const uint64_t tenant_id,
T &result,
ObSysPriv &schema,
bool &is_deleted,
@ -522,6 +520,9 @@ public:
static int fill_trigger_id(const uint64_t tenant_id, T &result,
uint64_t &trigger_id, bool &is_deleted);
template<typename T>
static int fill_table_schema(const uint64_t tenant_id, const bool check_deleted, T &result,
ObSimpleTableSchemaV2 &table_schema, bool &is_deleted);
template<typename T>
static int fill_table_schema(const uint64_t tenant_id, const bool check_deleted, T &result,
ObTableSchema &table_schema, bool &is_deleted);
template<typename T>

View File

@ -69,26 +69,25 @@ namespace schema
*
*********************************************************************/
template<typename T>
template<typename T, typename TABLE_SCHEMA>
int ObSchemaRetrieveUtils::retrieve_table_schema(
const uint64_t tenant_id,
const bool check_deleted,
T &result,
ObIAllocator &allocator,
ObIArray<ObTableSchema *> &table_schema_array)
ObIArray<TABLE_SCHEMA *> &table_schema_array)
{
int ret = common::OB_SUCCESS;
uint64_t prev_table_id = common::OB_INVALID_ID;
ObArenaAllocator tmp_allocator(ObModIds::OB_TEMP_VARIABLES);
ObTableSchema table_schema(&tmp_allocator);
while (OB_SUCCESS == ret && common::OB_SUCCESS == (ret = result.next())) {
TABLE_SCHEMA table_schema(&tmp_allocator);
while (OB_SUCC(ret) && OB_SUCC(result.next())) {
table_schema.reset();
tmp_allocator.reuse();
bool is_deleted = false;
ObTableSchema *allocated_table_schema = NULL;
if (OB_FAIL(ret)) {
} else if (OB_FAIL(fill_table_schema(tenant_id, check_deleted, result, table_schema, is_deleted))) {
SHARE_SCHEMA_LOG(WARN, "fail to fill table schema. ", K(check_deleted), K(ret));
TABLE_SCHEMA *allocated_table_schema = NULL;
if (OB_FAIL(fill_table_schema(tenant_id, check_deleted, result, table_schema, is_deleted))) {
SHARE_SCHEMA_LOG(WARN, "fail to fill table schema", KR(ret), K(check_deleted));
} else if (table_schema.get_table_id() == prev_table_id) {
ret = common::OB_SUCCESS;
} else if (is_deleted) {
@ -97,21 +96,21 @@ int ObSchemaRetrieveUtils::retrieve_table_schema(
"table_name", table_schema.get_table_name(),
"schema_version", table_schema.get_schema_version());
} else if (OB_FAIL(ObSchemaUtils::alloc_schema(allocator, table_schema, allocated_table_schema))) {
SHARE_SCHEMA_LOG(WARN, "alloc_table_schema failed", K(ret));
SHARE_SCHEMA_LOG(WARN, "alloc_table_schema failed", KR(ret));
} else if (OB_FAIL(table_schema_array.push_back(allocated_table_schema))) {
SHARE_SCHEMA_LOG(WARN, "failed to push back", K(ret));
SHARE_SCHEMA_LOG(WARN, "failed to push back", KR(ret));
// free table schema allocated
allocator.free(allocated_table_schema);
allocated_table_schema = NULL;
} else {
SHARE_SCHEMA_LOG(INFO, "retrieve table schema", K(table_schema), K(is_deleted), KR(ret));
SHARE_SCHEMA_LOG(INFO, "retrieve table schema", KR(ret), K(table_schema), K(is_deleted));
}
if (OB_FAIL(ret)) {
SHARE_SCHEMA_LOG(WARN, "retrieve table schema failed",
SHARE_SCHEMA_LOG(WARN, "retrieve table schema failed", KR(ret),
"table_id", table_schema.get_table_id(),
"schema_version", table_schema.get_schema_version(),
K(prev_table_id), K(is_deleted), KR(ret));
K(prev_table_id), K(is_deleted));
}
prev_table_id = table_schema.get_table_id();
}
@ -461,8 +460,9 @@ int ObSubPartSchemaRetrieveHelper<TABLE_SCHEMA>::get_table(
}
if (OB_FAIL(ret)) {
} else if (OB_UNLIKELY(OB_ISNULL(table) || table->get_table_id() != table_id)) {
ret = common::OB_ERR_UNEXPECTED;
SHARE_SCHEMA_LOG(ERROR, "cannot find table", K(ret), K(table_id), KPC(table));
// may occur when upgrade system tables
ret = common::OB_ENTRY_NOT_EXIST;
SHARE_SCHEMA_LOG(WARN, "cannot find table", K(ret), K(table_id), KPC(table));
}
return ret;
}
@ -565,8 +565,9 @@ int ObSchemaRetrieveHelper<TABLE_SCHEMA, SCHEMA>::get_table(
}
if (OB_FAIL(ret)) {
} else if (OB_UNLIKELY(OB_ISNULL(table) || table->get_table_id() != table_id)) {
ret = common::OB_ERR_UNEXPECTED;
SHARE_SCHEMA_LOG(ERROR, "cannot find table", K(ret), K(table_id), KPC(table));
// may occur when upgrade system tables
ret = common::OB_ENTRY_NOT_EXIST;
SHARE_SCHEMA_LOG(WARN, "cannot find table", K(ret), K(table_id), KPC(table));
}
return ret;
}
@ -1097,8 +1098,11 @@ int ObSchemaRetrieveUtils::fill_temp_table_schema(const uint64_t tenant_id, T &r
template<typename T>
int ObSchemaRetrieveUtils::fill_table_schema(
const uint64_t tenant_id, const bool check_deleted, T &result,
ObTableSchema &table_schema, bool &is_deleted)
const uint64_t tenant_id,
const bool check_deleted,
T &result,
ObTableSchema &table_schema,
bool &is_deleted)
{
int ret = common::OB_SUCCESS;
table_schema.reset();
@ -2830,7 +2834,6 @@ int ObSchemaRetrieveUtils::fill_sysvar_schema(const uint64_t tenant_id, T &resul
RETRIEVE_SCHEMA_FUNC_DEFINE(user);
RETRIEVE_SCHEMA_FUNC_DEFINE(database);
RETRIEVE_SCHEMA_FUNC_DEFINE(tablegroup);
RETRIEVE_SCHEMA_FUNC_DEFINE(table);
RETRIEVE_SCHEMA_FUNC_DEFINE(outline);
RETRIEVE_SCHEMA_FUNC_DEFINE(package);
RETRIEVE_SCHEMA_FUNC_DEFINE(trigger);
@ -3819,11 +3822,14 @@ int ObSchemaRetrieveUtils::fill_trigger_id(const uint64_t tenant_id, T &result,
}
template<typename T>
int ObSchemaRetrieveUtils::fill_table_schema(const uint64_t tenant_id,
T &result,
ObSimpleTableSchemaV2 &table_schema,
bool &is_deleted)
int ObSchemaRetrieveUtils::fill_table_schema(
const uint64_t tenant_id,
const bool check_deleted,
T &result,
ObSimpleTableSchemaV2 &table_schema,
bool &is_deleted)
{
UNUSED(check_deleted);
int ret = common::OB_SUCCESS;
bool ignore_column_error = false;
table_schema.reset();

View File

@ -842,6 +842,15 @@ public:
const uint64_t tenant_id,
const int64_t schema_version,
ObSimpleSysVariableSchema &schema) = 0;
#define GET_ALL_SCHEMA_WITH_ALLOCATOR_FUNC_DECLARE_PURE_VIRTUAL(SCHEMA, SCHEMA_TYPE) \
virtual int get_all_##SCHEMA##s(common::ObISQLClient &sql_client, \
common::ObIAllocator &allocator, \
const ObRefreshSchemaStatus &schema_status,\
const int64_t schema_version, \
const uint64_t tenant_id, \
common::ObIArray<SCHEMA_TYPE *> &schema_array) = 0;
GET_ALL_SCHEMA_WITH_ALLOCATOR_FUNC_DECLARE_PURE_VIRTUAL(table, ObSimpleTableSchemaV2);
#define GET_ALL_SCHEMA_FUNC_DECLARE_PURE_VIRTUAL(SCHEMA, SCHEMA_TYPE) \
virtual int get_all_##SCHEMA##s(common::ObISQLClient &sql_client, \
const ObRefreshSchemaStatus &schema_status,\
@ -851,7 +860,6 @@ public:
GET_ALL_SCHEMA_FUNC_DECLARE_PURE_VIRTUAL(user, ObSimpleUserSchema);
GET_ALL_SCHEMA_FUNC_DECLARE_PURE_VIRTUAL(database, ObSimpleDatabaseSchema);
GET_ALL_SCHEMA_FUNC_DECLARE_PURE_VIRTUAL(tablegroup, ObSimpleTablegroupSchema);
GET_ALL_SCHEMA_FUNC_DECLARE_PURE_VIRTUAL(table, ObSimpleTableSchemaV2);
GET_ALL_SCHEMA_FUNC_DECLARE_PURE_VIRTUAL(db_priv, ObDBPriv);
GET_ALL_SCHEMA_FUNC_DECLARE_PURE_VIRTUAL(table_priv, ObTablePriv);
GET_ALL_SCHEMA_FUNC_DECLARE_PURE_VIRTUAL(outline, ObSimpleOutlineSchema);
@ -947,6 +955,13 @@ public:
virtual int fetch_new_rls_context_id(const uint64_t tenant_id, uint64_t &new_rls_context_id) = 0;
//------------------For managing privileges-----------------------------//
#define GET_BATCH_SCHEMAS_WITH_ALLOCATOR_FUNC_DECLARE_PURE_VIRTUAL(SCHEMA, SCHEMA_TYPE) \
virtual int get_batch_##SCHEMA##s(const ObRefreshSchemaStatus &schema_status,\
common::ObISQLClient &client, \
common::ObIAllocator &allocator, \
const int64_t schema_version, \
common::ObArray<SchemaKey> &schema_keys, \
common::ObIArray<SCHEMA_TYPE *> &schema_array) = 0;
#define GET_BATCH_SCHEMAS_FUNC_DECLARE_PURE_VIRTUAL(SCHEMA, SCHEMA_TYPE) \
virtual int get_batch_##SCHEMA##s(const ObRefreshSchemaStatus &schema_status,\
common::ObISQLClient &client, \
@ -960,7 +975,7 @@ public:
GET_BATCH_SCHEMAS_FUNC_DECLARE_PURE_VIRTUAL(user, ObSimpleUserSchema);
GET_BATCH_SCHEMAS_FUNC_DECLARE_PURE_VIRTUAL(database, ObSimpleDatabaseSchema);
GET_BATCH_SCHEMAS_FUNC_DECLARE_PURE_VIRTUAL(tablegroup, ObSimpleTablegroupSchema);
GET_BATCH_SCHEMAS_FUNC_DECLARE_PURE_VIRTUAL(table, ObSimpleTableSchemaV2);
GET_BATCH_SCHEMAS_WITH_ALLOCATOR_FUNC_DECLARE_PURE_VIRTUAL(table, ObSimpleTableSchemaV2);
GET_BATCH_SCHEMAS_FUNC_DECLARE_PURE_VIRTUAL(db_priv, ObDBPriv);
GET_BATCH_SCHEMAS_FUNC_DECLARE_PURE_VIRTUAL(table_priv, ObTablePriv);
GET_BATCH_SCHEMAS_FUNC_DECLARE_PURE_VIRTUAL(outline, ObSimpleOutlineSchema);

View File

@ -1191,6 +1191,31 @@ int ObSchemaServiceSQLImpl::get_tenant_system_variable(const ObRefreshSchemaStat
return ret;
}
#define GET_ALL_SCHEMA_WITH_ALLOCATOR_FUNC_DEFINE(SCHEMA, SCHEMA_TYPE) \
int ObSchemaServiceSQLImpl::get_all_##SCHEMA##s(ObISQLClient &client, \
ObIAllocator &allocator, \
const ObRefreshSchemaStatus &schema_status, \
const int64_t schema_version, \
const uint64_t tenant_id, \
ObIArray<SCHEMA_TYPE *> &schema_array) \
{ \
int ret = OB_SUCCESS; \
schema_array.reset(); \
if (!check_inner_stat()) { \
ret = OB_NOT_INIT; \
LOG_WARN("check inner stat fail", KR(ret)); \
} else if (OB_FAIL(fetch_##SCHEMA##s(client, allocator, schema_status, schema_version, tenant_id, schema_array))) { \
LOG_WARN("fetch "#SCHEMA"s failed", KR(ret), K(schema_status), K(schema_version), K(tenant_id)); \
/* for liboblog compatibility */ \
if (-ER_NO_SUCH_TABLE == ret && ObSchemaService::g_liboblog_mode_) { \
LOG_WARN("liboblog mode, ignore "#SCHEMA" schema table NOT EXIST error", \
KR(ret), K(schema_status), K(schema_version), K(tenant_id)); \
ret = OB_SUCCESS; \
} \
} \
return ret; \
}
#define GET_ALL_SCHEMA_FUNC_DEFINE(SCHEMA, SCHEMA_TYPE) \
int ObSchemaServiceSQLImpl::get_all_##SCHEMA##s(ObISQLClient &client, \
const ObRefreshSchemaStatus &schema_status, \
@ -1202,12 +1227,13 @@ int ObSchemaServiceSQLImpl::get_tenant_system_variable(const ObRefreshSchemaStat
schema_array.reset(); \
if (!check_inner_stat()) { \
ret = OB_NOT_INIT; \
LOG_WARN("check inner stat fail"); \
LOG_WARN("check inner stat fail", KR(ret)); \
} else if (OB_FAIL(fetch_##SCHEMA##s(client, schema_status, schema_version, tenant_id, schema_array))) { \
LOG_WARN("fetch "#SCHEMA"s failed", K(ret), K(schema_status), K(schema_version), K(tenant_id)); \
LOG_WARN("fetch "#SCHEMA"s failed", KR(ret), K(schema_status), K(schema_version), K(tenant_id)); \
/* for liboblog compatibility */ \
if (-ER_NO_SUCH_TABLE == ret && ObSchemaService::g_liboblog_mode_) { \
LOG_WARN("liboblog mode, ignore "#SCHEMA" schema table NOT EXIST error", K(ret), K(schema_status), K(schema_version), K(tenant_id)); \
LOG_WARN("liboblog mode, ignore "#SCHEMA" schema table NOT EXIST error", \
KR(ret), K(schema_status), K(schema_version), K(tenant_id)); \
ret = OB_SUCCESS; \
} \
} \
@ -1216,8 +1242,8 @@ int ObSchemaServiceSQLImpl::get_tenant_system_variable(const ObRefreshSchemaStat
GET_ALL_SCHEMA_FUNC_DEFINE(user, ObSimpleUserSchema);
GET_ALL_SCHEMA_FUNC_DEFINE(database, ObSimpleDatabaseSchema);
GET_ALL_SCHEMA_WITH_ALLOCATOR_FUNC_DEFINE(table, ObSimpleTableSchemaV2);
GET_ALL_SCHEMA_FUNC_DEFINE(tablegroup, ObSimpleTablegroupSchema);
GET_ALL_SCHEMA_FUNC_DEFINE(table, ObSimpleTableSchemaV2);
GET_ALL_SCHEMA_FUNC_DEFINE(outline, ObSimpleOutlineSchema);
GET_ALL_SCHEMA_FUNC_DEFINE(synonym, ObSimpleSynonymSchema);
GET_ALL_SCHEMA_FUNC_DEFINE(routine, ObSimpleRoutineSchema);
@ -2883,6 +2909,59 @@ int ObSchemaServiceSQLImpl::get_batch_tenants(
LOG_INFO("get batch tenants finish", K(ret));
return ret;
}
#define GET_BATCH_SCHEMAS_WITH_ALLOCATOR_FUNC_DEFINE(SCHEMA, SCHEMA_TYPE) \
int ObSchemaServiceSQLImpl::get_batch_##SCHEMA##s( \
const ObRefreshSchemaStatus &schema_status, \
ObISQLClient &sql_client, \
ObIAllocator &allocator, \
const int64_t schema_version, \
ObArray<SchemaKey> &schema_keys, \
ObIArray<SCHEMA_TYPE *> &schema_array) \
{ \
int ret = OB_SUCCESS; \
schema_array.reset(); \
LOG_INFO("get batch "#SCHEMA"s", K(schema_version), K(schema_keys));\
if (!check_inner_stat()) { \
ret = OB_NOT_INIT; \
LOG_WARN("check inner stat fail", KR(ret)); \
} else if (OB_FAIL(schema_array.reserve(schema_keys.count()))) {\
LOG_WARN("fail to reserve schema array", KR(ret)); \
} else { \
std::sort(schema_keys.begin(), schema_keys.end(), SchemaKey::cmp_with_tenant_id); \
int64_t begin = 0; \
int64_t end = 0; \
while (OB_SUCCESS == ret && end < schema_keys.count()) { \
const uint64_t tenant_id = schema_keys.at(begin).tenant_id_; \
while (OB_SUCCESS == ret && end < schema_keys.count() \
&& tenant_id == schema_keys.at(end).tenant_id_ \
&& end - begin < MAX_IN_QUERY_PER_TIME) { \
end++; \
} \
if (OB_FAIL(fetch_##SCHEMA##s(sql_client, \
allocator, \
schema_status, \
schema_version, \
tenant_id, \
schema_array, \
&schema_keys.at(begin), \
end - begin))) { \
LOG_WARN("fetch batch "#SCHEMA"s failed", KR(ret)); \
/* for liboblog compatibility */ \
if (-ER_NO_SUCH_TABLE == ret && ObSchemaService::g_liboblog_mode_) { \
LOG_WARN("liboblog mode, ignore "#SCHEMA" schema table NOT EXIST error",\
KR(ret), K(schema_version), K(tenant_id), K(schema_status));\
ret = OB_SUCCESS; \
} \
} \
LOG_TRACE("finish fetch batch "#SCHEMA"s", KR(ret), K(begin), K(end), \
"total_count", schema_keys.count()); \
begin = end; \
} \
} \
return ret; \
}
GET_BATCH_SCHEMAS_WITH_ALLOCATOR_FUNC_DEFINE(table, ObSimpleTableSchemaV2);
#define GET_BATCH_SCHEMAS_FUNC_DEFINE(SCHEMA, SCHEMA_TYPE) \
int ObSchemaServiceSQLImpl::get_batch_##SCHEMA##s( \
@ -2894,11 +2973,12 @@ int ObSchemaServiceSQLImpl::get_batch_tenants(
{ \
int ret = OB_SUCCESS; \
schema_array.reset(); \
schema_array.reserve(schema_keys.count()); \
LOG_INFO("get batch "#SCHEMA"s", K(schema_version), K(schema_keys)); \
LOG_INFO("get batch "#SCHEMA"s", K(schema_version), K(schema_keys));\
if (!check_inner_stat()) { \
ret = OB_NOT_INIT; \
LOG_WARN("check inner stat fail"); \
LOG_WARN("check inner stat fail", KR(ret)); \
} else if (OB_FAIL(schema_array.reserve(schema_keys.count()))) {\
LOG_WARN("fail to reserve schema array", KR(ret)); \
} else { \
std::sort(schema_keys.begin(), schema_keys.end(), SchemaKey::cmp_with_tenant_id); \
int64_t begin = 0; \
@ -2917,18 +2997,19 @@ int ObSchemaServiceSQLImpl::get_batch_tenants(
schema_array, \
&schema_keys.at(begin), \
end - begin))) { \
LOG_WARN("fetch batch "#SCHEMA"s failed", K(ret)); \
/* for liboblog compatibility */ \
LOG_WARN("fetch batch "#SCHEMA"s failed", KR(ret)); \
/* for liboblog compatibility */ \
if (-ER_NO_SUCH_TABLE == ret && ObSchemaService::g_liboblog_mode_) { \
LOG_WARN("liboblog mode, ignore "#SCHEMA" schema table NOT EXIST error", \
K(ret), K(schema_version), K(tenant_id), K(schema_status)); \
LOG_WARN("liboblog mode, ignore "#SCHEMA" schema table NOT EXIST error",\
KR(ret), K(schema_version), K(tenant_id), K(schema_status));\
ret = OB_SUCCESS; \
} \
} \
LOG_DEBUG("finish fetch batch "#SCHEMA"s", K(begin), K(end), "total_count", schema_keys.count()); \
LOG_TRACE("finish fetch batch "#SCHEMA"s", KR(ret), K(begin), K(end), \
"total_count", schema_keys.count()); \
begin = end; \
} \
LOG_DEBUG("finish fetch batch "#SCHEMA"s", K(schema_array)); \
LOG_TRACE("finish fetch batch "#SCHEMA"s", KR(ret), K(schema_array)); \
} \
return ret; \
}
@ -2936,7 +3017,6 @@ int ObSchemaServiceSQLImpl::get_batch_tenants(
GET_BATCH_SCHEMAS_FUNC_DEFINE(user, ObSimpleUserSchema);
GET_BATCH_SCHEMAS_FUNC_DEFINE(database, ObSimpleDatabaseSchema);
GET_BATCH_SCHEMAS_FUNC_DEFINE(tablegroup, ObSimpleTablegroupSchema);
GET_BATCH_SCHEMAS_FUNC_DEFINE(table, ObSimpleTableSchemaV2);
GET_BATCH_SCHEMAS_FUNC_DEFINE(db_priv, ObDBPriv);
GET_BATCH_SCHEMAS_FUNC_DEFINE(table_priv, ObTablePriv);
GET_BATCH_SCHEMAS_FUNC_DEFINE(outline, ObSimpleOutlineSchema);
@ -4393,10 +4473,11 @@ int ObSchemaServiceSQLImpl::fetch_sys_variable_version(
int ObSchemaServiceSQLImpl::fetch_tables(
ObISQLClient &sql_client,
ObIAllocator &allocator,
const ObRefreshSchemaStatus &schema_status,
const int64_t schema_version,
const uint64_t tenant_id,
ObIArray<ObSimpleTableSchemaV2> &schema_array,
ObIArray<ObSimpleTableSchemaV2 *> &schema_array,
const SchemaKey *schema_keys,
const int64_t schema_key_size)
{
@ -4448,6 +4529,7 @@ int ObSchemaServiceSQLImpl::fetch_tables(
if (OB_SUCC(ret)) {
SMART_VAR(ObMySQLProxy::MySQLResult, res) {
DEFINE_SQL_CLIENT_RETRY_WEAK_WITH_SNAPSHOT(sql_client, snapshot_timestamp);
const bool check_deleted = true; // not used
if (OB_FAIL(sql.append(" ORDER BY tenant_id desc, table_id desc, schema_version desc"))) {
LOG_WARN("sql append failed", K(ret));
} else if (OB_FAIL(sql_client_retry_weak.read(res, exec_tenant_id, sql.ptr()))) {
@ -4457,7 +4539,8 @@ int ObSchemaServiceSQLImpl::fetch_tables(
LOG_WARN("fail to get result. ", K(ret));
} else if (OB_FAIL(schema_array.reserve(orig_cnt + inc_cnt))) {
LOG_WARN("fail to reserved schem array", KR(ret), K(orig_cnt), K(inc_cnt));
} else if (OB_FAIL(ObSchemaRetrieveUtils::retrieve_table_schema(tenant_id, *result, schema_array))) {
} else if (OB_FAIL(ObSchemaRetrieveUtils::retrieve_table_schema(
tenant_id, check_deleted, *result, allocator, schema_array))) {
LOG_WARN("failed to retrieve table schema", K(ret));
}
}
@ -4476,10 +4559,15 @@ int ObSchemaServiceSQLImpl::fetch_tables(
LOG_WARN("fail to reserved array", KR(ret), K(inc_cnt));
}
for (int64_t i = orig_cnt; OB_SUCC(ret) && i < schema_array.count(); ++i) {
const uint64_t table_id = schema_array.at(i).get_table_id();
if (OB_FAIL(table_ids.push_back(table_id))) {
uint64_t table_id = OB_INVALID_ID;
ObSimpleTableSchemaV2 *table = schema_array.at(i);
if (OB_ISNULL(table)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("schema is null", KR(ret), K(i));
} else if (FALSE_IT(table_id = table->get_table_id())) {
} else if (OB_FAIL(table_ids.push_back(table_id))) {
LOG_WARN("fail to push back table_id", KR(ret), K(table_id));
} else if (OB_FAIL(tables.push_back(&schema_array.at(i)))) {
} else if (OB_FAIL(tables.push_back(table))) {
LOG_WARN("fail to push back table schema", KR(ret), K(table_id));
}
}

View File

@ -183,6 +183,13 @@ public:
const uint64_t tenant_id,
const int64_t schema_version,
ObSimpleSysVariableSchema &schema);
#define GET_ALL_SCHEMA_WITH_ALLOCATOR_FUNC_DECLARE(SCHEMA, SCHEMA_TYPE) \
virtual int get_all_##SCHEMA##s(common::ObISQLClient &sql_client, \
common::ObIAllocator &allocator, \
const ObRefreshSchemaStatus &schema_status, \
const int64_t schema_version, \
const uint64_t tenant_id, \
common::ObIArray<SCHEMA_TYPE *> &schema_array);
#define GET_ALL_SCHEMA_FUNC_DECLARE(SCHEMA, SCHEMA_TYPE) \
virtual int get_all_##SCHEMA##s(common::ObISQLClient &sql_client, \
const ObRefreshSchemaStatus &schema_status, \
@ -191,8 +198,8 @@ public:
common::ObIArray<SCHEMA_TYPE> &schema_array);
GET_ALL_SCHEMA_FUNC_DECLARE(user, ObSimpleUserSchema);
GET_ALL_SCHEMA_FUNC_DECLARE(database, ObSimpleDatabaseSchema);
GET_ALL_SCHEMA_WITH_ALLOCATOR_FUNC_DECLARE(table, ObSimpleTableSchemaV2);
GET_ALL_SCHEMA_FUNC_DECLARE(tablegroup, ObSimpleTablegroupSchema);
GET_ALL_SCHEMA_FUNC_DECLARE(table, ObSimpleTableSchemaV2);
GET_ALL_SCHEMA_FUNC_DECLARE(db_priv, ObDBPriv);
GET_ALL_SCHEMA_FUNC_DECLARE(table_priv, ObTablePriv);
GET_ALL_SCHEMA_FUNC_DECLARE(outline, ObSimpleOutlineSchema);
@ -310,6 +317,13 @@ public:
common::ObArray<SchemaKey> &schema_keys,
common::ObIArray<ObSimpleTenantSchema> &schema_array);
#define GET_BATCH_SCHEMAS_WITH_ALLOCATOR_FUNC_DECLARE(SCHEMA, SCHEMA_TYPE) \
virtual int get_batch_##SCHEMA##s(const ObRefreshSchemaStatus &schema_status,\
common::ObISQLClient &client, \
common::ObIAllocator &allocator, \
const int64_t schema_version, \
common::ObArray<SchemaKey> &schema_keys, \
common::ObIArray<SCHEMA_TYPE *> &schema_array);
#define GET_BATCH_SCHEMAS_FUNC_DECLARE(SCHEMA, SCHEMA_TYPE) \
virtual int get_batch_##SCHEMA##s(const ObRefreshSchemaStatus &schema_status,\
common::ObISQLClient &client, \
@ -319,7 +333,7 @@ public:
GET_BATCH_SCHEMAS_FUNC_DECLARE(user, ObSimpleUserSchema);
GET_BATCH_SCHEMAS_FUNC_DECLARE(database, ObSimpleDatabaseSchema);
GET_BATCH_SCHEMAS_FUNC_DECLARE(tablegroup, ObSimpleTablegroupSchema);
GET_BATCH_SCHEMAS_FUNC_DECLARE(table, ObSimpleTableSchemaV2);
GET_BATCH_SCHEMAS_WITH_ALLOCATOR_FUNC_DECLARE(table, ObSimpleTableSchemaV2);
GET_BATCH_SCHEMAS_FUNC_DECLARE(db_priv, ObDBPriv);
GET_BATCH_SCHEMAS_FUNC_DECLARE(table_priv, ObTablePriv);
GET_BATCH_SCHEMAS_FUNC_DECLARE(outline, ObSimpleOutlineSchema);
@ -389,6 +403,15 @@ public:
common::ObArray<uint64_t> &tenant_ids,
common::ObIArray<ObTenantSchema> &schema_array);
#define FETCH_SCHEMAS_WITH_ALLOCATOR_FUNC_DECLARE(SCHEMA, SCHEMA_TYPE) \
int fetch_##SCHEMA##s(common::ObISQLClient &client, \
common::ObIAllocator &allocator, \
const ObRefreshSchemaStatus &schema_status,\
const int64_t schema_version, \
const uint64_t tenant_id, \
common::ObIArray<SCHEMA_TYPE *> &schema_array, \
const SchemaKey *schema_keys = NULL, \
const int64_t schema_key_size = 0);
#define FETCH_SCHEMAS_FUNC_DECLARE(SCHEMA, SCHEMA_TYPE) \
int fetch_##SCHEMA##s(common::ObISQLClient &client, \
const ObRefreshSchemaStatus &schema_status,\
@ -399,8 +422,8 @@ public:
const int64_t schema_key_size = 0);
FETCH_SCHEMAS_FUNC_DECLARE(user, ObSimpleUserSchema);
FETCH_SCHEMAS_FUNC_DECLARE(database, ObSimpleDatabaseSchema);
FETCH_SCHEMAS_WITH_ALLOCATOR_FUNC_DECLARE(table, ObSimpleTableSchemaV2);
FETCH_SCHEMAS_FUNC_DECLARE(tablegroup, ObSimpleTablegroupSchema);
FETCH_SCHEMAS_FUNC_DECLARE(table, ObSimpleTableSchemaV2);
FETCH_SCHEMAS_FUNC_DECLARE(db_priv, ObDBPriv);
FETCH_SCHEMAS_FUNC_DECLARE(table_priv, ObTablePriv);
FETCH_SCHEMAS_FUNC_DECLARE(outline, ObSimpleOutlineSchema);

View File

@ -644,7 +644,6 @@ int ObSchemaUtils::batch_get_table_schemas_from_inner_table_(
ObRefreshSchemaStatus schema_status;
schema_status.tenant_id_ = tenant_id;
int64_t schema_version = INT64_MAX - 1; // get latest schema
ObArray<ObSimpleTableSchemaV2> schema_array;
if (OB_UNLIKELY(!is_valid_tenant_id(tenant_id))) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid tenant_id", KR(ret), K(tenant_id));
@ -657,21 +656,13 @@ int ObSchemaUtils::batch_get_table_schemas_from_inner_table_(
} else if (OB_FAIL(schema_service->get_batch_tables(
schema_status,
sql_client,
allocator,
schema_version,
need_refresh_table_schema_keys,
schema_array))) {
table_schemas))) {
LOG_WARN("get batch tables failed", KR(ret),
K(schema_status), K(schema_version), K(need_refresh_table_schema_keys));
}
ARRAY_FOREACH(schema_array, idx) {
const ObSimpleTableSchemaV2 &table_schema = schema_array.at(idx);
ObSimpleTableSchemaV2 *new_table_schema = NULL;
if (OB_FAIL(alloc_schema(allocator, table_schema, new_table_schema))) {
LOG_WARN("fail to alloc schema", KR(ret), K(table_schema));
} else if (OB_FAIL(table_schemas.push_back(new_table_schema))) {
LOG_WARN("push back failed", KR(ret), KP(new_table_schema));
}
}
return ret;
}

View File

@ -3787,24 +3787,46 @@ int ObServerSchemaService::fetch_increment_schemas(
int ret = OB_SUCCESS;
ObArray<SchemaKey> schema_keys;
#define GET_BATCH_SCHEMAS(SCHEMA, SCHEMA_TYPE, SCHEMA_KEYS) \
if (OB_SUCC(ret)) { \
schema_keys.reset(); \
const SCHEMA_KEYS &new_keys = all_keys.new_##SCHEMA##_keys_; \
ObArray<SCHEMA_TYPE> &simple_schemas = simple_incre_schemas.simple_##SCHEMA##_schemas_; \
if (OB_FAIL(convert_schema_keys_to_array(new_keys, schema_keys))) { \
LOG_WARN("convert set to array failed", K(ret)); \
#define GET_BATCH_SCHEMAS(SCHEMA, SCHEMA_TYPE, SCHEMA_KEYS) \
if (OB_SUCC(ret)) { \
schema_keys.reset(); \
const SCHEMA_KEYS &new_keys = all_keys.new_##SCHEMA##_keys_; \
ObArray<SCHEMA_TYPE> &simple_schemas = simple_incre_schemas.simple_##SCHEMA##_schemas_;\
if (OB_FAIL(convert_schema_keys_to_array(new_keys, schema_keys))) { \
LOG_WARN("convert set to array failed", KR(ret)); \
} else if (OB_FAIL(schema_service_->get_batch_##SCHEMA##s(schema_status, sql_client, \
schema_version, schema_keys, simple_schemas))) { \
LOG_WARN("get batch "#SCHEMA"s failed", K(ret), K(schema_keys)); \
LOG_WARN("get batch "#SCHEMA"s failed", KR(ret), K(schema_keys)); \
} else { \
ALLOW_NEXT_LOG(); \
LOG_INFO("get batch "#SCHEMA"s success", K(schema_keys)); \
if (schema_keys.size() != simple_schemas.size()) { \
ret = OB_ERR_UNEXPECTED; \
LOG_ERROR("unexpected "#SCHEMA" result cnt", K(ret), K(schema_keys.size()), K(simple_schemas.size())); \
LOG_ERROR("unexpected "#SCHEMA" result cnt", \
KR(ret), K(schema_keys.size()), K(simple_schemas.size())); \
} \
}\
} \
}
#define GET_BATCH_SCHEMAS_WITH_ALLOCATOR(SCHEMA, SCHEMA_TYPE, SCHEMA_KEYS) \
if (OB_SUCC(ret)) { \
schema_keys.reset(); \
const SCHEMA_KEYS &new_keys = all_keys.new_##SCHEMA##_keys_; \
ObArray<SCHEMA_TYPE *> &simple_schemas = simple_incre_schemas.simple_##SCHEMA##_schemas_;\
if (OB_FAIL(convert_schema_keys_to_array(new_keys, schema_keys))) { \
LOG_WARN("convert set to array failed", KR(ret)); \
} else if (OB_FAIL(schema_service_->get_batch_##SCHEMA##s(schema_status, sql_client, \
simple_incre_schemas.allocator_, schema_version, schema_keys, simple_schemas))) { \
LOG_WARN("get batch "#SCHEMA"s failed", KR(ret), K(schema_keys)); \
} else { \
ALLOW_NEXT_LOG(); \
LOG_INFO("get batch "#SCHEMA"s success", K(schema_keys)); \
if (schema_keys.size() != simple_schemas.size()) { \
ret = OB_ERR_UNEXPECTED; \
LOG_ERROR("unexpected "#SCHEMA" result cnt", \
KR(ret), K(schema_keys.size()), K(simple_schemas.size())); \
} \
} \
}
#define GET_BATCH_SCHEMAS_WITHOUT_SCHEMA_STATUS(SCHEMA, SCHEMA_TYPE, SCHEMA_KEYS) \
@ -3830,7 +3852,7 @@ int ObServerSchemaService::fetch_increment_schemas(
GET_BATCH_SCHEMAS(user, ObSimpleUserSchema, UserKeys);
GET_BATCH_SCHEMAS(database, ObSimpleDatabaseSchema, DatabaseKeys);
GET_BATCH_SCHEMAS(tablegroup, ObSimpleTablegroupSchema, TablegroupKeys);
GET_BATCH_SCHEMAS(table, ObSimpleTableSchemaV2, TableKeys);
GET_BATCH_SCHEMAS_WITH_ALLOCATOR(table, ObSimpleTableSchemaV2, TableKeys);
GET_BATCH_SCHEMAS(outline, ObSimpleOutlineSchema, OutlineKeys);
GET_BATCH_SCHEMAS(routine, ObSimpleRoutineSchema, RoutineKeys);
GET_BATCH_SCHEMAS(package, ObSimplePackageSchema, PackageKeys);
@ -4137,7 +4159,7 @@ APPLY_SCHEMA_TO_CACHE_IMPL(ObSysVariableMgr, sys_variable, ObSimpleSysVariableSc
APPLY_SCHEMA_TO_CACHE_IMPL(ObSchemaMgr, user, ObSimpleUserSchema, UserKeys);
APPLY_SCHEMA_TO_CACHE_IMPL(ObSchemaMgr, database, ObSimpleDatabaseSchema, DatabaseKeys);
APPLY_SCHEMA_TO_CACHE_IMPL(ObSchemaMgr, tablegroup, ObSimpleTablegroupSchema, TablegroupKeys);
APPLY_SCHEMA_TO_CACHE_IMPL(ObSchemaMgr, table, ObSimpleTableSchemaV2, TableKeys);
APPLY_SCHEMA_TO_CACHE_IMPL(ObSchemaMgr, table, ObSimpleTableSchemaV2*, TableKeys);
APPLY_SCHEMA_TO_CACHE_IMPL(ObOutlineMgr, outline, ObSimpleOutlineSchema, OutlineKeys);
APPLY_SCHEMA_TO_CACHE_IMPL(ObRoutineMgr, routine, ObSimpleRoutineSchema, RoutineKeys);
APPLY_SCHEMA_TO_CACHE_IMPL(ObPackageMgr, package, ObSimplePackageSchema, PackageKeys);
@ -5171,18 +5193,21 @@ int ObServerSchemaService::convert_to_simple_schema(
}
int ObServerSchemaService::convert_to_simple_schema(
common::ObIAllocator &allocator,
const ObIArray<ObTableSchema> &schemas,
ObIArray<ObSimpleTableSchemaV2> &simple_schemas)
ObIArray<ObSimpleTableSchemaV2 *> &simple_schemas)
{
int ret= OB_SUCCESS;
simple_schemas.reset();
FOREACH_CNT_X(schema, schemas, OB_SUCC(ret)) {
ObSimpleTableSchemaV2 simple_schema;
if (OB_FAIL(convert_to_simple_schema(*schema, simple_schema))) {
LOG_WARN("convert failed", K(ret));
ObSimpleTableSchemaV2 *simple_schema = NULL;
if (OB_FAIL(ObSchemaUtils::alloc_schema(allocator, simple_schema))) {
LOG_WARN("fail to alloc simple schema", KR(ret));
} else if (OB_FAIL(convert_to_simple_schema(*schema, *simple_schema))) {
LOG_WARN("convert failed", KR(ret));
} else if (OB_FAIL(simple_schemas.push_back(simple_schema))) {
LOG_WARN("push back failed", K(ret));
LOG_WARN("push back failed", KR(ret));
}
}
@ -5190,22 +5215,25 @@ int ObServerSchemaService::convert_to_simple_schema(
}
int ObServerSchemaService::convert_to_simple_schema(
common::ObIAllocator &allocator,
const ObIArray<ObTableSchema *> &schemas,
ObIArray<ObSimpleTableSchemaV2> &simple_schemas)
ObIArray<ObSimpleTableSchemaV2 *> &simple_schemas)
{
int ret= OB_SUCCESS;
simple_schemas.reset();
FOREACH_CNT_X(schema, schemas, OB_SUCC(ret)) {
const ObTableSchema *table_schema = *schema;
ObSimpleTableSchemaV2 simple_schema;
ObSimpleTableSchemaV2 *simple_schema = NULL;
if (OB_ISNULL(table_schema)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("NULL ptr", K(ret), K(table_schema));
} else if (OB_FAIL(convert_to_simple_schema(*table_schema, simple_schema))) {
LOG_WARN("convert failed", K(ret));
LOG_WARN("NULL ptr", KR(ret), KP(table_schema));
} else if (OB_FAIL(ObSchemaUtils::alloc_schema(allocator, simple_schema))) {
LOG_WARN("fail to alloc simple schema", KR(ret));
} else if (OB_FAIL(convert_to_simple_schema(*table_schema, *simple_schema))) {
LOG_WARN("convert failed", KR(ret));
} else if (OB_FAIL(simple_schemas.push_back(simple_schema))) {
LOG_WARN("push back failed", K(ret));
LOG_WARN("push back failed", KR(ret));
}
}
@ -5814,7 +5842,11 @@ int ObServerSchemaService::try_fetch_publish_core_schemas(
}
if (OB_SUCC(ret)) {
ObSchemaMgr *schema_mgr_for_cache = NULL;
ObArray<ObSimpleTableSchemaV2> simple_core_schemas;
auto attr = SET_USE_500("PubCoreSchema", ObCtxIds::SCHEMA_SERVICE);
ObArenaAllocator allocator(attr);
ObArray<ObSimpleTableSchemaV2*> simple_core_schemas(
common::OB_MALLOC_NORMAL_BLOCK_SIZE,
common::ModulePageAllocator(allocator));
if (OB_FAIL(schema_mgr_for_cache_map_.get_refactored(tenant_id, schema_mgr_for_cache))) {
LOG_WARN("fail to get schema mgr for cache", KR(ret), K(schema_status));
} else if (OB_ISNULL(schema_mgr_for_cache)) {
@ -5822,7 +5854,7 @@ int ObServerSchemaService::try_fetch_publish_core_schemas(
LOG_WARN("schema_mgr_for_cache is null", KR(ret), K(schema_status));
} else if (OB_FAIL(update_schema_cache(core_tables))) {
LOG_WARN("failed to update schema cache", KR(ret), K(schema_status));
} else if (OB_FAIL(convert_to_simple_schema(core_schemas, simple_core_schemas))) {
} else if (OB_FAIL(convert_to_simple_schema(allocator, core_schemas, simple_core_schemas))) {
LOG_WARN("convert to simple schema failed", KR(ret), K(schema_status));
} else if (OB_FAIL(schema_mgr_for_cache->add_tables(simple_core_schemas))) {
LOG_WARN("add tables failed", KR(ret), K(schema_status));
@ -5882,7 +5914,11 @@ int ObServerSchemaService::try_fetch_publish_sys_schemas(
K(schema_status), K(schema_version), K(new_schema_version));
} else if (!sys_schema_change) {
ObSchemaMgr *schema_mgr_for_cache = NULL;
ObArray<ObSimpleTableSchemaV2> simple_sys_schemas;
auto attr = SET_USE_500("PubSysSchema", ObCtxIds::SCHEMA_SERVICE);
ObArenaAllocator allocator(attr);
ObArray<ObSimpleTableSchemaV2*> simple_sys_schemas(
common::OB_MALLOC_NORMAL_BLOCK_SIZE,
common::ModulePageAllocator(allocator));
if (OB_FAIL(schema_mgr_for_cache_map_.get_refactored(tenant_id, schema_mgr_for_cache))) {
LOG_WARN("fail to get schema mgr for cache", KR(ret), K(tenant_id));
} else if (OB_ISNULL(schema_mgr_for_cache)) {
@ -5890,7 +5926,7 @@ int ObServerSchemaService::try_fetch_publish_sys_schemas(
LOG_WARN("schema_mgr_for_cache is null", KR(ret), K(schema_status));
} else if (OB_FAIL(update_schema_cache(sys_schemas))) {
LOG_WARN("failed to update schema cache", KR(ret), K(schema_status));
} else if (OB_FAIL(convert_to_simple_schema(sys_schemas, simple_sys_schemas))) {
} else if (OB_FAIL(convert_to_simple_schema(allocator, sys_schemas, simple_sys_schemas))) {
LOG_WARN("convert to simple schema failed", KR(ret), K(schema_status));
} else if (OB_FAIL(schema_mgr_for_cache->add_tables(simple_sys_schemas))) {
LOG_WARN("add tables failed", KR(ret), K(schema_status));
@ -6044,38 +6080,44 @@ int ObServerSchemaService::refresh_tenant_full_normal_schema(
}
if (OB_SUCC(ret)) {
ObArray<ObSimpleUserSchema> simple_users;
ObArray<ObSimpleDatabaseSchema> simple_databases;
ObArray<ObSimpleTablegroupSchema> simple_tablegroups;
ObArray<ObSimpleTableSchemaV2> simple_tables;
ObArray<ObSimpleOutlineSchema> simple_outlines;
ObArray<ObSimpleRoutineSchema> simple_routines;
ObArray<ObSimpleSynonymSchema> simple_synonyms;
ObArray<ObSimplePackageSchema> simple_packages;
ObArray<ObSimpleTriggerSchema> simple_triggers;
ObArray<ObDBPriv> db_privs;
ObArray<ObSysPriv> sys_privs;
ObArray<ObTablePriv> table_privs;
ObArray<ObObjPriv> obj_privs;
ObArray<ObSimpleUDFSchema> simple_udfs;
ObArray<ObSimpleUDTSchema> simple_udts;
ObArray<ObSequenceSchema> simple_sequences;
ObArray<ObKeystoreSchema> simple_keystores;
ObArray<ObProfileSchema> simple_profiles;
ObArray<ObSAuditSchema> simple_audits;
auto attr = SET_USE_500("RefFullSchema", ObCtxIds::SCHEMA_SERVICE);
ObArenaAllocator allocator(attr);
#define INIT_ARRAY(TYPE, name) \
ObArray<TYPE> name(common::OB_MALLOC_NORMAL_BLOCK_SIZE, \
common::ModulePageAllocator(allocator));
INIT_ARRAY(ObSimpleUserSchema, simple_users);
INIT_ARRAY(ObSimpleDatabaseSchema, simple_databases);
INIT_ARRAY(ObSimpleTablegroupSchema, simple_tablegroups);
INIT_ARRAY(ObSimpleTableSchemaV2*, simple_tables);
INIT_ARRAY(ObSimpleOutlineSchema, simple_outlines);
INIT_ARRAY(ObSimpleRoutineSchema, simple_routines);
INIT_ARRAY(ObSimpleSynonymSchema, simple_synonyms);
INIT_ARRAY(ObSimplePackageSchema, simple_packages);
INIT_ARRAY(ObSimpleTriggerSchema, simple_triggers);
INIT_ARRAY(ObDBPriv, db_privs);
INIT_ARRAY(ObSysPriv, sys_privs);
INIT_ARRAY(ObTablePriv, table_privs);
INIT_ARRAY(ObObjPriv, obj_privs);
INIT_ARRAY(ObSimpleUDFSchema, simple_udfs);
INIT_ARRAY(ObSimpleUDTSchema, simple_udts);
INIT_ARRAY(ObSequenceSchema, simple_sequences);
INIT_ARRAY(ObKeystoreSchema, simple_keystores);
INIT_ARRAY(ObProfileSchema, simple_profiles);
INIT_ARRAY(ObSAuditSchema, simple_audits);
INIT_ARRAY(ObLabelSePolicySchema, simple_label_se_policys);
INIT_ARRAY(ObLabelSeComponentSchema, simple_label_se_components);
INIT_ARRAY(ObLabelSeLabelSchema, simple_label_se_labels);
INIT_ARRAY(ObLabelSeUserLevelSchema, simple_label_se_user_levels);
INIT_ARRAY(ObTablespaceSchema, simple_tablespaces);
INIT_ARRAY(ObDbLinkSchema, simple_dblinks);
INIT_ARRAY(ObDirectorySchema, simple_directories);
INIT_ARRAY(ObContextSchema, simple_contexts);
INIT_ARRAY(ObSimpleMockFKParentTableSchema, simple_mock_fk_parent_tables);
INIT_ARRAY(ObRlsPolicySchema, simple_rls_policys);
INIT_ARRAY(ObRlsGroupSchema, simple_rls_groups);
INIT_ARRAY(ObRlsContextSchema, simple_rls_contexts);
#undef INIT_ARRAY
ObSimpleSysVariableSchema simple_sys_variable;
ObArray<ObLabelSePolicySchema> simple_label_se_policys;
ObArray<ObLabelSeComponentSchema> simple_label_se_components;
ObArray<ObLabelSeLabelSchema> simple_label_se_labels;
ObArray<ObLabelSeUserLevelSchema> simple_label_se_user_levels;
ObArray<ObTablespaceSchema> simple_tablespaces;
ObArray<ObDbLinkSchema> simple_dblinks;
ObArray<ObDirectorySchema> simple_directories;
ObArray<ObContextSchema> simple_contexts;
ObArray<ObSimpleMockFKParentTableSchema> simple_mock_fk_parent_tables;
ObArray<ObRlsPolicySchema> simple_rls_policys;
ObArray<ObRlsGroupSchema> simple_rls_groups;
ObArray<ObRlsContextSchema> simple_rls_contexts;
if (OB_FAIL(schema_service_->get_sys_variable(sql_client, schema_status, tenant_id,
schema_version, simple_sys_variable))) {
@ -6090,8 +6132,8 @@ int ObServerSchemaService::refresh_tenant_full_normal_schema(
sql_client, schema_status, schema_version, tenant_id, simple_tablegroups))) {
LOG_WARN("get all tablegroups failed", K(ret), K(schema_version), K(tenant_id));
} else if (OB_FAIL(schema_service_->get_all_tables(
sql_client, schema_status, schema_version, tenant_id, simple_tables))) {
LOG_WARN("get all table schema failed", K(ret), K(schema_version), K(tenant_id));
sql_client, allocator, schema_status, schema_version, tenant_id, simple_tables))) {
LOG_WARN("get all table schema failed", KR(ret), K(schema_version), K(tenant_id));
} else if (OB_FAIL(schema_service_->get_all_outlines(
sql_client, schema_status, schema_version, tenant_id, simple_outlines))) {
LOG_WARN("get all outline schema failed", K(ret), K(schema_version), K(tenant_id));

View File

@ -812,7 +812,7 @@ public:
common::ObArray<ObSimpleTenantSchema> simple_tenant_schemas_; //new tenant
common::ObArray<ObSimpleTenantSchema> alter_tenant_schemas_;
common::ObArray<ObSimpleDatabaseSchema> simple_database_schemas_;
common::ObArray<ObSimpleTableSchemaV2> simple_table_schemas_;
common::ObArray<ObSimpleTableSchemaV2 *> simple_table_schemas_;
common::ObArray<ObSimpleTablegroupSchema> simple_tablegroup_schemas_;
common::ObArray<ObSimpleOutlineSchema> simple_outline_schemas_;
common::ObArray<ObSimpleRoutineSchema> simple_routine_schemas_;
@ -1155,11 +1155,13 @@ protected:
const uint64_t tenant_id,
const int64_t schema_version);
int convert_to_simple_schema(
common::ObIAllocator &allocator,
const common::ObIArray<ObTableSchema> &schemas,
common::ObIArray<ObSimpleTableSchemaV2> &simple_schemas);
common::ObIArray<ObSimpleTableSchemaV2 *> &simple_schemas);
int convert_to_simple_schema(
common::ObIAllocator &allocator,
const common::ObIArray<ObTableSchema *> &schemas,
common::ObIArray<ObSimpleTableSchemaV2> &simple_schemas);
common::ObIArray<ObSimpleTableSchemaV2 *> &simple_schemas);
int convert_to_simple_schema(
const ObTableSchema &schema,
ObSimpleTableSchemaV2 &simple_schema);