patch 4.0
This commit is contained in:
@ -16,154 +16,150 @@
|
||||
#include "share/ob_define.h"
|
||||
#include "sql/resolver/xa/ob_xa_stmt.h"
|
||||
#include "sql/ob_sql_trans_control.h"
|
||||
#include "storage/transaction/ob_trans_define.h"
|
||||
#include "storage/tx/ob_trans_define.h"
|
||||
#include "sql/engine/ob_exec_context.h"
|
||||
#include "sql/executor/ob_task_executor_ctx.h"
|
||||
#include "storage/ob_partition_service.h"
|
||||
#include "storage/tx/ob_xa_service.h"
|
||||
#include "pl/ob_pl.h"
|
||||
|
||||
namespace oceanbase {
|
||||
namespace oceanbase
|
||||
{
|
||||
using namespace common;
|
||||
using namespace transaction;
|
||||
namespace sql {
|
||||
|
||||
static inline void init_start_trans_param(
|
||||
ObSQLSessionInfo* session, ObTaskExecutorCtx& task_exec_ctx, transaction::ObStartTransParam& param)
|
||||
namespace sql
|
||||
{
|
||||
param.set_access_mode(transaction::ObTransAccessMode::READ_WRITE);
|
||||
param.set_type(session->get_trans_type());
|
||||
param.set_isolation(session->get_tx_isolation());
|
||||
param.set_cluster_version(task_exec_ctx.get_min_cluster_version());
|
||||
param.set_inner_trans(session->is_inner());
|
||||
}
|
||||
|
||||
int ObXaStartExecutor::execute(ObExecContext& ctx, ObXaStartStmt& stmt)
|
||||
int ObXaStartExecutor::execute(ObExecContext &ctx, ObXaStartStmt &stmt)
|
||||
{
|
||||
int ret = OB_NOT_SUPPORTED;
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "XA protocol start interface");
|
||||
UNUSED(ctx);
|
||||
UNUSED(stmt);
|
||||
// 暂时禁掉mysql模式下的xa调用
|
||||
return ret;
|
||||
/*
|
||||
}
|
||||
|
||||
int ObPlXaStartExecutor::execute(ObExecContext &ctx, ObXaStartStmt &stmt)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
int tmp_ret = OB_SUCCESS;
|
||||
ObPhysicalPlanCtx *plan_ctx = GET_PHY_PLAN_CTX(ctx);
|
||||
ObSQLSessionInfo *my_session = GET_MY_SESSION(ctx);
|
||||
ObTaskExecutorCtx &task_exec_ctx = ctx.get_task_exec_ctx();
|
||||
storage::ObPartitionService *ps = nullptr;
|
||||
int32_t xa_trans_state = ObXATransState::NON_EXISTING;
|
||||
ObTransDesc &trans_desc = my_session->get_trans_desc();
|
||||
|
||||
if (OB_ISNULL(plan_ctx) || OB_ISNULL(my_session)
|
||||
|| OB_ISNULL(ps = task_exec_ctx.get_partition_service())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_ERROR("invalid param", K(ret), K(plan_ctx), K(my_session));
|
||||
} else if (OB_FAIL(ps->get_xa_trans_state(xa_trans_state, trans_desc))) {
|
||||
LOG_WARN("get xa trans state failed", K(ret));
|
||||
} else if (ObXATransState::NON_EXISTING != xa_trans_state) {
|
||||
ret = OB_TRANS_XA_RMFAIL;
|
||||
LOG_USER_ERROR(OB_TRANS_XA_RMFAIL, ObXATransState::to_string(xa_trans_state));
|
||||
LOG_WARN("invalid xa state", K(ret), K(xa_trans_state));
|
||||
} else if (my_session->get_in_transaction()) {
|
||||
ret = OB_TRANS_XA_OUTSIDE;
|
||||
LOG_WARN("already start trans", K(ret));
|
||||
} else {
|
||||
transaction::ObStartTransParam &start_trans_param = plan_ctx->get_start_trans_param();
|
||||
init_start_trans_param(my_session, task_exec_ctx, start_trans_param);
|
||||
if (OB_FAIL(ObSqlTransControl::explicit_start_trans(ctx, start_trans_param))) {
|
||||
LOG_WARN("explicit start trans failed", K(ret), K(start_trans_param));
|
||||
} else if (OB_FAIL(ps->xa_start(stmt.get_xa_string(),
|
||||
stmt.get_gtrid_string().length(),
|
||||
stmt.get_bqual_string().length(),
|
||||
stmt.get_format_id(),
|
||||
stmt.get_flags(),
|
||||
trans_desc))) {
|
||||
LOG_WARN("xa start failed", K(ret), K(start_trans_param));
|
||||
if (OB_SUCCESS != (tmp_ret = ObSqlTransControl::explicit_end_trans(ctx, true))) {
|
||||
ret = tmp_ret;
|
||||
LOG_WARN("explicit end trans failed", K(ret));
|
||||
}
|
||||
} else {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
LOG_DEBUG("xa start execute", K(stmt.get_xa_string()));
|
||||
return ret;
|
||||
*/
|
||||
}
|
||||
|
||||
int ObPlXaStartExecutor::execute(ObExecContext& ctx, ObXaStartStmt& stmt)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObPhysicalPlanCtx* plan_ctx = GET_PHY_PLAN_CTX(ctx);
|
||||
ObSQLSessionInfo* my_session = GET_MY_SESSION(ctx);
|
||||
ObTaskExecutorCtx& task_exec_ctx = ctx.get_task_exec_ctx();
|
||||
storage::ObPartitionService* ps = nullptr;
|
||||
ObTransDesc& trans_desc = my_session->get_trans_desc();
|
||||
ObXATransID xid;
|
||||
int64_t org_cluster_id = OB_INVALID_ORG_CLUSTER_ID;
|
||||
int64_t tx_timeout = 0;
|
||||
uint64_t tenant_id = 0;
|
||||
|
||||
if (OB_ISNULL(plan_ctx) || OB_ISNULL(my_session) || OB_ISNULL(ps = task_exec_ctx.get_partition_service())) {
|
||||
if (OB_ISNULL(plan_ctx) || OB_ISNULL(my_session)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_ERROR("invalid param", K(ret), K(plan_ctx), K(my_session));
|
||||
ret = OB_TRANS_XA_RMFAIL;
|
||||
} else if (!stmt.is_valid_oracle_xid()) {
|
||||
ret = OB_TRANS_XA_INVAL;
|
||||
LOG_WARN("invalid xid for oracle mode", K(ret), K(stmt));
|
||||
} else if (OB_FAIL(xid.set(stmt.get_gtrid_string(), stmt.get_bqual_string(), stmt.get_format_id()))) {
|
||||
} else if (OB_FAIL(xid.set(stmt.get_gtrid_string(),
|
||||
stmt.get_bqual_string(),
|
||||
stmt.get_format_id()))) {
|
||||
LOG_WARN("set xid error", K(ret), K(stmt));
|
||||
} else if (my_session->get_in_transaction()) {
|
||||
ret = OB_TRANS_XA_OUTSIDE;
|
||||
LOG_WARN("already start trans", K(ret), K(stmt.get_xa_string()), K(trans_desc));
|
||||
LOG_WARN("already start trans", K(ret), K(stmt.get_xa_string()));
|
||||
} else if (OB_FAIL(get_org_cluster_id_(my_session, org_cluster_id))) {
|
||||
} else if (OB_FAIL(my_session->get_tx_timeout(tx_timeout))) {
|
||||
LOG_ERROR("fail to get trans timeout ts", K(ret));
|
||||
} else if (FALSE_IT(tenant_id = my_session->get_effective_tenant_id())) {
|
||||
} else {
|
||||
transaction::ObStartTransParam& start_trans_param = plan_ctx->get_start_trans_param();
|
||||
init_start_trans_param(my_session, task_exec_ctx, start_trans_param);
|
||||
const int64_t flags = stmt.get_flags();
|
||||
transaction::ObTxParam &tx_param = plan_ctx->get_trans_param();
|
||||
const bool is_readonly = ObXAFlag::contain_tmreadonly(flags);
|
||||
const bool is_serializable = ObXAFlag::contain_tmserializable(flags);
|
||||
if (is_readonly && !my_session->get_tx_read_only()) {
|
||||
tx_param.access_mode_ = ObTxAccessMode::RD_ONLY;
|
||||
} else {
|
||||
tx_param.access_mode_ = my_session->get_tx_read_only() ? ObTxAccessMode::RD_ONLY : ObTxAccessMode::RW;
|
||||
}
|
||||
if (is_serializable && !my_session->is_isolation_serializable()) {
|
||||
tx_param.isolation_ = ObTxIsolationLevel::SERIAL;
|
||||
} else {
|
||||
tx_param.isolation_ = my_session->get_tx_isolation();
|
||||
}
|
||||
tx_param.cluster_id_ = org_cluster_id;
|
||||
tx_param.timeout_us_ = tx_timeout;
|
||||
|
||||
if (OB_FAIL(ObSqlTransControl::explicit_start_trans(ctx, start_trans_param))) {
|
||||
LOG_WARN("explicit start trans failed", K(ret), K(start_trans_param));
|
||||
} else if (OB_FAIL(ps->xa_start(xid, stmt.get_flags(), my_session->get_xa_end_timeout_seconds(), trans_desc))) {
|
||||
LOG_WARN("xa start failed", K(ret), K(start_trans_param));
|
||||
// if (OB_SUCCESS != (tmp_ret = ObSqlTransControl::explicit_end_trans(ctx, true))) {
|
||||
// ret = tmp_ret;
|
||||
// LOG_WARN("explicit end trans failed", K(ret));
|
||||
//}
|
||||
my_session->reset_first_stmt_type();
|
||||
ObTxDesc *&tx_desc = my_session->get_tx_desc();
|
||||
if (OB_FAIL(MTL(transaction::ObXAService*)->xa_start(xid,
|
||||
flags,
|
||||
my_session->get_xa_end_timeout_seconds(),
|
||||
my_session->get_sessid(),
|
||||
tx_param,
|
||||
tx_desc))) {
|
||||
LOG_WARN("xa start failed", K(ret), K(tx_param));
|
||||
my_session->reset_first_need_txn_stmt_type();
|
||||
my_session->reset_tx_variable();
|
||||
my_session->set_early_lock_release(false);
|
||||
ctx.set_need_disconnect(false);
|
||||
my_session->get_trans_desc().get_standalone_stmt_desc().reset();
|
||||
} else {
|
||||
// do nothing
|
||||
// associate xa with session
|
||||
my_session->associate_xa(xid);
|
||||
my_session->set_explicit_start_trans(true);
|
||||
}
|
||||
}
|
||||
LOG_DEBUG("xa start execute", K(stmt));
|
||||
LOG_INFO("xa start execute", K(stmt));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObXaEndExecutor::execute(ObExecContext& ctx, ObXaEndStmt& stmt)
|
||||
int ObPlXaStartExecutor::get_org_cluster_id_(ObSQLSessionInfo *session, int64_t &org_cluster_id) {
|
||||
int ret = OB_SUCCESS;
|
||||
if (OB_FAIL(session->get_ob_org_cluster_id(org_cluster_id))) {
|
||||
LOG_WARN("fail to get ob_org_cluster_id", K(ret));
|
||||
} else if (OB_INVALID_ORG_CLUSTER_ID == org_cluster_id ||
|
||||
OB_INVALID_CLUSTER_ID == org_cluster_id) {
|
||||
org_cluster_id = ObServerConfig::get_instance().cluster_id;
|
||||
// 如果没设置ob_org_cluster_id(0为非法值,认为没有设置),则设为当前集群的cluster_id。
|
||||
// 如果配置项中没设置cluster_id,则ObServerConfig::get_instance().cluster_id会拿到默认值-1。
|
||||
// 配置项中没设置cluster_id的话observer是起不来的,因此这里org_cluster_id不会为-1。
|
||||
// 保险起见,这里判断org_cluster_id为0或者-1都将其设为ObServerConfig::get_instance().cluster_id。
|
||||
if (org_cluster_id < OB_MIN_CLUSTER_ID
|
||||
|| org_cluster_id > OB_MAX_CLUSTER_ID) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_ERROR("org_cluster_id is set to cluster_id, but it is out of range",
|
||||
K(ret), K(org_cluster_id), K(OB_MIN_CLUSTER_ID), K(OB_MAX_CLUSTER_ID));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObXaEndExecutor::execute(ObExecContext &ctx, ObXaEndStmt &stmt)
|
||||
{
|
||||
int ret = OB_NOT_SUPPORTED;
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "XA protocol end interface");
|
||||
UNUSED(ctx);
|
||||
UNUSED(stmt);
|
||||
// 暂时禁掉mysql模式下的xa调用
|
||||
return ret;
|
||||
/*
|
||||
int ret = OB_SUCCESS;
|
||||
int tmp_ret = OB_SUCCESS;
|
||||
ObSQLSessionInfo *my_session = GET_MY_SESSION(ctx);
|
||||
ObTaskExecutorCtx &task_exec_ctx = ctx.get_task_exec_ctx();
|
||||
storage::ObPartitionService *ps = nullptr;
|
||||
//storage::ObPartitionService *ps = nullptr;
|
||||
|
||||
if (OB_ISNULL(my_session) || OB_ISNULL(ps = task_exec_ctx.get_partition_service())) {
|
||||
// if (OB_ISNULL(my_session) || OB_ISNULL(ps = task_exec_ctx.get_partition_service())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_ERROR("invalid param", K(ret), K(my_session));
|
||||
// mysql调用flags置为TMSUCCESS
|
||||
} else if (OB_FAIL(ps->xa_end(stmt.get_xa_string(),
|
||||
transaction::ObXAEndFlag::TMSUCCESS,
|
||||
my_session->get_trans_desc()))) {
|
||||
LOG_WARN("xa end failed", K(ret), K(stmt.get_xa_string()));
|
||||
// 如果是OB_TRANS_XA_RMFAIL错误那么由用户决定是否回滚
|
||||
if (OB_TRANS_XA_RMFAIL != ret
|
||||
&& OB_SUCCESS != (tmp_ret = ObSqlTransControl::explicit_end_trans(ctx, true))) {
|
||||
ret = tmp_ret;
|
||||
LOG_WARN("explicit end trans failed", K(ret));
|
||||
}
|
||||
} else {
|
||||
my_session->reset_first_stmt_type();
|
||||
my_session->reset_first_need_txn_stmt_type();
|
||||
my_session->reset_tx_variable();
|
||||
my_session->set_early_lock_release(false);
|
||||
ctx.set_need_disconnect(false);
|
||||
@ -174,49 +170,58 @@ int ObXaEndExecutor::execute(ObExecContext& ctx, ObXaEndStmt& stmt)
|
||||
*/
|
||||
}
|
||||
|
||||
int ObPlXaEndExecutor::execute(ObExecContext& ctx, ObXaEndStmt& stmt)
|
||||
int ObPlXaEndExecutor::execute(ObExecContext &ctx, ObXaEndStmt &stmt)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
// int tmp_ret = OB_SUCCESS;
|
||||
ObSQLSessionInfo* my_session = GET_MY_SESSION(ctx);
|
||||
ObTaskExecutorCtx& task_exec_ctx = ctx.get_task_exec_ctx();
|
||||
storage::ObPartitionService* ps = nullptr;
|
||||
//int tmp_ret = OB_SUCCESS;
|
||||
ObSQLSessionInfo *my_session = GET_MY_SESSION(ctx);
|
||||
ObTaskExecutorCtx &task_exec_ctx = ctx.get_task_exec_ctx();
|
||||
ObXATransID xid;
|
||||
|
||||
if (OB_ISNULL(my_session) || OB_ISNULL(ps = task_exec_ctx.get_partition_service())) {
|
||||
if (OB_ISNULL(my_session)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_ERROR("invalid param", K(ret), K(my_session));
|
||||
} else if (!stmt.is_valid_oracle_xid()) {
|
||||
ret = OB_TRANS_XA_INVAL;
|
||||
LOG_WARN("invalid xid for oracle mode", K(ret), K(stmt));
|
||||
} else if (OB_FAIL(xid.set(stmt.get_gtrid_string(), stmt.get_bqual_string(), stmt.get_format_id()))) {
|
||||
} else if (OB_FAIL(xid.set(stmt.get_gtrid_string(),
|
||||
stmt.get_bqual_string(),
|
||||
stmt.get_format_id()))) {
|
||||
LOG_WARN("set xid error", K(ret), K(stmt));
|
||||
} else if (!my_session->get_in_transaction()) {
|
||||
ret = OB_TRANS_XA_PROTO;
|
||||
LOG_WARN("not in a trans", K(ret));
|
||||
} else if (OB_FAIL(ps->xa_end(xid, stmt.get_flags(), my_session->get_trans_desc()))) {
|
||||
LOG_WARN("xa end failed", K(ret), K(stmt.get_xa_string()));
|
||||
// if (OB_TRANS_XA_RMFAIL != ret
|
||||
// && OB_SUCCESS != (tmp_ret = ObSqlTransControl::explicit_end_trans(ctx, true))) {
|
||||
// ret = tmp_ret;
|
||||
// LOG_WARN("explicit end trans failed", K(ret));
|
||||
// }
|
||||
} else {
|
||||
my_session->reset_first_stmt_type();
|
||||
my_session->reset_tx_variable();
|
||||
my_session->set_early_lock_release(false);
|
||||
ctx.set_need_disconnect(false);
|
||||
my_session->get_trans_desc().get_standalone_stmt_desc().reset();
|
||||
int64_t flags = stmt.get_flags();
|
||||
flags = my_session->has_tx_level_temp_table() ? (flags | ObXAFlag::TEMPTABLE) : flags;
|
||||
if (OB_FAIL(MTL(transaction::ObXAService*)->xa_end(xid, flags,
|
||||
my_session->get_tx_desc()))) {
|
||||
LOG_WARN("xa end failed", K(ret), K(stmt.get_xa_string()));
|
||||
// 如果是OB_TRANS_XA_RMFAIL错误那么由用户决定是否回滚
|
||||
// if (OB_TRANS_XA_RMFAIL != ret
|
||||
// && OB_SUCCESS != (tmp_ret = ObSqlTransControl::explicit_end_trans(ctx, true))) {
|
||||
// ret = tmp_ret;
|
||||
// LOG_WARN("explicit end trans failed", K(ret));
|
||||
// }
|
||||
} else {
|
||||
my_session->reset_first_need_txn_stmt_type();
|
||||
my_session->reset_tx_variable();
|
||||
my_session->set_early_lock_release(false);
|
||||
my_session->disassociate_xa();
|
||||
ctx.set_need_disconnect(false);
|
||||
}
|
||||
}
|
||||
LOG_DEBUG("xa end execute", K(stmt));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObXaPrepareExecutor::execute(ObExecContext& ctx, ObXaPrepareStmt& stmt)
|
||||
int ObXaPrepareExecutor::execute(ObExecContext &ctx, ObXaPrepareStmt &stmt)
|
||||
{
|
||||
int ret = OB_NOT_SUPPORTED;
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "XA protocol prepare interface");
|
||||
UNUSED(ctx);
|
||||
UNUSED(stmt);
|
||||
// 暂时禁掉mysql模式下的xa调用
|
||||
return ret;
|
||||
/*
|
||||
int ret = OB_SUCCESS;
|
||||
@ -224,9 +229,9 @@ int ObXaPrepareExecutor::execute(ObExecContext& ctx, ObXaPrepareStmt& stmt)
|
||||
ObSQLSessionInfo *my_session = GET_MY_SESSION(ctx);
|
||||
ObTaskExecutorCtx &task_exec_ctx = ctx.get_task_exec_ctx();
|
||||
ObPhysicalPlanCtx *plan_ctx = GET_PHY_PLAN_CTX(ctx);
|
||||
storage::ObPartitionService *ps = nullptr;
|
||||
//storage::ObPartitionService *ps = nullptr;
|
||||
if (OB_ISNULL(my_session) || OB_ISNULL(plan_ctx)
|
||||
|| OB_ISNULL(ps = task_exec_ctx.get_partition_service())) {
|
||||
// || OB_ISNULL(ps = task_exec_ctx.get_partition_service())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_ERROR("invalid param", K(ret), K(my_session), K(plan_ctx), K(ps));
|
||||
} else if (my_session->get_in_transaction()) {
|
||||
@ -239,6 +244,7 @@ int ObXaPrepareExecutor::execute(ObExecContext& ctx, ObXaPrepareStmt& stmt)
|
||||
init_start_trans_param(my_session, task_exec_ctx, start_trans_param);
|
||||
if (OB_FAIL(ps->xa_prepare(stmt.get_xa_string(), tenant_id, timeout))) {
|
||||
LOG_WARN("xa prepare failed", K(ret), K(stmt.get_xa_string()));
|
||||
// 如果是OB_TRANS_XA_RMFAIL错误那么由用户决定是否回滚
|
||||
// if (OB_TRANS_XA_RMFAIL != ret
|
||||
// && OB_SUCCESS != (tmp_ret = ObSqlTransControl::explicit_end_trans(ctx, true))) {
|
||||
// ret = tmp_ret;
|
||||
@ -252,154 +258,198 @@ int ObXaPrepareExecutor::execute(ObExecContext& ctx, ObXaPrepareStmt& stmt)
|
||||
*/
|
||||
}
|
||||
|
||||
int ObPlXaPrepareExecutor::execute(ObExecContext& ctx, ObXaPrepareStmt& stmt)
|
||||
int ObPlXaPrepareExecutor::execute(ObExecContext &ctx, ObXaPrepareStmt &stmt)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSQLSessionInfo* my_session = GET_MY_SESSION(ctx);
|
||||
ObTaskExecutorCtx& task_exec_ctx = ctx.get_task_exec_ctx();
|
||||
ObPhysicalPlanCtx* plan_ctx = GET_PHY_PLAN_CTX(ctx);
|
||||
storage::ObPartitionService* ps = nullptr;
|
||||
ObSQLSessionInfo *my_session = GET_MY_SESSION(ctx);
|
||||
ObTaskExecutorCtx &task_exec_ctx = ctx.get_task_exec_ctx();
|
||||
ObXATransID xid;
|
||||
if (OB_ISNULL(my_session) || OB_ISNULL(plan_ctx) || OB_ISNULL(ps = task_exec_ctx.get_partition_service())) {
|
||||
|
||||
if (OB_ISNULL(my_session)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_ERROR("invalid param", K(ret), K(my_session), K(plan_ctx), K(ps));
|
||||
LOG_ERROR("invalid param", K(ret), K(my_session));
|
||||
} else if (!stmt.is_valid_oracle_xid()) {
|
||||
ret = OB_TRANS_XA_INVAL;
|
||||
LOG_WARN("invalid xid for oracle mode", K(ret), K(stmt));
|
||||
} else if (OB_FAIL(xid.set(stmt.get_gtrid_string(), stmt.get_bqual_string(), stmt.get_format_id()))) {
|
||||
} else if (OB_FAIL(xid.set(stmt.get_gtrid_string(),
|
||||
stmt.get_bqual_string(),
|
||||
stmt.get_format_id()))) {
|
||||
LOG_WARN("set xid error", K(ret), K(stmt));
|
||||
} else if (my_session->get_in_transaction()) {
|
||||
ret = OB_TRANS_XA_RMERR;
|
||||
LOG_WARN("already start trans", K(ret));
|
||||
} else {
|
||||
const uint64_t tenant_id = my_session->get_effective_tenant_id();
|
||||
int64_t timeout = plan_ctx->get_trans_timeout_timestamp();
|
||||
transaction::ObStartTransParam& start_trans_param = plan_ctx->get_start_trans_param();
|
||||
init_start_trans_param(my_session, task_exec_ctx, start_trans_param);
|
||||
if (OB_FAIL(ps->xa_prepare(xid, tenant_id, timeout))) {
|
||||
int64_t timeout_seconds = my_session->get_xa_end_timeout_seconds();
|
||||
if (OB_FAIL(MTL(transaction::ObXAService*)->xa_prepare(xid, timeout_seconds))) {
|
||||
if (OB_TRANS_XA_RDONLY != ret) {
|
||||
LOG_WARN("xa prepare failed", K(ret), K(stmt));
|
||||
}
|
||||
// TODO: 如果是OB_TRANS_XA_RMFAIL错误那么由用户决定是否回滚
|
||||
}
|
||||
}
|
||||
|
||||
LOG_DEBUG("xa prepare execute", K(stmt));
|
||||
LOG_INFO("xa prepare execute", K(stmt));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObXaEndTransExecutor::execute_(const ObString& xid, const bool is_rollback, ObExecContext& ctx)
|
||||
int ObXaEndTransExecutor::execute_(const ObString &xid,
|
||||
const bool is_rollback, ObExecContext &ctx)
|
||||
{
|
||||
int ret = OB_NOT_SUPPORTED;
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "XA protocol end trans interface");
|
||||
UNUSED(xid);
|
||||
UNUSED(is_rollback);
|
||||
UNUSED(ctx);
|
||||
// 暂时禁掉mysql模式下的xa调用
|
||||
return ret;
|
||||
/*
|
||||
}
|
||||
|
||||
int ObPlXaEndTransExecutor::execute(ObExecContext &ctx, ObXaCommitStmt &stmt)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!stmt.is_valid_oracle_xid()) {
|
||||
ret = OB_TRANS_XA_INVAL;
|
||||
LOG_WARN("invalid xid for oracle mode", K(ret), K(stmt));
|
||||
} else {
|
||||
ret = execute_(stmt.get_gtrid_string(),
|
||||
stmt.get_bqual_string(),
|
||||
stmt.get_format_id(),
|
||||
false,
|
||||
stmt.get_flags(),
|
||||
ctx);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPlXaEndTransExecutor::execute(ObExecContext &ctx, ObXaRollBackStmt &stmt)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!stmt.is_valid_oracle_xid()) {
|
||||
ret = OB_TRANS_XA_INVAL;
|
||||
LOG_WARN("invalid xid for oracle mode", K(ret), K(stmt));
|
||||
} else {
|
||||
ret = execute_(stmt.get_gtrid_string(),
|
||||
stmt.get_bqual_string(),
|
||||
stmt.get_format_id(),
|
||||
true,
|
||||
stmt.get_flags(),
|
||||
ctx);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPlXaEndTransExecutor::execute_(const ObString >rid_str,
|
||||
const ObString &bqual_str,
|
||||
const int64_t format_id,
|
||||
const bool is_rollback,
|
||||
const int64_t flags,
|
||||
ObExecContext &ctx)
|
||||
{
|
||||
UNUSEDx(gtrid_str, bqual_str, format_id, is_rollback, flags, ctx);
|
||||
int ret = OB_NOT_SUPPORTED;
|
||||
LOG_USER_ERROR(OB_NOT_SUPPORTED, "XA protocol end trans interface");
|
||||
// ObSQLSessionInfo *my_session = GET_MY_SESSION(ctx);
|
||||
// ObTaskExecutorCtx &task_exec_ctx = ctx.get_task_exec_ctx();
|
||||
// ObPhysicalPlanCtx *plan_ctx = GET_PHY_PLAN_CTX(ctx);
|
||||
// ObTxDesc &trans_desc = *my_session->get_tx_desc();
|
||||
// storage::ObPartitionService *ps = nullptr;
|
||||
// ObXATransID xid;
|
||||
|
||||
// if (OB_ISNULL(plan_ctx) || OB_ISNULL(my_session)
|
||||
// || OB_ISNULL(ps = task_exec_ctx.get_partition_service())) {
|
||||
// ret = OB_ERR_UNEXPECTED;
|
||||
// LOG_ERROR("invalid param", K(ret), K(plan_ctx), K(my_session));
|
||||
// } else if (OB_FAIL(xid.set(gtrid_str,
|
||||
// bqual_str,
|
||||
// format_id))) {
|
||||
// LOG_WARN("set xid error", K(ret), K(gtrid_str), K(bqual_str), K(format_id));
|
||||
// } else if (my_session->get_in_transaction()) {
|
||||
// ret = OB_TRANS_XA_RMFAIL;
|
||||
// LOG_WARN("already start trans", K(ret));
|
||||
// } else {
|
||||
// transaction::ObTxParam &tx_param = plan_ctx->get_trans_param();
|
||||
// if (OB_FAIL(ObSqlTransControl::explicit_start_trans(ctx, false))) {
|
||||
// LOG_WARN("explicit start trans failed", K(ret), K(tx_param));
|
||||
// } else if (OB_FAIL(ps->xa_end_trans(xid, is_rollback, flags, trans_desc))) {
|
||||
// LOG_WARN("fail to execute xa commit/rollback", K(xid), K(is_rollback));
|
||||
// } else {
|
||||
// LOG_DEBUG("succeed to execute xa commit/rollback", K(xid), K(is_rollback));
|
||||
// }
|
||||
// my_session->reset_first_need_txn_stmt_type();
|
||||
// my_session->reset_tx_variable();
|
||||
// my_session->set_early_lock_release(false);
|
||||
// ctx.set_need_disconnect(false);
|
||||
// }
|
||||
// LOG_DEBUG("xa end_trans execute", K(gtrid_str), K(bqual_str), K(format_id), K(is_rollback),
|
||||
// K(flags));
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPlXaCommitExecutor::execute(ObExecContext &ctx, ObXaCommitStmt &stmt)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSQLSessionInfo *my_session = GET_MY_SESSION(ctx);
|
||||
ObTaskExecutorCtx &task_exec_ctx = ctx.get_task_exec_ctx();
|
||||
ObPhysicalPlanCtx *plan_ctx = GET_PHY_PLAN_CTX(ctx);
|
||||
ObTransDesc &trans_desc = my_session->get_trans_desc();
|
||||
storage::ObPartitionService *ps = nullptr;
|
||||
|
||||
if (OB_ISNULL(plan_ctx) || OB_ISNULL(my_session)
|
||||
|| OB_ISNULL(ps = task_exec_ctx.get_partition_service())) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_ERROR("invalid param", K(ret), K(plan_ctx), K(my_session));
|
||||
} else if (my_session->get_in_transaction()) {
|
||||
ret = OB_TRANS_XA_OUTSIDE;
|
||||
LOG_WARN("already start trans", K(ret));
|
||||
} else {
|
||||
transaction::ObStartTransParam &start_trans_param = plan_ctx->get_start_trans_param();
|
||||
init_start_trans_param(my_session, task_exec_ctx, start_trans_param);
|
||||
if (OB_FAIL(ObSqlTransControl::explicit_start_trans(ctx, start_trans_param))) {
|
||||
LOG_WARN("explicit start trans failed", K(ret), K(start_trans_param));
|
||||
} else if (OB_FAIL(ps->xa_end_trans(xid, is_rollback, 0, trans_desc))) {
|
||||
LOG_WARN("fail to execute xa commit/rollback", K(xid), K(is_rollback));
|
||||
} else {
|
||||
LOG_DEBUG("succeed to execute xa commit/rollback", K(xid), K(is_rollback));
|
||||
}
|
||||
my_session->reset_first_stmt_type();
|
||||
my_session->reset_tx_variable();
|
||||
my_session->set_early_lock_release(false);
|
||||
ctx.set_need_disconnect(false);
|
||||
my_session->get_trans_desc().get_standalone_stmt_desc().reset();
|
||||
}
|
||||
LOG_DEBUG("xa end_trans execute", K(xid), K(is_rollback));
|
||||
return ret;
|
||||
*/
|
||||
}
|
||||
|
||||
int ObPlXaEndTransExecutor::execute(ObExecContext& ctx, ObXaCommitStmt& stmt)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!stmt.is_valid_oracle_xid()) {
|
||||
ret = OB_TRANS_XA_INVAL;
|
||||
LOG_WARN("invalid xid for oracle mode", K(ret), K(stmt));
|
||||
} else {
|
||||
ret =
|
||||
execute_(stmt.get_gtrid_string(), stmt.get_bqual_string(), stmt.get_format_id(), false, stmt.get_flags(), ctx);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPlXaEndTransExecutor::execute(ObExecContext& ctx, ObXaRollBackStmt& stmt)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
if (!stmt.is_valid_oracle_xid()) {
|
||||
ret = OB_TRANS_XA_INVAL;
|
||||
LOG_WARN("invalid xid for oracle mode", K(ret), K(stmt));
|
||||
} else {
|
||||
ret = execute_(stmt.get_gtrid_string(), stmt.get_bqual_string(), stmt.get_format_id(), true, stmt.get_flags(), ctx);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ObPlXaEndTransExecutor::execute_(const ObString& gtrid_str, const ObString& bqual_str, const int64_t format_id,
|
||||
const bool is_rollback, const int64_t flags, ObExecContext& ctx)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSQLSessionInfo* my_session = GET_MY_SESSION(ctx);
|
||||
ObTaskExecutorCtx& task_exec_ctx = ctx.get_task_exec_ctx();
|
||||
ObPhysicalPlanCtx* plan_ctx = GET_PHY_PLAN_CTX(ctx);
|
||||
ObTransDesc& trans_desc = my_session->get_trans_desc();
|
||||
storage::ObPartitionService* ps = nullptr;
|
||||
ObTxDesc *tx_desc = my_session->get_tx_desc();
|
||||
int64_t xa_timeout_seconds = my_session->get_xa_end_timeout_seconds();
|
||||
ObXATransID xid;
|
||||
bool access_temp_table = false;
|
||||
|
||||
if (OB_ISNULL(plan_ctx) || OB_ISNULL(my_session) || OB_ISNULL(ps = task_exec_ctx.get_partition_service())) {
|
||||
bool has_tx_level_temp_table = false;
|
||||
if (!stmt.is_valid_oracle_xid()) {
|
||||
ret = OB_TRANS_XA_INVAL;
|
||||
LOG_WARN("invalid xid for oracle mode", K(ret), K(stmt));
|
||||
} else if (OB_ISNULL(my_session)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_ERROR("invalid param", K(ret), K(plan_ctx), K(my_session));
|
||||
} else if (OB_FAIL(xid.set(gtrid_str, bqual_str, format_id))) {
|
||||
LOG_WARN("set xid error", K(ret), K(gtrid_str), K(bqual_str), K(format_id));
|
||||
LOG_ERROR("invalid param", K(ret), K(my_session));
|
||||
} else if (OB_FAIL(xid.set(stmt.get_gtrid_string(),
|
||||
stmt.get_bqual_string(),
|
||||
stmt.get_format_id()))) {
|
||||
LOG_WARN("set xid error", K(ret), K(stmt), K(xid));
|
||||
} else if (my_session->get_in_transaction()) {
|
||||
ret = OB_TRANS_XA_RMFAIL;
|
||||
LOG_WARN("already start trans", K(ret));
|
||||
LOG_WARN("already start trans", K(ret), K(tx_desc->tid()));
|
||||
} else {
|
||||
transaction::ObStartTransParam& start_trans_param = plan_ctx->get_start_trans_param();
|
||||
init_start_trans_param(my_session, task_exec_ctx, start_trans_param);
|
||||
if (OB_FAIL(ObSqlTransControl::explicit_start_trans(ctx, start_trans_param))) {
|
||||
LOG_WARN("explicit start trans failed", K(ret), K(start_trans_param));
|
||||
} else if (OB_FAIL(ps->xa_end_trans(xid, is_rollback, flags, trans_desc, access_temp_table))) {
|
||||
LOG_WARN("fail to execute xa commit/rollback", K(xid), K(is_rollback));
|
||||
} else {
|
||||
LOG_DEBUG("succeed to execute xa commit/rollback", K(xid), K(is_rollback));
|
||||
if (OB_FAIL(MTL(transaction::ObXAService*)->xa_commit(xid, stmt.get_flags(),
|
||||
xa_timeout_seconds, has_tx_level_temp_table))) {
|
||||
LOG_WARN("xa commit failed", K(ret), K(xid));
|
||||
}
|
||||
if (!is_rollback && access_temp_table) {
|
||||
int temp_ret = my_session->drop_temp_tables(false, true /*is_xa_trans*/);
|
||||
if (OB_SUCCESS != temp_ret) {
|
||||
LOG_WARN("trx level temporary table clean failed", KR(temp_ret));
|
||||
}
|
||||
}
|
||||
my_session->reset_first_stmt_type();
|
||||
my_session->reset_tx_variable();
|
||||
my_session->set_early_lock_release(false);
|
||||
ctx.set_need_disconnect(false);
|
||||
my_session->get_trans_desc().get_standalone_stmt_desc().reset();
|
||||
}
|
||||
LOG_DEBUG("xa end_trans execute", K(gtrid_str), K(bqual_str), K(format_id), K(is_rollback), K(flags));
|
||||
if (has_tx_level_temp_table) {
|
||||
int temp_ret = my_session->drop_temp_tables(false, true/*is_xa_trans*/);
|
||||
if (OB_SUCCESS != temp_ret) {
|
||||
LOG_WARN("trx level temporary table clean failed", KR(temp_ret));
|
||||
}
|
||||
}
|
||||
LOG_INFO("xa commit", K(ret), K(stmt), K(xid));
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // end namespace sql
|
||||
} // end namespace oceanbase
|
||||
int ObPlXaRollbackExecutor::execute(ObExecContext &ctx, ObXaRollBackStmt &stmt)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
ObSQLSessionInfo *my_session = GET_MY_SESSION(ctx);
|
||||
ObTxDesc *tx_desc = my_session->get_tx_desc();
|
||||
int64_t xa_timeout_seconds = my_session->get_xa_end_timeout_seconds();
|
||||
ObXATransID xid;
|
||||
if (!stmt.is_valid_oracle_xid()) {
|
||||
ret = OB_TRANS_XA_INVAL;
|
||||
LOG_WARN("invalid xid for oracle mode", K(ret), K(stmt));
|
||||
} else if (OB_ISNULL(my_session)) {
|
||||
ret = OB_ERR_UNEXPECTED;
|
||||
LOG_ERROR("invalid param", K(ret), K(my_session));
|
||||
} else if (OB_FAIL(xid.set(stmt.get_gtrid_string(),
|
||||
stmt.get_bqual_string(),
|
||||
stmt.get_format_id()))) {
|
||||
LOG_WARN("set xid error", K(ret), K(stmt), K(xid));
|
||||
} else if (my_session->get_in_transaction()) {
|
||||
ret = OB_TRANS_XA_RMFAIL;
|
||||
LOG_WARN("already start trans", K(ret), K(tx_desc->tid()));
|
||||
} else {
|
||||
if (OB_FAIL(MTL(transaction::ObXAService*)->xa_rollback(xid, xa_timeout_seconds))) {
|
||||
LOG_WARN("xa rollback failed", K(ret), K(xid));
|
||||
}
|
||||
}
|
||||
LOG_INFO("xa rollback", K(ret), K(stmt), K(xid));
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // end namespace sql
|
||||
} // end namespace oceanbase
|
||||
|
||||
Reference in New Issue
Block a user