[CP] fix some ctas exception handle bugs
This commit is contained in:
parent
a963f52add
commit
491d36e26a
@ -408,6 +408,8 @@ void ObServer::destroy()
|
||||
LOG_WARN("sql memory manager timer destroyed");
|
||||
TG_DESTROY(lib::TGDefIDs::ServerTracerTimer);
|
||||
LOG_WARN("server trace timer destroyed");
|
||||
TG_DESTROY(lib::TGDefIDs::CTASCleanUpTimer);
|
||||
LOG_WARN("ctas clean up timer destroyed");
|
||||
root_service_.destroy();
|
||||
LOG_WARN("root service destroyed");
|
||||
ob_service_.destroy();
|
||||
@ -645,6 +647,8 @@ int ObServer::stop()
|
||||
LOG_WARN("sql memory manager timer stopped");
|
||||
TG_STOP(lib::TGDefIDs::ServerTracerTimer);
|
||||
LOG_WARN("server trace timer stopped");
|
||||
TG_STOP(lib::TGDefIDs::CTASCleanUpTimer);
|
||||
LOG_WARN("ctas clean up timer stopped");
|
||||
LOG_INFO("begin stop sql conn pool");
|
||||
sql_conn_pool_.stop();
|
||||
LOG_WARN("sql connection pool stopped");
|
||||
@ -750,6 +754,7 @@ int ObServer::wait()
|
||||
TG_WAIT(lib::TGDefIDs::FreezeTimer);
|
||||
TG_WAIT(lib::TGDefIDs::SqlMemTimer);
|
||||
TG_WAIT(lib::TGDefIDs::ServerTracerTimer);
|
||||
TG_WAIT(lib::TGDefIDs::CTASCleanUpTimer);
|
||||
LOG_INFO("wait timer success");
|
||||
root_service_.wait();
|
||||
LOG_INFO("wait root service success");
|
||||
@ -927,6 +932,8 @@ int ObServer::init_config()
|
||||
LOG_ERROR("init sql memory manger timer fail", K(ret));
|
||||
} else if (OB_FAIL(TG_START(lib::TGDefIDs::ServerTracerTimer))) {
|
||||
LOG_WARN("fail to init server trace timer", KR(ret));
|
||||
} else if (OB_FAIL(TG_START(lib::TGDefIDs::CTASCleanUpTimer))) {
|
||||
LOG_ERROR("fail to init ctas clean up timer", KR(ret));
|
||||
} else if (OB_FAIL(config_mgr_.base_init())) {
|
||||
LOG_WARN("config_mgr_ base_init failed", K(ret));
|
||||
} else if (OB_FAIL(config_mgr_.init(sql_proxy_, self_addr_))) {
|
||||
@ -2045,10 +2052,10 @@ bool ObServer::ObCTASCleanUp::operator()(sql::ObSQLSessionMgr::Key key, sql::ObS
|
||||
set_drop_flag(false);
|
||||
ATOMIC_STORE(&obs_->need_ctas_cleanup_,
|
||||
true); // The current session is creating a table and needs to continue to check in the next schedule
|
||||
LOG_DEBUG("current table is in status of creating", K(sess_info->get_last_active_time()));
|
||||
LOG_INFO("current table is in status of creating", K(sess_info->get_last_active_time()));
|
||||
} else {
|
||||
(void)sess_info->unlock_query();
|
||||
LOG_DEBUG("current table was in status of creating", K(sess_info->get_last_active_time()));
|
||||
LOG_INFO("current table was in status of creating", K(sess_info->get_last_active_time()));
|
||||
}
|
||||
} else if (ObCTASCleanUp::TEMP_TAB_RULE == get_cleanup_type()) { // 3, Directly connected temporary table cleanup
|
||||
if (sess_info->get_sess_create_time() < get_schema_version() + 100) {
|
||||
@ -2238,7 +2245,7 @@ int ObServer::init_refresh_active_time_task()
|
||||
int ObServer::init_ctas_clean_up_task()
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(ctas_clean_up_task_.init(this, lib::TGDefIDs::ServerGTimer))) {
|
||||
if (OB_FAIL(ctas_clean_up_task_.init(this, lib::TGDefIDs::CTASCleanUpTimer))) {
|
||||
LOG_WARN("fail to init ctas clean up task", K(ret));
|
||||
}
|
||||
return ret;
|
||||
@ -2350,12 +2357,15 @@ int ObServer::clean_up_invalid_tables()
|
||||
}
|
||||
}
|
||||
if (ctas_cleanup.get_drop_flag()) {
|
||||
LOG_DEBUG("a table will be dropped!", K(*table_schema));
|
||||
LOG_INFO("a table will be dropped!", K(*table_schema));
|
||||
database_schema = NULL;
|
||||
drop_table_arg.tables_.reset();
|
||||
drop_table_arg.if_exist_ = true;
|
||||
drop_table_arg.tenant_id_ = table_schema->get_tenant_id();
|
||||
drop_table_arg.exec_tenant_id_ = table_schema->get_tenant_id();
|
||||
drop_table_arg.table_type_ = table_schema->get_table_type();
|
||||
drop_table_arg.session_id_ = table_schema->get_session_id();
|
||||
drop_table_arg.to_recyclebin_ = false;
|
||||
table_item.table_name_ = table_schema->get_table_name_str();
|
||||
table_item.mode_ = table_schema->get_name_case_mode();
|
||||
if (OB_FAIL(schema_guard.get_database_schema(table_schema->get_database_id(), database_schema))) {
|
||||
|
@ -8822,12 +8822,29 @@ int ObDDLOperator::insert_temp_table_info(ObMySQLTransaction& trans, const ObTab
|
||||
if (OB_ISNULL(schema_service)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get invalid schema service", K(ret));
|
||||
} else if (false == table_schema.is_tmp_table()) {
|
||||
// do nothing...
|
||||
} else if (table_schema.is_ctas_tmp_table() || table_schema.is_tmp_table()) {
|
||||
if (is_inner_table(table_schema.get_table_id())) {
|
||||
ret = OB_OP_NOT_ALLOW;
|
||||
LOG_WARN("create tmp sys table not allowed", K(ret), "table_id", table_schema.get_table_id());
|
||||
} else if (OB_FAIL(schema_service->get_table_sql_service().insert_temp_table_info(trans, table_schema))) {
|
||||
LOG_WARN("insert_temp_table_info failed", K(ret));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObDDLOperator::delete_temp_table_info(ObMySQLTransaction& trans, const ObTableSchema& table_schema)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSchemaService* schema_service = schema_service_.get_schema_service();
|
||||
if (OB_ISNULL(schema_service)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get invalid schema service", K(ret));
|
||||
} else if (is_inner_table(table_schema.get_table_id())) {
|
||||
ret = OB_OP_NOT_ALLOW;
|
||||
LOG_WARN("create tmp sys table not allowed", K(ret), "table_id", table_schema.get_table_id());
|
||||
} else if (OB_FAIL(schema_service->get_table_sql_service().insert_temp_table_info(trans, table_schema))) {
|
||||
} else if (OB_FAIL(schema_service->get_table_sql_service().delete_from_all_temp_table(
|
||||
trans, table_schema.get_tenant_id(), table_schema.get_table_id()))) {
|
||||
LOG_WARN("insert_temp_table_info failed", K(ret));
|
||||
}
|
||||
return ret;
|
||||
|
@ -502,6 +502,8 @@ public:
|
||||
const obrpc::ObAlterTablegroupArg& arg);
|
||||
virtual int insert_temp_table_info(
|
||||
common::ObMySQLTransaction& trans, const share::schema::ObTableSchema& table_schema);
|
||||
virtual int delete_temp_table_info(
|
||||
common::ObMySQLTransaction& trans, const share::schema::ObTableSchema& table_schema);
|
||||
int check_is_delay_delete(const int64_t tenant_id, bool& is_delay_delete);
|
||||
template <typename T>
|
||||
int construct_new_name_for_recyclebin(const T& schema, common::ObSqlString& new_table_name);
|
||||
|
@ -4551,6 +4551,11 @@ int ObDDLService::alter_table_in_trans(obrpc::ObAlterTableArg &alter_table_arg,
|
||||
if (OB_FAIL(ddl_operator.update_table_attribute(
|
||||
new_table_schema, trans, operation_type, &alter_table_arg.ddl_stmt_str_))) {
|
||||
LOG_WARN("failed to update data table schema version and max used column is!", K(ret));
|
||||
} else if (alter_table_schema.alter_option_bitset_.has_member(ObAlterTableArg::SESSION_ID) &&
|
||||
0 == new_table_schema.get_session_id() &&
|
||||
!new_table_schema.is_tmp_table() &&
|
||||
OB_FAIL(ddl_operator.delete_temp_table_info(trans, new_table_schema))) {
|
||||
LOG_WARN("failed to delete temp table info", K(ret));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4187,7 +4187,7 @@ int ObRootService::logical_restore_partitions(const obrpc::ObRestorePartitionsAr
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObRootService::create_table(const ObCreateTableArg& arg, UInt64& table_id)
|
||||
int ObRootService::create_table(const ObCreateTableArg& arg, ObCreateTableRes& res)
|
||||
{
|
||||
LOG_DEBUG("receive create table arg", K(arg));
|
||||
int ret = OB_SUCCESS;
|
||||
@ -4352,7 +4352,7 @@ int ObRootService::create_table(const ObCreateTableArg& arg, UInt64& table_id)
|
||||
LOG_WARN("push_back failed", K(ret));
|
||||
} else {
|
||||
RS_TRACE(generate_schema_index);
|
||||
table_id = table_schema.get_table_id();
|
||||
res.table_id_ = table_schema.get_table_id();
|
||||
// generate index schemas
|
||||
ObIndexBuilder index_builder(ddl_service_);
|
||||
ObTableSchema index_schema;
|
||||
@ -4485,7 +4485,7 @@ int ObRootService::create_table(const ObCreateTableArg& arg, UInt64& table_id)
|
||||
}
|
||||
// get child column schema.
|
||||
if (OB_SUCC(ret)) {
|
||||
foreign_key_info.child_table_id_ = table_id;
|
||||
foreign_key_info.child_table_id_ = res.table_id_;
|
||||
foreign_key_info.parent_table_id_ = parent_schema->get_table_id();
|
||||
for (int64_t j = 0; OB_SUCC(ret) && j < foreign_key_arg.child_columns_.count(); j++) {
|
||||
const ObString& column_name = foreign_key_arg.child_columns_.at(j);
|
||||
@ -4579,12 +4579,21 @@ int ObRootService::create_table(const ObCreateTableArg& arg, UInt64& table_id)
|
||||
K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)) {
|
||||
uint64_t tenant_id = table_schema.get_tenant_id();
|
||||
if (is_inner_table(res.table_id_)) {
|
||||
tenant_id = OB_SYS_TENANT_ID;
|
||||
}
|
||||
if (OB_FAIL(schema_service_->get_tenant_schema_version(tenant_id, res.schema_version_))) {
|
||||
LOG_WARN("failed to get tenant schema version", K(ret));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RS_TRACE(create_table_end);
|
||||
FORCE_PRINT_TRACE(THE_RS_TRACE, "[create table]");
|
||||
int64_t cost = ObTimeUtility::current_time() - begin_time;
|
||||
ROOTSERVICE_EVENT_ADD("ddl", "create_table", K(ret), K(table_id), K(cost));
|
||||
ROOTSERVICE_EVENT_ADD("ddl", "create_table", K(ret), "table_id", res.table_id_, K(cost));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -9725,7 +9734,7 @@ int ObRootService::table_allow_ddl_operation(const obrpc::ObAlterTableArg& arg)
|
||||
ret = OB_OP_NOT_ALLOW;
|
||||
LOG_WARN("table is physical or logical split can not split", K(ret), K(schema));
|
||||
LOG_USER_ERROR(OB_OP_NOT_ALLOW, "table is in physial or logical split, ddl operation");
|
||||
} else if (0 != schema->get_session_id() && false == schema->is_tmp_table()) {
|
||||
} else if (schema->is_ctas_tmp_table()) {
|
||||
if (!alter_table_schema.alter_option_bitset_.has_member(ObAlterTableArg::SESSION_ID)) {
|
||||
// to prevet alter table after failed to create table, the table is invisible.
|
||||
ret = OB_OP_NOT_ALLOW;
|
||||
|
@ -953,7 +953,7 @@ public:
|
||||
int create_database(const obrpc::ObCreateDatabaseArg& arg, obrpc::UInt64& db_id);
|
||||
int create_tablegroup(const obrpc::ObCreateTablegroupArg& arg, obrpc::UInt64& tg_id);
|
||||
int get_frozen_status(const obrpc::Int64& arg, storage::ObFrozenStatus& frozen_status);
|
||||
int create_table(const obrpc::ObCreateTableArg& arg, obrpc::UInt64& table_id);
|
||||
int create_table(const obrpc::ObCreateTableArg& arg, obrpc::ObCreateTableRes& res);
|
||||
int alter_database(const obrpc::ObAlterDatabaseArg& arg);
|
||||
int alter_table(const obrpc::ObAlterTableArg& arg, obrpc::ObAlterTableRes& res);
|
||||
int alter_tablegroup(const obrpc::ObAlterTablegroupArg& arg);
|
||||
|
@ -63,7 +63,7 @@ public:
|
||||
RPC_S(PRD modify_system_variable, obrpc::OB_MODIFY_SYSVAR, (ObModifySysVarArg));
|
||||
RPC_S(PRD create_database, obrpc::OB_CREATE_DATABASE, (ObCreateDatabaseArg), UInt64);
|
||||
RPC_S(PRD create_tablegroup, obrpc::OB_CREATE_TABLEGROUP, (ObCreateTablegroupArg), UInt64);
|
||||
RPC_S(PRD create_table, obrpc::OB_CREATE_TABLE, (ObCreateTableArg), UInt64);
|
||||
RPC_S(PRD create_table, obrpc::OB_CREATE_TABLE, (ObCreateTableArg), ObCreateTableRes);
|
||||
RPC_S(PRD alter_table, obrpc::OB_ALTER_TABLE, (ObAlterTableArg), ObAlterTableRes);
|
||||
RPC_S(PRD alter_database, obrpc::OB_ALTER_DATABASE, (ObAlterDatabaseArg));
|
||||
RPC_S(PRD drop_database, obrpc::OB_DROP_DATABASE, (ObDropDatabaseArg), UInt64);
|
||||
|
@ -823,6 +823,8 @@ bool ObCreateTableArg::is_allow_when_upgrade() const
|
||||
return bret;
|
||||
}
|
||||
|
||||
OB_SERIALIZE_MEMBER(ObCreateTableRes, table_id_, schema_version_);
|
||||
|
||||
bool ObCreateTableLikeArg::is_valid() const
|
||||
{
|
||||
return OB_INVALID_ID != tenant_id_ && !origin_db_name_.empty() && !origin_table_name_.empty() &&
|
||||
|
@ -1016,6 +1016,23 @@ public:
|
||||
// New members of ObCreateTableArg need to pay attention to the implementation of is_allow_when_upgrade
|
||||
};
|
||||
|
||||
struct ObCreateTableRes {
|
||||
OB_UNIS_VERSION(1);
|
||||
|
||||
public:
|
||||
ObCreateTableRes() : table_id_(OB_INVALID_ID), schema_version_(OB_INVALID_VERSION)
|
||||
{}
|
||||
int assign(const ObCreateTableRes &other)
|
||||
{
|
||||
table_id_ = other.table_id_;
|
||||
schema_version_ = other.schema_version_;
|
||||
return common::OB_SUCCESS;
|
||||
}
|
||||
TO_STRING_KV(K_(table_id), K_(schema_version));
|
||||
uint64_t table_id_;
|
||||
int64_t schema_version_;
|
||||
};
|
||||
|
||||
struct ObCreateTableLikeArg : public ObDDLArg {
|
||||
OB_UNIS_VERSION(1);
|
||||
|
||||
|
@ -143,4 +143,5 @@ TG_DEF(DtlDfc, DtlDfc, "", TG_STATIC, TIMER)
|
||||
TG_DEF(DDLRetryGhostIndex, DDLRetryGhostIndex, "", TG_STATIC, TIMER)
|
||||
TG_DEF(StoreFileAutoExtend, StoreFileAutoExtend, "", TG_STATIC, TIMER)
|
||||
TG_DEF(TTLScheduler, TTLScheduler, "", TG_STATIC, TIMER)
|
||||
TG_DEF(CTASCleanUpTimer, CTASCleanUpTimer, "", TG_STATIC, TIMER)
|
||||
#endif
|
||||
|
@ -115,7 +115,7 @@ int ObUpgradeUtils::create_tenant_table(
|
||||
} else {
|
||||
obrpc::ObCreateTableArg arg;
|
||||
uint64_t table_id = OB_INVALID_ID;
|
||||
obrpc::UInt64 new_table_id(OB_INVALID_ID);
|
||||
obrpc::ObCreateTableRes res;
|
||||
table_id = combine_id(tenant_id, extract_pure_id(table_schema.get_table_id()));
|
||||
bool exist = false;
|
||||
if (OB_FAIL(check_table_exist(table_id, exist))) {
|
||||
@ -163,21 +163,21 @@ int ObUpgradeUtils::create_tenant_table(
|
||||
if (OB_ISNULL(GCTX.root_service_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid global context", K(ret), K(GCTX));
|
||||
} else if (OB_FAIL(GCTX.root_service_->create_table(arg, new_table_id))) {
|
||||
LOG_WARN("fail to create table", K(ret), K(arg), K(new_table_id));
|
||||
} else if (OB_FAIL(GCTX.root_service_->create_table(arg, res))) {
|
||||
LOG_WARN("fail to create table", K(ret), K(arg), K(res));
|
||||
}
|
||||
} else {
|
||||
if (OB_ISNULL(GCTX.rs_rpc_proxy_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid global context", K(ret), K(GCTX));
|
||||
} else if (OB_FAIL(GCTX.rs_rpc_proxy_->create_table(arg, new_table_id))) {
|
||||
LOG_WARN("fail to create table", K(ret), K(arg), K(new_table_id));
|
||||
} else if (OB_FAIL(GCTX.rs_rpc_proxy_->create_table(arg, res))) {
|
||||
LOG_WARN("fail to create table", K(ret), K(arg), K(res));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(ret)) {
|
||||
} else if (table_id != new_table_id) {
|
||||
LOG_WARN("table_id not match", K(ret), K(table_id), K(new_table_id));
|
||||
} else if (table_id != res.table_id_) {
|
||||
LOG_WARN("table_id not match", K(ret), K(table_id), K(res.table_id_));
|
||||
} else {
|
||||
LOG_INFO("[UPGRADE] create tenant space table end", K(ret), K(tenant_id), K(table_id));
|
||||
}
|
||||
@ -447,7 +447,7 @@ int ObUpgradeUtils::force_create_tenant_table(
|
||||
} else {
|
||||
obrpc::ObCreateTableArg arg;
|
||||
uint64_t table_id = OB_INVALID_ID;
|
||||
obrpc::UInt64 new_table_id(OB_INVALID_ID);
|
||||
obrpc::ObCreateTableRes res;
|
||||
table_id = combine_id(tenant_id, extract_pure_id(table_schema.get_table_id()));
|
||||
|
||||
arg.if_not_exist_ = true;
|
||||
@ -469,10 +469,10 @@ int ObUpgradeUtils::force_create_tenant_table(
|
||||
} else if (OB_ISNULL(GCTX.root_service_)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("invalid global context", K(ret), K(GCTX));
|
||||
} else if (OB_FAIL(GCTX.root_service_->create_table(arg, new_table_id))) {
|
||||
LOG_WARN("fail to create table", K(ret), K(arg), K(new_table_id));
|
||||
} else if (table_id != new_table_id) {
|
||||
LOG_WARN("table_id not match", K(ret), K(table_id), K(new_table_id));
|
||||
} else if (OB_FAIL(GCTX.root_service_->create_table(arg, res))) {
|
||||
LOG_WARN("fail to create table", K(ret), K(arg), K(res));
|
||||
} else if (table_id != res.table_id_) {
|
||||
LOG_WARN("table_id not match", K(ret), K(table_id), K(res.table_id_));
|
||||
} else {
|
||||
LOG_INFO("create table", K(ret), K(table_id));
|
||||
}
|
||||
|
@ -2466,25 +2466,25 @@ int ObSchemaServiceSQLImpl::fetch_temp_table_schema(const ObRefreshSchemaStatus&
|
||||
const int64_t snapshot_timestamp = schema_status.snapshot_timestamp_;
|
||||
DEFINE_SQL_CLIENT_RETRY_WEAK_WITH_SNAPSHOT(sql_client, snapshot_timestamp);
|
||||
const uint64_t exec_tenant_id = fill_exec_tenant_id(schema_status);
|
||||
if (false == table_schema.is_tmp_table()) {
|
||||
// do nothing...
|
||||
} else if (OB_FAIL(sql.assign_fmt("SELECT create_host FROM %s where tenant_id = %lu and table_id = %lu",
|
||||
OB_ALL_TEMP_TABLE_TNAME,
|
||||
fill_extract_tenant_id(schema_status, tenant_id),
|
||||
fill_extract_schema_id(schema_status, table_schema.get_table_id())))) {
|
||||
LOG_WARN("append sql failed", K(table_schema), K(ret));
|
||||
} else if (OB_FAIL(sql_client_retry_weak.read(res, exec_tenant_id, sql.ptr()))) {
|
||||
LOG_WARN("execute sql failed", K(sql), K(ret));
|
||||
} else if (OB_UNLIKELY(NULL == (result = res.get_result()))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("failed to get result.", K(table_schema), K(ret));
|
||||
} else if (OB_FAIL(result->next())) {
|
||||
LOG_WARN("failed to get temp table info", K(table_schema), K(ret));
|
||||
if (OB_ITER_END == ret) {
|
||||
ret = OB_SUCCESS;
|
||||
if (table_schema.is_tmp_table() || table_schema.is_ctas_tmp_table()) {
|
||||
if (OB_FAIL(sql.assign_fmt("SELECT create_host FROM %s where tenant_id = %lu and table_id = %lu",
|
||||
OB_ALL_TEMP_TABLE_TNAME,
|
||||
fill_extract_tenant_id(schema_status, tenant_id),
|
||||
fill_extract_schema_id(schema_status, table_schema.get_table_id())))) {
|
||||
LOG_WARN("append sql failed", K(table_schema), K(ret));
|
||||
} else if (OB_FAIL(sql_client_retry_weak.read(res, exec_tenant_id, sql.ptr()))) {
|
||||
LOG_WARN("execute sql failed", K(sql), K(ret));
|
||||
} else if (OB_UNLIKELY(NULL == (result = res.get_result()))) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("failed to get result.", K(table_schema), K(ret));
|
||||
} else if (OB_FAIL(result->next())) {
|
||||
LOG_WARN("failed to get temp table info", K(table_schema), K(ret));
|
||||
if (OB_ITER_END == ret) {
|
||||
ret = OB_SUCCESS;
|
||||
}
|
||||
} else if (OB_FAIL(ObSchemaRetrieveUtils::fill_temp_table_schema(tenant_id, *result, table_schema))) {
|
||||
LOG_WARN("fail to fill temp table schema", K(ret), K(tenant_id));
|
||||
}
|
||||
} else if (OB_FAIL(ObSchemaRetrieveUtils::fill_temp_table_schema(tenant_id, *result, table_schema))) {
|
||||
LOG_WARN("fail to fill temp table schema", K(ret), K(tenant_id));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
@ -565,6 +565,10 @@ public:
|
||||
{
|
||||
return TMP_TABLE == table_type_ || TMP_TABLE_ORA_SESS == table_type_ || TMP_TABLE_ORA_TRX == table_type_;
|
||||
}
|
||||
inline bool is_ctas_tmp_table() const
|
||||
{
|
||||
return 0 != session_id_ && !is_tmp_table();
|
||||
}
|
||||
inline bool is_mysql_tmp_table() const
|
||||
{
|
||||
return TMP_TABLE == table_type_;
|
||||
|
@ -825,8 +825,8 @@ int ObTableSqlService::drop_table(const ObTableSchema& table_schema, const int64
|
||||
}
|
||||
}
|
||||
|
||||
// delete from __all_temp_table if it is a temporary table
|
||||
if (OB_SUCC(ret) && table_schema.is_tmp_table()) {
|
||||
// delete from __all_temp_table if it is a temporary table or ctas temporary table
|
||||
if (OB_SUCC(ret) && (table_schema.is_ctas_tmp_table() || table_schema.is_tmp_table())) {
|
||||
if (OB_FAIL(delete_from_all_temp_table(sql_client, table_schema.get_tenant_id(), table_id))) {
|
||||
LOG_WARN("delete from all temp table failed", K(ret));
|
||||
}
|
||||
@ -4340,21 +4340,21 @@ int ObTableSqlService::insert_temp_table_info(ObISQLClient& sql_client, const Ob
|
||||
const uint64_t table_id = table_schema.get_table_id();
|
||||
int64_t affected_rows = 0;
|
||||
ObSqlString insert_sql_string;
|
||||
if (false == table_schema.is_tmp_table()) {
|
||||
// do nothing...
|
||||
} else if (OB_SUCCESS != (ret = insert_sql_string.append_fmt(
|
||||
"INSERT INTO %s (TENANT_ID, TABLE_ID, CREATE_HOST) values(%lu, %lu, \"%.*s\")",
|
||||
OB_ALL_TEMP_TABLE_TNAME,
|
||||
ObSchemaUtils::get_extract_tenant_id(exec_tenant_id, tenant_id),
|
||||
ObSchemaUtils::get_extract_schema_id(exec_tenant_id, table_id),
|
||||
table_schema.get_create_host_str().length(),
|
||||
table_schema.get_create_host_str().ptr()))) {
|
||||
LOG_WARN("sql string append format string failed, ", K(ret));
|
||||
} else if (OB_FAIL(sql_client.write(exec_tenant_id, insert_sql_string.ptr(), affected_rows))) {
|
||||
LOG_WARN("execute sql failed, ", "sql", insert_sql_string.ptr(), K(ret));
|
||||
} else if (1 != affected_rows) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("affected_rows expect to 1, ", K(affected_rows), K(ret));
|
||||
if (table_schema.is_ctas_tmp_table() || table_schema.is_tmp_table()) {
|
||||
if (OB_SUCCESS != (ret = insert_sql_string.append_fmt(
|
||||
"INSERT INTO %s (TENANT_ID, TABLE_ID, CREATE_HOST) values(%lu, %lu, \"%.*s\")",
|
||||
OB_ALL_TEMP_TABLE_TNAME,
|
||||
ObSchemaUtils::get_extract_tenant_id(exec_tenant_id, tenant_id),
|
||||
ObSchemaUtils::get_extract_schema_id(exec_tenant_id, table_id),
|
||||
table_schema.get_create_host_str().length(),
|
||||
table_schema.get_create_host_str().ptr()))) {
|
||||
LOG_WARN("sql string append format string failed, ", K(ret));
|
||||
} else if (OB_FAIL(sql_client.write(exec_tenant_id, insert_sql_string.ptr(), affected_rows))) {
|
||||
LOG_WARN("execute sql failed, ", "sql", insert_sql_string.ptr(), K(ret));
|
||||
} else if (1 != affected_rows) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("affected_rows expect to 1, ", K(affected_rows), K(ret));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -174,7 +174,6 @@ private:
|
||||
common::ObISQLClient& sql_client, const ObTableSchema& table_schema, const int64_t new_schema_version);
|
||||
int delete_table_part_info(const ObTableSchema& table_schema, const int64_t new_schema_version,
|
||||
common::ObISQLClient& sql_client, bool is_delay_delete);
|
||||
int delete_from_all_temp_table(common::ObISQLClient& sql_client, const uint64_t tenant_id, const uint64_t table_id);
|
||||
int add_columns(common::ObISQLClient& sql_client, const ObTableSchema& table);
|
||||
int add_columns_for_core(common::ObISQLClient& sql_client, const ObTableSchema& table);
|
||||
int add_columns_for_not_core(common::ObISQLClient& sql_client, const ObTableSchema& table);
|
||||
@ -226,6 +225,7 @@ private:
|
||||
public:
|
||||
int log_operation_wrapper(ObSchemaOperation& opt, common::ObISQLClient& sql_client);
|
||||
int insert_temp_table_info(common::ObISQLClient& trans, const ObTableSchema& table_schema);
|
||||
int delete_from_all_temp_table(common::ObISQLClient& sql_client, const uint64_t tenant_id, const uint64_t table_id);
|
||||
|
||||
private:
|
||||
int exec_update(common::ObISQLClient& sql_client, const uint64_t table_id, const char* table_name,
|
||||
|
@ -245,26 +245,20 @@ int ObCreateTableExecutor::execute_ctas(
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int64_t affected_rows = 0;
|
||||
int64_t dummy = 0;
|
||||
ObMySQLProxy* sql_proxy = ctx.get_sql_proxy();
|
||||
common::ObCommonSqlProxy* user_sql_proxy;
|
||||
common::ObOracleSqlProxy oracle_sql_proxy;
|
||||
ObSQLSessionInfo* my_session = ctx.get_my_session();
|
||||
ObPhysicalPlanCtx* plan_ctx = ctx.get_physical_plan_ctx();
|
||||
ObSchemaGetterGuard schema_guard;
|
||||
obrpc::ObAlterTableArg alter_table_arg;
|
||||
obrpc::ObDropTableArg drop_table_arg;
|
||||
obrpc::ObTableItem table_item;
|
||||
ObSqlString ins_sql;
|
||||
bool is_auto_commit = false;
|
||||
bool need_clean_up = false;
|
||||
int first_err_code = OB_SUCCESS;
|
||||
const observer::ObGlobalContext& gctx = observer::ObServer::get_instance().get_gctx();
|
||||
const ObTableSchema* table_schema = NULL;
|
||||
obrpc::UInt64 table_id;
|
||||
common::sqlclient::ObISQLConnection* conn = NULL;
|
||||
obrpc::ObCreateTableRes create_table_res;
|
||||
obrpc::ObCreateTableArg& create_table_arg = stmt.get_create_table_arg();
|
||||
create_table_arg.is_inner_ = my_session->is_inner();
|
||||
bool need_clean = true;
|
||||
CK(OB_NOT_NULL(sql_proxy),
|
||||
OB_NOT_NULL(my_session),
|
||||
OB_NOT_NULL(gctx.schema_service_),
|
||||
@ -283,97 +277,126 @@ int ObCreateTableExecutor::execute_ctas(
|
||||
LOG_WARN("failed to prepare alter table arg", K(ret));
|
||||
} else if (OB_FAIL(prepare_drop_arg(stmt, my_session, table_item, drop_table_arg))) {
|
||||
LOG_WARN("failed to prepare drop table arg", K(ret));
|
||||
} else if (OB_FAIL(common_rpc_proxy->create_table(create_table_arg, table_id))) {
|
||||
} else if (OB_FAIL(common_rpc_proxy->create_table(create_table_arg, create_table_res))) {
|
||||
LOG_WARN("rpc proxy create table failed", K(ret), "dst", common_rpc_proxy->get_server());
|
||||
} else if (OB_INVALID_ID != table_id) {
|
||||
const int64_t s1 = ObTimeUtility::current_time();
|
||||
int64_t s2 = 0;
|
||||
const int64_t DDL_WAIT_TIME = 1 * 1000 * 1000; // 1s
|
||||
const int64_t SLEEP_ON_NEED_RETRY = 10 * 1000; // 10ms
|
||||
obrpc::ObAlterTableRes res;
|
||||
while (true) {
|
||||
if (OB_FAIL(
|
||||
gctx.schema_service_->get_tenant_schema_guard(my_session->get_effective_tenant_id(), schema_guard))) {
|
||||
LOG_WARN("failed to get schema guard", K(ret));
|
||||
break;
|
||||
} else if (OB_INVALID_ID != create_table_res.table_id_) {
|
||||
if (OB_INVALID_VERSION == create_table_res.schema_version_) {
|
||||
// During upgrade, high version server send create table rpc to low version RS. RS will
|
||||
// return a struct UINT64. Try deserialize UINT64 to ObCreateTableRes will only get correct
|
||||
// table_id. And schema_version remain default value OB_INVALID_VERSION.
|
||||
// In this scenario, using old strategy.
|
||||
ObSchemaGetterGuard schema_guard;
|
||||
const ObTableSchema* table_schema = NULL;
|
||||
const int64_t s1 = ObTimeUtility::current_time();
|
||||
int64_t s2 = 0;
|
||||
const int64_t DDL_WAIT_TIME = 1 * 1000 * 1000; // 1s
|
||||
const int64_t SLEEP_ON_NEED_RETRY = 10 * 1000; // 10ms
|
||||
while (true) {
|
||||
if (OB_FAIL(
|
||||
gctx.schema_service_->get_tenant_schema_guard(my_session->get_effective_tenant_id(), schema_guard))) {
|
||||
LOG_WARN("failed to get schema guard", K(ret));
|
||||
break;
|
||||
}
|
||||
if (OB_FAIL(schema_guard.get_table_schema(create_table_res.table_id_, table_schema))) {
|
||||
LOG_WARN("failed to get table schema", K(ret), K(create_table_res.table_id_));
|
||||
break;
|
||||
}
|
||||
s2 = ObTimeUtility::current_time();
|
||||
if (OB_NOT_NULL(table_schema)) {
|
||||
LOG_DEBUG("CTAS refresh table schema succeed!", K(ret), K(s2 - s1));
|
||||
break;
|
||||
}
|
||||
if (s2 - s1 < DDL_WAIT_TIME) {
|
||||
ret = OB_SUCCESS;
|
||||
usleep(SLEEP_ON_NEED_RETRY);
|
||||
LOG_DEBUG("CTAS refresh table schema failed, try again", K(ret), K(create_table_res.table_id_), K(s2 - s1));
|
||||
} else {
|
||||
LOG_DEBUG("CTAS refresh table schema timeout!", K(ret), K(create_table_res.table_id_), K(s2 - s1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (OB_FAIL(schema_guard.get_table_schema(table_id, table_schema))) {
|
||||
LOG_WARN("failed to get table schema", K(ret), K(table_id));
|
||||
break;
|
||||
}
|
||||
s2 = ObTimeUtility::current_time();
|
||||
if (OB_NOT_NULL(table_schema)) {
|
||||
LOG_DEBUG("CTAS refresh table schema succeed!", K(ret), K(s2 - s1));
|
||||
break;
|
||||
}
|
||||
if (s2 - s1 < DDL_WAIT_TIME) {
|
||||
ret = OB_SUCCESS;
|
||||
usleep(SLEEP_ON_NEED_RETRY);
|
||||
LOG_DEBUG("CTAS refresh table schema failed, try again", K(ret), K(table_id), K(s2 - s1));
|
||||
} else {
|
||||
LOG_DEBUG("CTAS refresh table schema timeout!", K(ret), K(table_id), K(s2 - s1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (share::is_oracle_mode()) {
|
||||
user_sql_proxy = &oracle_sql_proxy;
|
||||
} else {
|
||||
user_sql_proxy = sql_proxy;
|
||||
uint64_t tenant_id = my_session->get_effective_tenant_id();
|
||||
if (is_inner_table(create_table_res.table_id_)) {
|
||||
tenant_id = OB_SYS_TENANT_ID;
|
||||
}
|
||||
if (OB_FAIL(gctx.schema_service_->async_refresh_schema(tenant_id, create_table_res.schema_version_))) {
|
||||
LOG_WARN("failed to async refresh schema", K(ret));
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ERRSIM
|
||||
{
|
||||
int tmp_ret = E(EventTable::EN_CTAS_FAIL_NO_DROP_ERROR) OB_SUCCESS;
|
||||
if (OB_FAIL(tmp_ret)) {
|
||||
ret = tmp_ret;
|
||||
need_clean = false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
// do nothing...
|
||||
#endif
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
common::sqlclient::ObISQLConnection *conn = NULL;
|
||||
if (share::is_oracle_mode()) {
|
||||
user_sql_proxy = &oracle_sql_proxy;
|
||||
} else {
|
||||
user_sql_proxy = sql_proxy;
|
||||
}
|
||||
if (OB_FAIL(pool->acquire(my_session, conn))) {
|
||||
LOG_WARN("failed to acquire inner connection", K(ret));
|
||||
} else if (OB_ISNULL(conn)) {
|
||||
ret = OB_INNER_STAT_ERROR;
|
||||
LOG_WARN("connection can not be NULL", K(ret));
|
||||
} else if (OB_FAIL(conn->start_transaction())) {
|
||||
LOG_WARN("failed start transaction", K(ret));
|
||||
} else {
|
||||
if (OB_FAIL(conn->execute_write(my_session->get_effective_tenant_id(), ins_sql.ptr(),
|
||||
affected_rows, true))) {
|
||||
LOG_WARN("failed to exec sql", K(ins_sql), K(ret));
|
||||
}
|
||||
// transaction started, must commit or rollback
|
||||
int tmp_ret = OB_SUCCESS;
|
||||
if (OB_LIKELY(OB_SUCCESS == ret)) {
|
||||
tmp_ret = conn->commit();
|
||||
} else {
|
||||
tmp_ret = conn->rollback();
|
||||
}
|
||||
if (OB_UNLIKELY(OB_SUCCESS != tmp_ret)) {
|
||||
ret = (OB_SUCCESS == ret) ? tmp_ret : ret;
|
||||
LOG_WARN("fail to end transaction", K(ret), K(tmp_ret));
|
||||
}
|
||||
}
|
||||
if (OB_NOT_NULL(conn)) {
|
||||
user_sql_proxy->close(conn, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret)) {
|
||||
obrpc::ObAlterTableRes res;
|
||||
if (OB_FAIL(common_rpc_proxy->alter_table(alter_table_arg, res))) {
|
||||
LOG_WARN("failed to update table session", K(ret), K(alter_table_arg));
|
||||
}
|
||||
}
|
||||
|
||||
if (OB_FAIL(ret)) {
|
||||
// do nothing
|
||||
} else if (OB_FAIL(pool->acquire(my_session, conn))) {
|
||||
need_clean_up = true;
|
||||
first_err_code = ret;
|
||||
LOG_WARN("failed to acquire inner connection", K(ret));
|
||||
} else if (OB_FAIL(
|
||||
conn->execute_write(my_session->get_effective_tenant_id(), ins_sql.ptr(), affected_rows, true))) {
|
||||
need_clean_up = true;
|
||||
first_err_code = ret;
|
||||
LOG_WARN("failed to exec sql", K(ins_sql), K(ret));
|
||||
} else if (OB_FAIL(my_session->get_autocommit(is_auto_commit))) {
|
||||
need_clean_up = true;
|
||||
first_err_code = ret;
|
||||
LOG_WARN("failed to get auto commit", K(ret));
|
||||
} else if (!is_auto_commit &&
|
||||
OB_FAIL(conn->execute_write(my_session->get_effective_tenant_id(), "commit;", dummy, true))) {
|
||||
need_clean_up = true;
|
||||
first_err_code = ret;
|
||||
LOG_WARN("failed to exec commit", K(ins_sql), K(ret));
|
||||
} else if (OB_FAIL(common_rpc_proxy->alter_table(alter_table_arg, res))) {
|
||||
need_clean_up = true;
|
||||
first_err_code = ret;
|
||||
LOG_WARN("failed to update table session", K(ret), K(alter_table_arg));
|
||||
my_session->update_last_active_time();
|
||||
if (OB_LIKELY(need_clean)) {
|
||||
int tmp_ret = OB_SUCCESS;
|
||||
if (OB_SUCCESS != (tmp_ret = common_rpc_proxy->drop_table(drop_table_arg))) {
|
||||
LOG_WARN("failed to drop table", K(drop_table_arg), K(ret));
|
||||
} else {
|
||||
LOG_INFO("table is created and dropped due to error ", K(ret));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
plan_ctx->set_affected_rows(affected_rows);
|
||||
LOG_DEBUG("CTAS all done", K(ins_sql), K(affected_rows), K(share::is_oracle_mode()));
|
||||
}
|
||||
|
||||
#ifdef ERRSIM
|
||||
{
|
||||
int test_used_ret = OB_SUCCESS;
|
||||
test_used_ret = E(EventTable::EN_CTAS_FAIL_NO_DROP_ERROR) OB_SUCCESS;
|
||||
if (OB_FAIL(test_used_ret)) {
|
||||
need_clean_up = false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
// do nothing...
|
||||
#endif
|
||||
|
||||
if (need_clean_up) {
|
||||
if (OB_FAIL(common_rpc_proxy->drop_table(drop_table_arg))) {
|
||||
LOG_WARN("failed to drop table", K(drop_table_arg), K(ret));
|
||||
} else {
|
||||
ret = first_err_code;
|
||||
LOG_INFO("table is created and dropped due to error ", K(ret));
|
||||
}
|
||||
}
|
||||
if (OB_NOT_NULL(conn)) {
|
||||
user_sql_proxy->close(conn, true);
|
||||
}
|
||||
} else {
|
||||
LOG_DEBUG("table exists, no need to CTAS", K(table_id));
|
||||
LOG_DEBUG("table exists, no need to CTAS", K(create_table_res.table_id_));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -384,7 +407,7 @@ int ObCreateTableExecutor::execute(ObExecContext& ctx, ObCreateTableStmt& stmt)
|
||||
int ret = OB_SUCCESS;
|
||||
ObTaskExecutorCtx* task_exec_ctx = NULL;
|
||||
obrpc::ObCommonRpcProxy* common_rpc_proxy = NULL;
|
||||
obrpc::UInt64 table_id;
|
||||
obrpc::ObCreateTableRes res;
|
||||
obrpc::ObCreateTableArg& create_table_arg = stmt.get_create_table_arg();
|
||||
ObString first_stmt;
|
||||
ObSelectStmt* select_stmt = stmt.get_sub_select();
|
||||
@ -411,7 +434,7 @@ int ObCreateTableExecutor::execute(ObExecContext& ctx, ObCreateTableStmt& stmt)
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("common rpc proxy should not be null", K(ret));
|
||||
} else if (OB_ISNULL(select_stmt)) {
|
||||
if (OB_FAIL(common_rpc_proxy->create_table(create_table_arg, table_id))) {
|
||||
if (OB_FAIL(common_rpc_proxy->create_table(create_table_arg, res))) {
|
||||
LOG_WARN("rpc proxy create table failed", K(ret), "dst", common_rpc_proxy->get_server());
|
||||
} else { /* do nothing */
|
||||
}
|
||||
@ -419,8 +442,10 @@ int ObCreateTableExecutor::execute(ObExecContext& ctx, ObCreateTableStmt& stmt)
|
||||
LOG_WARN("execute create table as select failed", K(ret));
|
||||
}
|
||||
|
||||
if (OB_SUCC(ret) && 0 != table_schema.get_session_id()) {
|
||||
LOG_DEBUG("CTAS or temporary table create detected", K(table_schema));
|
||||
// only CTAS or create temperary table will make session_id != 0. If such table detected, set
|
||||
// need ctas cleanup task anyway to do some cleanup jobs
|
||||
if (0 != table_schema.get_session_id()) {
|
||||
LOG_TRACE("CTAS or temporary table create detected", K(table_schema));
|
||||
ATOMIC_STORE(&OBSERVER.need_ctas_cleanup_, true);
|
||||
}
|
||||
}
|
||||
|
@ -76,6 +76,12 @@ int PwjTable::init(const ObTableSchema& table_schema, const ObPhyTableLocationIn
|
||||
}
|
||||
}
|
||||
}
|
||||
if (OB_SUCC(ret)
|
||||
&& ((share::schema::PARTITION_LEVEL_TWO == part_level_) || (share::schema::PARTITION_LEVEL_ONE == part_level_))
|
||||
&& 0 == part_number_) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_WARN("get unexpected part number", K(ref_table_id_), K(table_schema), K(phy_tbl_info));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user