fix: match error in killing inner sql when __all_virtual_session_info has no user tenant name in inner sql

This commit is contained in:
JLY2015
2023-05-22 12:11:31 +00:00
committed by ob-robot
parent 19035231a9
commit 058c604632
8 changed files with 50 additions and 14 deletions

View File

@ -425,7 +425,7 @@ int ObInnerSqlRpcP::create_tmp_session(
}
void ObInnerSqlRpcP::cleanup_tmp_session(
sql::ObSQLSessionInfo *tmp_session,
sql::ObSQLSessionInfo *&tmp_session,
sql::ObFreeSessionCtx &free_session_ctx)
{
if (NULL != GCTX.session_mgr_ && NULL != tmp_session) {
@ -531,13 +531,23 @@ int ObInnerSqlRpcP::process()
} else if (OB_FAIL(pool->acquire(transmit_arg.get_conn_id(), transmit_arg.get_is_oracle_mode(),
ObInnerSQLTransmitArg::OPERATION_TYPE_ROLLBACK == transmit_arg.get_operation_type(),
conn, tmp_session))) {
cleanup_tmp_session(tmp_session, free_session_ctx);
LOG_WARN("failed to acquire inner connection", K(ret), K(transmit_arg));
}
/* init session info */
if (OB_SUCC(ret) && OB_NOT_NULL(tmp_session)) {
uint64_t tenant_id = transmit_arg.get_tenant_id();
share::schema::ObSchemaGetterGuard schema_guard;
const ObSimpleTenantSchema *tenant_schema = NULL;
if (OB_FAIL(GCTX.schema_service_->get_tenant_schema_guard(tenant_id, schema_guard))) {
LOG_WARN("fail to get schema guard", K(ret), K(tenant_id));
} else if (OB_FAIL(schema_guard.get_tenant_info(tenant_id, tenant_schema))) {
LOG_WARN("fail to get tenant schema", K(ret), K(tenant_id));
} else if (OB_ISNULL(tenant_schema)) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("tenant schema is null", K(ret));
} else {
tmp_session->set_current_trace_id(ObCurTraceId::get_trace_id());
tmp_session->switch_tenant(transmit_arg.get_tenant_id());
tmp_session->switch_tenant_with_name(transmit_arg.get_tenant_id(), tenant_schema->get_tenant_name_str());
ObString sql_stmt(sql_str.ptr());
if (OB_FAIL(tmp_session->set_session_active(
sql_stmt,
@ -547,6 +557,7 @@ int ObInnerSqlRpcP::process()
LOG_WARN("failed to set tmp session active", K(ret));
}
}
}
if (OB_FAIL(ret)) {
} else if (OB_ISNULL(inner_conn = static_cast<observer::ObInnerSQLConnection *>(conn))) {
// do nothing, because conn was set null if need kill_using_conn in aquire

View File

@ -46,7 +46,7 @@ private:
sql::ObFreeSessionCtx &free_session_ctx,
const bool is_oracle_mode);
void cleanup_tmp_session(
sql::ObSQLSessionInfo *tmp_session,
sql::ObSQLSessionInfo *&tmp_session,
sql::ObFreeSessionCtx &free_session_ctx);
int process_start_transaction(

View File

@ -136,7 +136,7 @@ int ObAllVirtualSessionInfo::FillScanner::operator()(
break;
}
case TENANT: {
cur_row_->cells_[cell_idx].set_varchar(sess_info->get_tenant_name());
cur_row_->cells_[cell_idx].set_varchar(sess_info->get_effective_tenant_name());
cur_row_->cells_[cell_idx].set_collation_type(default_collation);
break;
}

View File

@ -3220,6 +3220,7 @@ int ObDDLTaskRecordOperator::kill_task_inner_sql(
LOG_WARN("assign sql string failed", K(ret));
}
}
LOG_INFO("kill session sql string", K(sql_string), K(task_id), K(sql_exec_addr));
if (OB_FAIL(ret)) {
} else if (OB_FAIL(proxy.read(res, OB_SYS_TENANT_ID, sql_string.ptr(), &sql_exec_addr))) { // default use OB_SYS_TENANT_ID
LOG_WARN("query ddl task record failed", K(ret), K(sql_string));

View File

@ -462,6 +462,7 @@ class ObString;
ACT(BEFORE_CHECK_CLEAN_DRTASK,)\
ACT(BEFORE_UNIQ_TASK_RUN,)\
ACT(BEFORE_PARELLEL_TRUNCATE,)\
ACT(END_DDL_IN_PX_SUBCOORD,)\
ACT(MAX_DEBUG_SYNC_POINT,)
DECLARE_ENUM(ObDebugSyncPoint, debug_sync_point, OB_DEBUG_SYNC_POINT_DEF);

View File

@ -872,6 +872,7 @@ int ObPxSubCoord::end_ddl(const bool need_commit)
}
LOG_INFO("end ddl sstable", K(ret), K(need_commit));
}
DEBUG_SYNC(END_DDL_IN_PX_SUBCOORD);
if (OB_EAGAIN == ret) {
ret = OB_STATE_NOT_MATCH; // avoid px hang
}

View File

@ -535,6 +535,27 @@ int ObBasicSessionInfo::set_tenant(const common::ObString &tenant_name,
return ret;
}
int ObBasicSessionInfo::switch_tenant_with_name(
uint64_t effective_tenant_id, const common::ObString &tenant_name)
{
int ret = OB_SUCCESS;
if (!is_valid_tenant_id(effective_tenant_id)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid tenant id", K(ret), K(effective_tenant_id));
} else if (tenant_name.empty()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("tenant name is empty", K(ret), K(tenant_name));
} else if (tenant_name.length() > OB_MAX_TENANT_NAME_LENGTH) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("tenant name too long", K(ret), K(tenant_name));
} else if (OB_FAIL(switch_tenant(effective_tenant_id))) {
LOG_WARN("fail to switch tenant", K(ret), K(effective_tenant_id));
} else if (OB_FAIL(ob_cstrcopy(effective_tenant_, sizeof(effective_tenant_), tenant_name))) {
LOG_WARN("tenant name too long", K(ret), K(tenant_name));
}
return ret;
}
int ObBasicSessionInfo::switch_tenant(uint64_t effective_tenant_id)
{
int ret = OB_SUCCESS;

View File

@ -407,6 +407,7 @@ public:
const uint64_t length,
uint64_t &ori_tenant_id);
int switch_tenant(uint64_t effective_tenant_id);
int switch_tenant_with_name(uint64_t effective_tenant_id, const common::ObString &tenant_name);
int set_default_database(const common::ObString &database_name,
common::ObCollationType coll_type = common::CS_TYPE_INVALID);
int reset_default_database() { return set_default_database(""); }