forked from oceanbase/seekdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathob_package_executor.cpp
More file actions
165 lines (154 loc) · 6.53 KB
/
Copy pathob_package_executor.cpp
File metadata and controls
165 lines (154 loc) · 6.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Copyright (c) 2025 OceanBase.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define USING_LOG_PREFIX SQL_ENG
#include "ob_package_executor.h"
#include "sql/resolver/ddl/ob_create_package_stmt.h"
#include "sql/resolver/ddl/ob_alter_package_stmt.h"
#include "sql/resolver/ddl/ob_drop_package_stmt.h"
#include "pl/ob_pl_resolver.h"
#include "pl/ob_pl_compile_utils.h"
namespace oceanbase
{
namespace sql
{
using namespace common;
using namespace share::schema;
int ObCreatePackageExecutor::execute(ObExecContext &ctx, ObCreatePackageStmt &stmt)
{
int ret = OB_SUCCESS;
ObTaskExecutorCtx *task_exec_ctx = NULL;
obrpc::ObCommonRpcProxy *common_rpc_proxy = NULL;
obrpc::UInt64 table_id;
obrpc::ObCreatePackageArg &arg = stmt.get_create_package_arg();
uint64_t tenant_id = arg.package_info_.get_tenant_id();
bool has_error = ERROR_STATUS_HAS_ERROR == arg.error_info_.get_error_status();
ObString &db_name = arg.db_name_;
const ObString &package_name = arg.package_info_.get_package_name();
share::schema::ObPackageType type = arg.package_info_.get_type();
ObString first_stmt;
obrpc::ObRoutineDDLRes res;
omt::ObTenantConfigGuard tenant_config(TENANT_CONF(ctx.get_my_session()->get_effective_tenant_id()));
if (OB_FAIL(stmt.get_first_stmt(first_stmt))) {
LOG_WARN("fail to get first stmt" , K(ret));
} else {
arg.ddl_stmt_str_ = first_stmt;
}
if (OB_FAIL(ret)) {
} else if (OB_ISNULL(task_exec_ctx = GET_TASK_EXECUTOR_CTX(ctx))) {
ret = OB_NOT_INIT;
LOG_WARN("get task executor context failed", K(ret));
} else if (OB_FAIL(task_exec_ctx->get_common_rpc(common_rpc_proxy))) {
LOG_WARN("get common rpc proxy failed", K(ret));
} else if (OB_ISNULL(common_rpc_proxy)){
ret = OB_ERR_UNEXPECTED;
LOG_WARN("common rpc proxy should not be null", K(ret));
} else if (OB_FAIL(common_rpc_proxy->create_package_with_res(arg, res))) {
LOG_WARN("rpc proxy create package failed", K(ret),
"dst", common_rpc_proxy->get_server());
}
if (OB_SUCC(ret)
&& !has_error
&& tenant_config.is_valid()
&& tenant_config->plsql_v2_compatibility) {
OZ (ObSPIService::force_refresh_schema(tenant_id, res.store_routine_schema_version_));
OZ (ctx.get_task_exec_ctx().schema_service_->
get_tenant_schema_guard(ctx.get_my_session()->get_effective_tenant_id(), *ctx.get_sql_ctx()->schema_guard_));
OZ (pl::ObPLCompilerUtils::compile(ctx,
tenant_id,
db_name,
package_name,
pl::ObPLCompilerUtils::get_compile_type(type),
res.store_routine_schema_version_));
}
return ret;
}
int ObAlterPackageExecutor::execute(ObExecContext &ctx, ObAlterPackageStmt &stmt)
{
int ret = OB_SUCCESS;
ObTaskExecutorCtx *task_exec_ctx = NULL;
obrpc::ObCommonRpcProxy *common_rpc_proxy = NULL;
obrpc::UInt64 table_id;
obrpc::ObAlterPackageArg &arg = stmt.get_alter_package_arg();
uint64_t tenant_id = arg.tenant_id_;
bool has_error = ERROR_STATUS_HAS_ERROR == arg.error_info_.get_error_status();
ObString &db_name = arg.db_name_;
const ObString &package_name = arg.package_name_;
share::schema::ObPackageType type = arg.package_type_;
ObString first_stmt;
obrpc::ObRoutineDDLRes res;
omt::ObTenantConfigGuard tenant_config(TENANT_CONF(ctx.get_my_session()->get_effective_tenant_id()));
if (OB_FAIL(stmt.get_first_stmt(first_stmt))) {
LOG_WARN("fail to get first stmt" , K(ret));
} else {
arg.ddl_stmt_str_ = first_stmt;
}
// we need send rpc for alter package, because it must refresh package state after alter package
if (OB_FAIL(ret)) {
} else if (OB_ISNULL(task_exec_ctx = GET_TASK_EXECUTOR_CTX(ctx))) {
ret = OB_NOT_INIT;
LOG_WARN("get task executor context failed", K(ret));
} else if (OB_FAIL(task_exec_ctx->get_common_rpc(common_rpc_proxy))) {
LOG_WARN("get common rpc proxy failed", K(ret));
} else if (OB_ISNULL(common_rpc_proxy)){
ret = OB_ERR_UNEXPECTED;
LOG_WARN("common rpc proxy should not be null", K(ret));
} else if (OB_FAIL(common_rpc_proxy->alter_package_with_res(arg, res))) {
LOG_WARN("rpc proxy drop procedure failed", K(ret), "dst", common_rpc_proxy->get_server());
}
if (OB_SUCC(ret) && !has_error &&
tenant_config.is_valid() &&
tenant_config->plsql_v2_compatibility) {
OZ (ObSPIService::force_refresh_schema(tenant_id, res.store_routine_schema_version_));
OZ (ctx.get_task_exec_ctx().schema_service_->
get_tenant_schema_guard(ctx.get_my_session()->get_effective_tenant_id(), *ctx.get_sql_ctx()->schema_guard_));
OZ (pl::ObPLCompilerUtils::compile(ctx,
tenant_id,
db_name,
package_name,
pl::ObPLCompilerUtils::get_compile_type(type),
res.store_routine_schema_version_));
}
return ret;
}
int ObDropPackageExecutor::execute(ObExecContext &ctx, ObDropPackageStmt &stmt)
{
int ret = OB_SUCCESS;
ObTaskExecutorCtx *task_exec_ctx = NULL;
obrpc::ObCommonRpcProxy *common_rpc_proxy = NULL;
obrpc::UInt64 table_id;
obrpc::ObDropPackageArg &arg = stmt.get_drop_package_arg();
ObString first_stmt;
if (OB_FAIL(stmt.get_first_stmt(first_stmt))) {
LOG_WARN("fail to get first stmt" , K(ret));
} else {
arg.ddl_stmt_str_ = first_stmt;
}
if (OB_FAIL(ret)) {
} else if (OB_ISNULL(task_exec_ctx = GET_TASK_EXECUTOR_CTX(ctx))) {
ret = OB_NOT_INIT;
LOG_WARN("get task executor context failed", K(ret));
} else if (OB_FAIL(task_exec_ctx->get_common_rpc(common_rpc_proxy))) {
LOG_WARN("get common rpc proxy failed", K(ret));
} else if (OB_ISNULL(common_rpc_proxy)){
ret = OB_ERR_UNEXPECTED;
LOG_WARN("common rpc proxy should not be null", K(ret));
} else if (OB_FAIL(common_rpc_proxy->drop_package(arg))) {
LOG_WARN("rpc proxy drop package failed", K(ret), "dst", common_rpc_proxy->get_server());
}
return ret;
}
}
}